sparseArray Class Reference

#include <sparse-array.hpp>

Inheritance diagram for sparseArray:

Inheritance graph
[legend]
Collaboration diagram for sparseArray:

Collaboration graph
[legend]
List of all members.

Detailed Description

This is an implementation of a sparse array to be used where not all cells within an array structure (example: subsector map) are occupied.

See also:
sparseArrayNode

Definition at line 37 of file sparse-array.hpp.

Public Member Functions

 sparseArray ()
void add (sparseArrayNode *p)
void addAt (int row, int column, sparseArrayNode *p)
sparseArrayNodefindAt (int row, int column)


Constructor & Destructor Documentation

sparseArray::sparseArray (  ) 

Normal non-parametized constructor.

Definition at line 30 of file sparse-array.cpp.

00030                         {
00031         root = new sparseArrayNode(-1,-1);
00032 }


Member Function Documentation

void sparseArray::add ( sparseArrayNode p  ) 

Adds a sparseArrayNode to the sparse array using the row and column coordinates embedded within the sparseArrayNode. If a node already exists at the coordinates specified by the passed in sparseArrayNode then the passed in node replaces the already existing one.

Parameters:
p pointer to a sparseArrayNode

Definition at line 103 of file sparse-array.cpp.

References addAt(), sparseArrayNode::getColumn(), and sparseArrayNode::getRow().

00103                                        {
00104         int r=p->getRow();
00105         int c=p->getColumn();
00106         
00107         this->addAt(r,c,p);
00108         
00109 }

Here is the call graph for this function:

void sparseArray::addAt ( int  row,
int  column,
sparseArrayNode p 
)

Adds a sparseArrayNode to a specific row and column as passed by the parameters. The row and column attributes within the inserted node are set to agree with the passed in parameters. If there already exists a node at the coordinates passed then the passed in node replaces the existing one.

Parameters:
row integer value for row
column integer value for column
p pointer to a sparseArrayNode to be inserted.

Definition at line 111 of file sparse-array.cpp.

References sparseArrayNode::getColumn(), sparseArrayNode::getDown(), sparseArrayNode::getRow(), sparseArrayNode::setColumn(), sparseArrayNode::setDown(), and sparseArrayNode::setRow().

Referenced by add(), and subsector::addParsec().

00111                                                                {
00112 #ifdef DEBUG_ON
00113         printf("Entering sparseArray::addAt([%d],[%d],<ptr>)\n",row,column);
00114 #endif
00115         
00116         sparseArrayNode* p = this->findColumnHead(column);
00117         node->setRow(row);
00118         node->setColumn(column);
00119         
00120         
00121         if ( p->getDown() == 0 ) {
00122 #ifdef DEBUG_ON
00123                 printf("\tInserting new node just below the column header\n");
00124 #endif
00125                 p->setDown(node);
00126 #ifdef DEBUG_ON
00127                 printf("Returning from sparseArray::addAt()\n");
00128 #endif
00129                 return;
00130         } else { 
00131                 while(p->getDown() != 0 ) {
00132 #ifdef DEBUG_ON
00133                         printf("\tThis is [%d,%d] and below that is [%d,%d] (Tryig to insert [%d,%d]\n",
00134 
00135                                    p->getRow(),p->getColumn(),
00136                                    p->getDown()->getRow(),p->getDown()->getColumn(),
00137                                    row,column
00138                                    );
00139 #endif
00140                         if ( p->getDown()->getRow() >= row ) {
00141 #ifdef DEBUG_ON
00142                                 printf("\t\tInserting here!\n");
00143 #endif
00144                                 node->setDown(p->getDown());
00145                                 p->setDown(p);
00146 #ifdef DEBUG_ON
00147                                 printf("returning.\n");
00148 #endif
00149                                 return;
00150                         }
00151 #ifdef DEBUG_ON
00152                         printf("\tGoing to the next node.\n");
00153 #endif
00154                         p=p->getDown();
00155                 }
00156                 p->setDown(node);
00157                 node->setDown(0);
00158         }
00159         
00160                                 
00161 }

Here is the call graph for this function:

Here is the caller graph for this function:

sparseArrayNode * sparseArray::findAt ( int  row,
int  column 
)

Finds a sparseArrayNode at the coordinates passed in and returns a pointer to it or a null if none exists.

Parameters:
row integer value for the row.
column integer value for the column
Returns:
pointer to the sparseArrayNode at those coordinates or null if it doesn't exist.

Definition at line 164 of file sparse-array.cpp.

References sparseArrayNode::getDown(), and sparseArrayNode::getRow().

00164                                                       {
00165         sparseArrayNode *p = this->findColumnHead (column);
00166         
00167         while(p->getDown() != (sparseArrayNode*)0){
00168                 p = p->getDown();
00169                 if ( p->getRow() == row ) 
00170                         return p;
00171         }
00172         if ( p->getRow() != row )
00173                 return (sparseArrayNode*)0;
00174         else 
00175                 return p;
00176         
00177 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Fri Mar 7 16:43:06 2008 for frpuniverse by  doxygen 1.4.7