@@ -77,19 +77,12 @@ public function createVertex($id = NULL, $returnDuplicate = false)
7777 // no ID given
7878 if ($ id === NULL ) {
7979 $ id = $ this ->getNextId ();
80- } elseif (!is_int ($ id ) && !is_string ($ id )) {
81- throw new InvalidArgumentException ('Vertex ID has to be of type integer or string ' );
8280 }
83- if ($ this ->vertices ->hasVertexId ($ id )) {
84- if ($ returnDuplicate ) {
85- return $ this ->vertices ->getVertexId ($ id );
86- }
87- throw new OverflowException ('ID must be unique ' );
81+ if ($ returnDuplicate && $ this ->vertices ->hasVertexId ($ id )) {
82+ return $ this ->vertices ->getVertexId ($ id );
8883 }
89- $ vertex = new Vertex ($ id , $ this );
90- $ this ->verticesStorage [$ id ] = $ vertex ;
9184
92- return $ vertex ;
85+ return new Vertex ( $ id , $ this ) ;
9386 }
9487
9588 /**
@@ -110,7 +103,6 @@ public function createVertexClone(Vertex $originalVertex)
110103 $ newVertex ->setLayout ($ originalVertex ->getLayout ());
111104 $ newVertex ->setBalance ($ originalVertex ->getBalance ());
112105 $ newVertex ->setGroup ($ originalVertex ->getGroup ());
113- $ this ->verticesStorage [$ id ] = $ newVertex ;
114106
115107 return $ newVertex ;
116108 }
@@ -264,7 +256,7 @@ public function createVertices($n)
264256 $ vertices = array ();
265257 if (is_int ($ n ) && $ n >= 0 ) {
266258 for ($ id = $ this ->getNextId (), $ n += $ id ; $ id < $ n ; ++$ id ) {
267- $ vertices [$ id ] = $ this -> verticesStorage [ $ id ] = new Vertex ($ id , $ this );
259+ $ vertices [$ id ] = new Vertex ($ id , $ this );
268260 }
269261 } elseif (is_array ($ n )) {
270262 // array given => check to make sure all given IDs are available (atomic operation)
@@ -283,7 +275,7 @@ public function createVertices($n)
283275
284276 // actually create all requested vertices
285277 foreach ($ n as $ id ) {
286- $ vertices [$ id ] = $ this -> verticesStorage [ $ id ] = new Vertex ($ id , $ this );
278+ $ vertices [$ id ] = new Vertex ($ id , $ this );
287279 }
288280 } else {
289281 throw new InvalidArgumentException ('Invalid number of vertices given. Must be non-negative integer or an array of Vertex IDs ' );
@@ -349,6 +341,22 @@ public function getVertexFirst()
349341 return $ this ->vertices ->getVertexFirst ();
350342 }
351343
344+ /**
345+ * adds a new Vertex to the Graph (MUST NOT be called manually!)
346+ *
347+ * @param Vertex $vertex instance of the new Vertex
348+ * @return void
349+ * @private
350+ * @see self::createVertex() instead!
351+ */
352+ public function addVertex (Vertex $ vertex )
353+ {
354+ if (isset ($ this ->verticesStorage [$ vertex ->getId ()])) {
355+ throw new OverflowException ('ID must be unique ' );
356+ }
357+ $ this ->verticesStorage [$ vertex ->getId ()] = $ vertex ;
358+ }
359+
352360 /**
353361 * adds a new Edge to the Graph (MUST NOT be called manually!)
354362 *
0 commit comments