@@ -32,7 +32,10 @@ class Cursor {
3232 for ( const vertex of vertices . values ( ) ) {
3333 let condition = true ;
3434 for ( const name of names ) {
35- condition = condition && vertex . links . has ( name ) ;
35+ if ( ! vertex . links . has ( name ) ) {
36+ condition = false ;
37+ break ;
38+ }
3639 }
3740 if ( condition ) result . add ( vertex ) ;
3841 }
@@ -48,9 +51,10 @@ class Graph {
4851 }
4952
5053 add ( data ) {
51- const vertex = new Vertex ( this , data ) ;
5254 const key = data [ this . keyField ] ;
53- if ( this . vertices . get ( key ) === undefined ) {
55+ let vertex = this . vertices . get ( key ) ;
56+ if ( ! vertex ) {
57+ vertex = new Vertex ( this , data ) ;
5458 this . vertices . set ( key , vertex ) ;
5559 }
5660 return vertex ;
@@ -81,10 +85,10 @@ class Graph {
8185 link ( from ) {
8286 return {
8387 to ( ...destinations ) {
84- destinations . forEach ( ( target ) => {
85- if ( target ) from . link ( target ) ;
86- } ) ;
87- }
88+ for ( const destination of destinations ) {
89+ from . link ( destination ) ;
90+ }
91+ } ,
8892 } ;
8993 }
9094
@@ -95,15 +99,14 @@ class Graph {
9599 vertices . push ( vertex ) ;
96100 const keys = Object . keys ( record ) ;
97101 for ( const [ key , idx ] of this . indices ) {
98- if ( keys . includes ( key ) ) {
99- const value = record [ key ] ;
100- let records = idx . get ( value ) ;
101- if ( ! records ) {
102- records = new Set ( ) ;
103- idx . set ( value , records ) ;
104- }
105- records . add ( vertex ) ;
102+ if ( ! keys . includes ( key ) ) continue ;
103+ const value = record [ key ] ;
104+ let records = idx . get ( value ) ;
105+ if ( ! records ) {
106+ records = new Set ( ) ;
107+ idx . set ( value , records ) ;
106108 }
109+ records . add ( vertex ) ;
107110 }
108111 }
109112 return vertices ;
0 commit comments