#include <sparse-vector.hpp>
Inheritance diagram for sparseVector:
Definition at line 37 of file sparse-vector.hpp.
Public Member Functions | |
sparseVector () | |
sparseVector (sparseVectorNode *p) | |
void | setRoot (sparseVectorNode *p) |
sparseVectorNode * | getRoot () |
void | addAt (int, sparseVectorNode *) |
sparseVectorNode * | findAt (int) |
char * | dumpAsXML () |
sparseVector::sparseVector | ( | ) | [inline] |
A normal class constructor where no nodes are passed in for initialization. The root node is constructed within this constructor.
Definition at line 47 of file sparse-vector.hpp.
00047 { 00048 root = new sparseVectorNode(-1,(sparseVectorNode*)0); 00049 00050 };
sparseVector::sparseVector | ( | sparseVectorNode * | p | ) | [inline] |
A rarely used form of the class constructor where we deliberately set the root node with a supplied value.
p | a pointer to a sparseVectorNode object. |
Definition at line 59 of file sparse-vector.hpp.
void sparseVector::addAt | ( | int | , | |
sparseVectorNode * | ||||
) |
Add a sparseVector to the sparse vector. If there already exists a node at the index specified then the node passed will replace the node already in the structure.
int | integer value representing the index to set the node to. | |
sparseVectorNode* | pointer to the sparseVectorNode to be added. |
Definition at line 32 of file sparse-vector.cpp.
References sparseVectorNode::getIndex(), sparseVectorNode::getNext(), and sparseVectorNode::setNext().
Referenced by orbitPlane::add(), and star::placeCompanion().
00032 { 00033 sparseVectorNode* p=root; 00034 00035 n -> setIndex(ix); // Just to make sure for sanity's sake later. 00036 00037 00038 if ( p->getNext() == (sparseVectorNode*) 0 ) { // Root node points to zero 00039 p->setNext(n); 00040 n->setNext((sparseVectorNode* ) 0 ); 00041 } else { 00042 while ( p->getNext() != (sparseVectorNode*)0){ 00043 p = p->getNext(); 00044 if ( (p->getNext() != (sparseVectorNode*)0) && 00045 (p->getNext()->getIndex() > n->getIndex()) ){ 00046 n->setNext(p->getNext()); 00047 p->setNext(n); 00048 return; 00049 } 00050 } 00051 00052 p->setNext(n); 00053 n->setNext((sparseVectorNode*)0); 00054 return; 00055 } 00056 00057 }
Here is the call graph for this function:
Here is the caller graph for this function:
char * sparseVector::dumpAsXML | ( | ) |
Dump an XML represention of the structure. This should get overloaded by child classes of this class.
Definition at line 96 of file sparse-vector.cpp.
References sparseVectorNode::getNext().
00096 { 00097 // Get ready folks.. this will be ugly... 00098 char * s; 00099 sparseVectorNode* p; 00100 00101 s=(char*) malloc(129); 00102 s[0]='\0'; 00103 00104 sprintf(s,"%s\n",XMLSTART); 00105 if ( root->getNext() == (sparseVectorNode*)0){ 00106 strcat(s,XMLEND); 00107 return s; 00108 } else { 00109 p=root->getNext(); 00110 s = addXML(s,p); 00111 while(p->getNext() != (sparseVectorNode*)0){ 00112 p=p->getNext(); 00113 s=addXML(s,p); 00114 } 00115 } 00116 strcat(s,XMLEND); 00117 00118 return s; 00119 }
Here is the call graph for this function:
sparseVectorNode * sparseVector::findAt | ( | int | ) |
Find the sparseVectorNode in the list occupying index value passed.
int | -- integer index for node being searched for. |
Definition at line 65 of file sparse-vector.cpp.
References sparseVectorNode::getIndex(), and sparseVectorNode::getNext().
00065 { 00066 sparseVectorNode* p = root; 00067 00068 if ( root->getNext() == (sparseVectorNode*) 0 ) 00069 return (sparseVectorNode* ) 0; 00070 while(p->getNext() != (sparseVectorNode*)0){ 00071 p = p->getNext(); 00072 if ( p->getIndex() == ix ) 00073 return p; 00074 } 00075 return (p->getIndex() == ix ? p : (sparseVectorNode*) 0 ); 00076 00077 }
Here is the call graph for this function:
sparseVectorNode* sparseVector::getRoot | ( | ) | [inline] |
A getter function to return the current root node.
Definition at line 76 of file sparse-vector.hpp.
void sparseVector::setRoot | ( | sparseVectorNode * | p | ) | [inline] |
A setter funnction that ges the value of the root node.
p | a pointer to a sparseVectorNode that will be used as the root node |
Definition at line 69 of file sparse-vector.hpp.