@@ -103,12 +103,6 @@ export class Graph {
103103 this . _edgeLabels = { } ;
104104 }
105105
106- /* Number of nodes in the graph. Should only be changed by the implementation. */
107- _nodeCount = 0 ;
108-
109- /* Number of edges in the graph. Should only be changed by the implementation. */
110- _edgeCount = 0 ;
111-
112106 /* === Graph functions ========= */
113107
114108 isDirected ( ) {
@@ -142,11 +136,11 @@ export class Graph {
142136 return this ;
143137 }
144138
145- nodeCount ( ) {
146- return this . _nodeCount ;
139+ nodeCount ( ) : number {
140+ return this . nodes . length ;
147141 }
148142
149- nodes ( ) {
143+ nodes ( ) : string [ ] {
150144 return Object . keys ( this . _nodes ) ;
151145 }
152146
@@ -195,7 +189,6 @@ export class Graph {
195189 this . _preds [ v ] = { } ;
196190 this . _out [ v ] = { } ;
197191 this . _sucs [ v ] = { } ;
198- ++ this . _nodeCount ;
199192 return this ;
200193 }
201194
@@ -228,7 +221,6 @@ export class Graph {
228221 each ( Object . keys ( this . _out [ v ] ) , removeEdge ) ;
229222 delete this . _out [ v ] ;
230223 delete this . _sucs [ v ] ;
231- -- this . _nodeCount ;
232224 }
233225 return this ;
234226 }
@@ -385,11 +377,11 @@ export class Graph {
385377 return this ;
386378 }
387379
388- edgeCount ( ) {
389- return this . _edgeCount ;
380+ edgeCount ( ) : number {
381+ return this . edges . length ;
390382 }
391383
392- edges ( ) {
384+ edges ( ) : Edge [ ] {
393385 return values ( this . _edgeObjs ) ;
394386 }
395387
@@ -475,7 +467,6 @@ export class Graph {
475467 incrementOrInitEntry ( this . _sucs [ v ] , w ) ;
476468 this . _in [ w ] [ e ] = edgeObj ;
477469 this . _out [ v ] [ e ] = edgeObj ;
478- this . _edgeCount ++ ;
479470 return this ;
480471 }
481472
@@ -510,7 +501,6 @@ export class Graph {
510501 decrementOrRemoveEntry ( this . _sucs [ v ] , w ) ;
511502 delete this . _in [ w ] [ e ] ;
512503 delete this . _out [ v ] [ e ] ;
513- this . _edgeCount -- ;
514504 }
515505 return this ;
516506 }
0 commit comments