@@ -8,11 +8,11 @@ class Vertex {
8
8
}
9
9
link ( ...args ) {
10
10
const distinct = new Set ( args ) ;
11
- const links = this . links ;
12
- const keyField = this . graph . keyField ;
11
+ const { links } = this ;
12
+ const { keyField } = this . graph ;
13
13
for ( const item of distinct ) {
14
- const key = item . data [ keyField ] ;
15
- links . set ( key , null ) ;
14
+ const value = item . data [ keyField ] ;
15
+ links . set ( value , item ) ;
16
16
}
17
17
return this ;
18
18
}
@@ -23,7 +23,7 @@ class Cursor {
23
23
this . vertices = vertices ;
24
24
}
25
25
linked ( ...names ) {
26
- const vertices = this . vertices ;
26
+ const { vertices } = this ;
27
27
const result = new Set ( ) ;
28
28
for ( const vertex of vertices ) {
29
29
let condition = true ;
@@ -53,7 +53,7 @@ class Graph {
53
53
const vertices = new Set ( ) ;
54
54
for ( const vertex of this . vertices . values ( ) ) {
55
55
let condition = true ;
56
- const data = vertex . data ;
56
+ const { data } = vertex ;
57
57
if ( data ) {
58
58
for ( const field in query ) {
59
59
condition = condition && data [ field ] === query [ field ] ;
@@ -69,21 +69,36 @@ class Graph {
69
69
70
70
const graph = new Graph ( 'name' ) ;
71
71
72
- const marcus = graph . add (
73
- { name : 'Marcus Aurelius' , city : 'Rome' , born : 121 , dynasty : 'Antonine' }
74
- ) ;
75
- const lucius = graph . add (
76
- { name : 'Lucius Verus' , city : 'Rome' , born : 130 , dynasty : 'Antonine' }
77
- ) ;
78
- const pius = graph . add (
79
- { name : 'Antoninus Pius' , city : 'Lanuvium' , born : 86 , dynasty : 'Antonine' }
80
- ) ;
81
- const hadrian = graph . add (
82
- { name : 'Hadrian' , city : 'Santiponce' , born : 76 , dynasty : 'Nerva–Trajan' }
83
- ) ;
84
- const trajan = graph . add (
85
- { name : 'Trajan' , city : 'Sevilla' , born : 98 , dynasty : 'Nerva–Trajan' }
86
- ) ;
72
+ const marcus = graph . add ( {
73
+ name : 'Marcus Aurelius' ,
74
+ city : 'Rome' ,
75
+ born : 121 ,
76
+ dynasty : 'Antonine' ,
77
+ } ) ;
78
+ const lucius = graph . add ( {
79
+ name : 'Lucius Verus' ,
80
+ city : 'Rome' ,
81
+ born : 130 ,
82
+ dynasty : 'Antonine' ,
83
+ } ) ;
84
+ const pius = graph . add ( {
85
+ name : 'Antoninus Pius' ,
86
+ city : 'Lanuvium' ,
87
+ born : 86 ,
88
+ dynasty : 'Antonine' ,
89
+ } ) ;
90
+ const hadrian = graph . add ( {
91
+ name : 'Hadrian' ,
92
+ city : 'Santiponce' ,
93
+ born : 76 ,
94
+ dynasty : 'Nerva–Trajan' ,
95
+ } ) ;
96
+ const trajan = graph . add ( {
97
+ name : 'Trajan' ,
98
+ city : 'Sevilla' ,
99
+ born : 98 ,
100
+ dynasty : 'Nerva–Trajan' ,
101
+ } ) ;
87
102
88
103
marcus . link ( lucius ) ;
89
104
lucius . link ( trajan , marcus , marcus , marcus ) ;
0 commit comments