File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ class Vertex {
66 this . data = data ;
77 this . links = new Map ( ) ;
88 }
9+
910 link ( ...args ) {
1011 const distinct = new Set ( args ) ;
1112 const { links } = this ;
@@ -22,6 +23,7 @@ class Cursor {
2223 constructor ( vertices ) {
2324 this . vertices = vertices ;
2425 }
26+
2527 linked ( ...names ) {
2628 const { vertices } = this ;
2729 const result = new Set ( ) ;
@@ -41,6 +43,7 @@ class Graph {
4143 this . keyField = keyField ;
4244 this . vertices = new Map ( ) ;
4345 }
46+
4447 add ( data ) {
4548 const vertex = new Vertex ( this , data ) ;
4649 const key = data [ this . keyField ] ;
@@ -49,6 +52,7 @@ class Graph {
4952 }
5053 return vertex ;
5154 }
55+
5256 select ( query ) {
5357 const vertices = new Set ( ) ;
5458 for ( const vertex of this . vertices . values ( ) ) {
@@ -75,24 +79,28 @@ const marcus = graph.add({
7579 born : 121 ,
7680 dynasty : 'Antonine' ,
7781} ) ;
82+
7883const lucius = graph . add ( {
7984 name : 'Lucius Verus' ,
8085 city : 'Rome' ,
8186 born : 130 ,
8287 dynasty : 'Antonine' ,
8388} ) ;
89+
8490const pius = graph . add ( {
8591 name : 'Antoninus Pius' ,
8692 city : 'Lanuvium' ,
8793 born : 86 ,
8894 dynasty : 'Antonine' ,
8995} ) ;
96+
9097const hadrian = graph . add ( {
9198 name : 'Hadrian' ,
9299 city : 'Santiponce' ,
93100 born : 76 ,
94101 dynasty : 'Nerva–Trajan' ,
95102} ) ;
103+
96104const trajan = graph . add ( {
97105 name : 'Trajan' ,
98106 city : 'Sevilla' ,
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ class Vertex {
66 this . data = data ;
77 this . links = new Map ( ) ;
88 }
9+
910 link ( ...args ) {
1011 const distinct = new Set ( args ) ;
1112 const { links } = this ;
@@ -22,6 +23,7 @@ class Cursor {
2223 constructor ( vertices ) {
2324 this . vertices = vertices ;
2425 }
26+
2527 linked ( ...names ) {
2628 const { vertices } = this ;
2729 const result = new Set ( ) ;
@@ -41,6 +43,7 @@ class Graph {
4143 this . keyField = keyField ;
4244 this . vertices = new Map ( ) ;
4345 }
46+
4447 add ( data ) {
4548 const vertex = new Vertex ( this , data ) ;
4649 const key = data [ this . keyField ] ;
@@ -49,6 +52,7 @@ class Graph {
4952 }
5053 return vertex ;
5154 }
55+
5256 select ( query ) {
5357 const vertices = new Set ( ) ;
5458 for ( const vertex of this . vertices . values ( ) ) {
@@ -63,6 +67,7 @@ class Graph {
6367 }
6468 return new Cursor ( vertices ) ;
6569 }
70+
6671 link ( source ) {
6772 const { vertices } = this ;
6873 const from = vertices . get ( source ) ;
@@ -77,6 +82,7 @@ class Graph {
7782 }
7883 } ;
7984 }
85+
8086 insert ( records ) {
8187 for ( const record of records ) {
8288 this . add ( record ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class Vertex {
88 this . data = data ;
99 this . links = new Map ( ) ;
1010 }
11+
1112 link ( ...args ) {
1213 const distinct = new Set ( args ) ;
1314 const { links } = this ;
@@ -24,6 +25,7 @@ class Cursor {
2425 constructor ( vertices ) {
2526 this . vertices = vertices ;
2627 }
28+
2729 linked ( ...names ) {
2830 const { vertices } = this ;
2931 const result = new Set ( ) ;
@@ -44,6 +46,7 @@ class Graph {
4446 this . vertices = new Map ( ) ;
4547 this . indices = new Map ( ) ;
4648 }
49+
4750 add ( data ) {
4851 const vertex = new Vertex ( this , data ) ;
4952 const key = data [ this . keyField ] ;
@@ -52,6 +55,7 @@ class Graph {
5255 }
5356 return vertex ;
5457 }
58+
5559 select ( query ) {
5660 let vertices ;
5761 const keys = Object . keys ( query ) ;
@@ -73,6 +77,7 @@ class Graph {
7377 }
7478 return new Cursor ( vertices ) ;
7579 }
80+
7681 link ( from ) {
7782 return {
7883 to ( ...destinations ) {
@@ -82,6 +87,7 @@ class Graph {
8287 }
8388 } ;
8489 }
90+
8591 insert ( rows ) {
8692 const vertices = [ ] ;
8793 for ( const record of rows ) {
@@ -102,6 +108,7 @@ class Graph {
102108 }
103109 return vertices ;
104110 }
111+
105112 index ( key ) {
106113 let idx = this . indices . get ( key ) ;
107114 if ( ! idx ) {
You can’t perform that action at this time.
0 commit comments