@@ -66,22 +66,20 @@ public void intersectAll(long nodeIdA, IntersectionConsumer consumer) {
66
66
AdjacencyList adjacency = this .adjacency ;
67
67
68
68
AdjacencyList .DecompressingCursor mainDecompressingCursor = cursor (nodeIdA , cache , offsets , adjacency );
69
+
69
70
// find first neighbour B of A id > A
70
71
long nodeIdB = mainDecompressingCursor .skipUntil (nodeIdA );
71
72
if (nodeIdA > nodeIdB ) {
72
73
return ;
73
74
}
74
75
75
- AdjacencyList .DecompressingCursor lead , follow , decompressingCursorA = cacheA , decompressingCursorB = cacheB ;
76
+ AdjacencyList .DecompressingCursor decompressingCursorA = cacheA , decompressingCursorB = cacheB ;
76
77
77
- long CfromB ;
78
78
long CfromA ;
79
-
79
+ long CfromB ;
80
80
long lastNodeB ;
81
81
long lastNodeC ;
82
82
83
- long s ,t ;
84
-
85
83
// for all neighbours of A
86
84
while (mainDecompressingCursor .hasNextVLong ()) {
87
85
lastNodeC = -1 ;
@@ -103,32 +101,29 @@ public void intersectAll(long nodeIdA, IntersectionConsumer consumer) {
103
101
lastNodeC = CfromB ;
104
102
}
105
103
106
- lead = decompressingCursorB ;
107
- s = CfromB ;
108
- follow = decompressingCursorA ;
109
- t = CfromA ;
110
-
111
104
// while both A and B have more neighbours
112
- while (lead .hasNextVLong () && follow .hasNextVLong ()) {
113
- s = lead .nextVLong ();
114
- if (s > t ) {
115
- t = follow .advance (s );
105
+ while (decompressingCursorB .hasNextVLong () && decompressingCursorA .hasNextVLong ()) {
106
+ // take the next neighbour Cb of B
107
+ CfromB = decompressingCursorB .nextVLong ();
108
+ if (CfromB > CfromA ) {
109
+ // if Cb > Ca, take the next neighbour Ca of A with id >= Cb
110
+ CfromA = decompressingCursorA .advance (CfromB );
116
111
}
117
- if (t == s && t > lastNodeC && degreeFilter .test (s )) {
118
- consumer .accept (nodeIdA , nodeIdB , s );
119
- lastNodeC = s ;
112
+ // check for triangle
113
+ if (CfromA == CfromB && CfromA > lastNodeC && degreeFilter .test (CfromB )) {
114
+ consumer .accept (nodeIdA , nodeIdB , CfromB );
115
+ lastNodeC = CfromB ;
120
116
}
121
117
}
122
118
123
- if (lead .hasNextVLong ()) {
124
- s = lead .advance (t );
125
- if (t == s && t > lastNodeC && degreeFilter .test (s )) {
126
- consumer .accept (nodeIdA , nodeIdB , s );
127
- }
128
- } else if (follow .hasNextVLong ()) {
129
- t = follow .advance (s );
130
- if (t == s && t > lastNodeC && degreeFilter .test (s )) {
131
- consumer .accept (nodeIdA , nodeIdB , s );
119
+ // it is possible that the last Ca > Cb, but there are no more neighbours Ca of A
120
+ // so if there are more neighbours Cb of B
121
+ if (decompressingCursorB .hasNextVLong ()) {
122
+ // we take the next neighbour Cb of B with id >= Ca
123
+ CfromB = decompressingCursorB .advance (CfromA );
124
+ // check for triangle
125
+ if (CfromA == CfromB && CfromA > lastNodeC && degreeFilter .test (CfromB )) {
126
+ consumer .accept (nodeIdA , nodeIdB , CfromB );
132
127
}
133
128
}
134
129
}
0 commit comments