@@ -56,83 +56,85 @@ class HugeGraphIntersectImpl implements RelationshipIntersect {
56
56
}
57
57
58
58
@ Override
59
- public void intersectAll (long nodeIdA , IntersectionConsumer consumer ) {
59
+ public void intersectAll (long nodeA , IntersectionConsumer consumer ) {
60
60
// check the first node's degree
61
- if (!degreeFilter .test (nodeIdA )) {
61
+ if (!degreeFilter .test (nodeA )) {
62
62
return ;
63
63
}
64
64
65
65
AdjacencyOffsets offsets = this .offsets ;
66
66
AdjacencyList adjacency = this .adjacency ;
67
+ AdjacencyList .DecompressingCursor neighboursAMain = cursor (nodeA , cache , offsets , adjacency );
67
68
68
- AdjacencyList .DecompressingCursor mainDecompressingCursor = cursor (nodeIdA , cache , offsets , adjacency );
69
-
70
- // find first neighbour B of A id > A
71
- long nodeIdB = mainDecompressingCursor .skipUntil (nodeIdA );
72
- if (nodeIdA > nodeIdB ) {
69
+ // find first neighbour B of A with id > A
70
+ long nodeB = neighboursAMain .skipUntil (nodeA );
71
+ // if there is no such neighbour -> no triangle (or we already found it)
72
+ if (nodeA > nodeB ) {
73
73
return ;
74
74
}
75
75
76
- AdjacencyList .DecompressingCursor decompressingCursorA = cacheA , decompressingCursorB = cacheB ;
76
+ AdjacencyList .DecompressingCursor neighboursA = cacheA , neighboursB = cacheB ;
77
77
78
- long CfromA ;
79
- long CfromB ;
78
+ long nodeCa ;
79
+ long nodeCb ;
80
80
long lastNodeB ;
81
81
long lastNodeC ;
82
82
83
83
// for all neighbours of A
84
- while (mainDecompressingCursor .hasNextVLong ()) {
84
+ while (neighboursAMain .hasNextVLong ()) {
85
85
lastNodeC = -1 ;
86
86
// check the second node's degree
87
- if (degreeFilter .test (nodeIdB )) {
88
- decompressingCursorB = cursor (nodeIdB , decompressingCursorB , offsets , adjacency );
87
+ if (degreeFilter .test (nodeB )) {
88
+ neighboursB = cursor (nodeB , neighboursB , offsets , adjacency );
89
89
// find first neighbour Cb of B with id > B
90
- CfromB = decompressingCursorB .skipUntil (nodeIdB );// check the third node's degree
91
- if (CfromB > nodeIdB && degreeFilter .test (CfromB )) {
90
+ nodeCb = neighboursB .skipUntil (nodeB );
91
+
92
+ // check the third node's degree
93
+ if (nodeCb > nodeB && degreeFilter .test (nodeCb )) {
92
94
// copy the state of A's cursor
93
- decompressingCursorA .copyFrom (mainDecompressingCursor );
95
+ neighboursA .copyFrom (neighboursAMain );
94
96
// find the first neighbour Ca of A with id >= Cb
95
- CfromA = decompressingCursorA .advance (CfromB );
97
+ nodeCa = neighboursA .advance (nodeCb );
96
98
97
99
// if Ca = Cb we have found a triangle
98
100
// we only submit one triangle per parallel relationship
99
- if (CfromA == CfromB && CfromB > lastNodeC ) {
100
- consumer .accept (nodeIdA , nodeIdB , CfromB );
101
- lastNodeC = CfromB ;
101
+ if (nodeCa == nodeCb && nodeCb > lastNodeC ) {
102
+ consumer .accept (nodeA , nodeB , nodeCb );
103
+ lastNodeC = nodeCb ;
102
104
}
103
105
104
106
// while both A and B have more neighbours
105
- while (decompressingCursorB .hasNextVLong () && decompressingCursorA .hasNextVLong ()) {
107
+ while (neighboursB .hasNextVLong () && neighboursA .hasNextVLong ()) {
106
108
// take the next neighbour Cb of B
107
- CfromB = decompressingCursorB .nextVLong ();
108
- if (CfromB > CfromA ) {
109
+ nodeCb = neighboursB .nextVLong ();
110
+ if (nodeCb > nodeCa ) {
109
111
// if Cb > Ca, take the next neighbour Ca of A with id >= Cb
110
- CfromA = decompressingCursorA .advance (CfromB );
112
+ nodeCa = neighboursA .advance (nodeCb );
111
113
}
112
114
// check for triangle
113
- if (CfromA == CfromB && CfromA > lastNodeC && degreeFilter .test (CfromB )) {
114
- consumer .accept (nodeIdA , nodeIdB , CfromB );
115
- lastNodeC = CfromB ;
115
+ if (nodeCa == nodeCb && nodeCa > lastNodeC && degreeFilter .test (nodeCb )) {
116
+ consumer .accept (nodeA , nodeB , nodeCb );
117
+ lastNodeC = nodeCb ;
116
118
}
117
119
}
118
120
119
121
// it is possible that the last Ca > Cb, but there are no more neighbours Ca of A
120
122
// so if there are more neighbours Cb of B
121
- if (decompressingCursorB .hasNextVLong ()) {
123
+ if (neighboursB .hasNextVLong ()) {
122
124
// we take the next neighbour Cb of B with id >= Ca
123
- CfromB = decompressingCursorB .advance (CfromA );
125
+ nodeCb = neighboursB .advance (nodeCa );
124
126
// check for triangle
125
- if (CfromA == CfromB && CfromA > lastNodeC && degreeFilter .test (CfromB )) {
126
- consumer .accept (nodeIdA , nodeIdB , CfromB );
127
+ if (nodeCa == nodeCb && nodeCa > lastNodeC && degreeFilter .test (nodeCb )) {
128
+ consumer .accept (nodeA , nodeB , nodeCb );
127
129
}
128
130
}
129
131
}
130
132
}
131
133
132
134
// TODO: use skipUntil?
133
- lastNodeB = nodeIdB ;
134
- while (mainDecompressingCursor .hasNextVLong () && nodeIdB == lastNodeB ) {
135
- nodeIdB = mainDecompressingCursor .nextVLong ();
135
+ lastNodeB = nodeB ;
136
+ while (neighboursAMain .hasNextVLong () && nodeB == lastNodeB ) {
137
+ nodeB = neighboursAMain .nextVLong ();
136
138
}
137
139
}
138
140
}
0 commit comments