MCPcopy Create free account
hub / github.com/OpenSees/OpenSees / addVertex

Method addVertex

SRC/graph/graph/ArrayGraph.cpp:91–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89
90
91bool
92ArrayGraph::addVertex(Vertex *vertexPtr)
93{
94 // check the vertex * and its adjacency list
95 if (vertexPtr == 0) {
96 opserr << "WARNING ArrayGraph::addVertex";
97 opserr << " - attempting to add a NULL vertex*\n";
98 return false;
99 }
100
101 if (vertexPtr->getDegree() != 0) {
102 const ID &adjacency = vertexPtr->getAdjacency();
103 int size = adjacency.Size();
104 for (int i=0; i<size; i++) {
105 Vertex *other = this->getVertexPtr(adjacency(i));
106 if (other == 0) {
107 opserr << "WARNING ArrayGraph::addVertex";
108 opserr << " - vertex with adjacent vertex not in graph\n";
109 return false;
110 }
111 }
112 }
113
114 // check if we have room to place the vertex
115 if (numVertex == sizeVertices) {
116
117 int newSize = sizeVertices*2;
118 Vertex **newVertices = new Vertex *[newSize];
119
120 if (newVertices == 0) {
121 opserr << "WARNING ArrayGraph::addVertex";
122 opserr << " - out of contiguous memory could not create a new array";
123 delete vertexPtr;
124 return false;
125 }
126
127 // copy the old and 0 the extra, then delete the old
128 for (int i=0; i<sizeVertices; i++)
129 newVertices[i] = theVertices[i];
130 for (int j=sizeVertices; j<newSize; j++)
131 newVertices[j] = 0;
132
133 delete [] theVertices;
134
135 theVertices = newVertices;
136 sizeVertices = newSize;
137 }
138
139 // now see if we can add the Vertex into the array in its vertexTag location
140 int vertexTag = vertexPtr->getTag();
141 if ((vertexTag >= 0) && (vertexTag < sizeVertices) &&
142 (theVertices[vertexTag] == 0)) {
143
144 theVertices[vertexTag]= vertexPtr;
145 numVertex++;
146 return 0;
147
148 } else {

Callers

nothing calls this directly

Calls 4

getVertexPtrMethod · 0.95
getDegreeMethod · 0.45
SizeMethod · 0.45
getTagMethod · 0.45

Tested by

no test coverage detected