@@ -73,16 +73,23 @@ public void intersectAll(long nodeA, IntersectionConsumer consumer) {
73
73
return ;
74
74
}
75
75
76
- AdjacencyList .DecompressingCursor neighboursA = cacheA , neighboursB = cacheB ;
77
-
76
+ // iterates over neighbours of A
77
+ AdjacencyList .DecompressingCursor neighboursA = cacheA ;
78
+ // current neighbour of A
78
79
long nodeCa ;
80
+ // iterates over neighbours of B
81
+ AdjacencyList .DecompressingCursor neighboursB = cacheB ;
82
+ // current neighbour of B
79
83
long nodeCb ;
80
- long lastNodeB ;
81
- long lastNodeC ;
84
+
85
+ // last node where Ca = Cb
86
+ // prevents counting a new triangle for parallel relationships
87
+ long triangleC ;
82
88
83
89
// for all neighbours of A
84
90
while (neighboursAMain .hasNextVLong ()) {
85
- lastNodeC = -1 ;
91
+ // we have not yet seen a triangle
92
+ triangleC = -1 ;
86
93
// check the second node's degree
87
94
if (degreeFilter .test (nodeB )) {
88
95
neighboursB = cursor (nodeB , neighboursB , offsets , adjacency );
@@ -98,9 +105,9 @@ public void intersectAll(long nodeA, IntersectionConsumer consumer) {
98
105
99
106
// if Ca = Cb we have found a triangle
100
107
// we only submit one triangle per parallel relationship
101
- if (nodeCa == nodeCb && nodeCb > lastNodeC ) {
102
- consumer .accept (nodeA , nodeB , nodeCb );
103
- lastNodeC = nodeCb ;
108
+ if (nodeCa == nodeCb && nodeCa > triangleC ) {
109
+ consumer .accept (nodeA , nodeB , nodeCa );
110
+ triangleC = nodeCa ;
104
111
}
105
112
106
113
// while both A and B have more neighbours
@@ -112,9 +119,9 @@ public void intersectAll(long nodeA, IntersectionConsumer consumer) {
112
119
nodeCa = neighboursA .advance (nodeCb );
113
120
}
114
121
// check for triangle
115
- if (nodeCa == nodeCb && nodeCa > lastNodeC && degreeFilter .test (nodeCb )) {
116
- consumer .accept (nodeA , nodeB , nodeCb );
117
- lastNodeC = nodeCb ;
122
+ if (nodeCa == nodeCb && nodeCa > triangleC && degreeFilter .test (nodeCa )) {
123
+ consumer .accept (nodeA , nodeB , nodeCa );
124
+ triangleC = nodeCa ;
118
125
}
119
126
}
120
127
@@ -124,18 +131,15 @@ public void intersectAll(long nodeA, IntersectionConsumer consumer) {
124
131
// we take the next neighbour Cb of B with id >= Ca
125
132
nodeCb = neighboursB .advance (nodeCa );
126
133
// check for triangle
127
- if (nodeCa == nodeCb && nodeCa > lastNodeC && degreeFilter .test (nodeCb )) {
128
- consumer .accept (nodeA , nodeB , nodeCb );
134
+ if (nodeCa == nodeCb && nodeCa > triangleC && degreeFilter .test (nodeCa )) {
135
+ consumer .accept (nodeA , nodeB , nodeCa );
129
136
}
130
137
}
131
138
}
132
139
}
133
140
134
- // TODO: use skipUntil?
135
- lastNodeB = nodeB ;
136
- while (neighboursAMain .hasNextVLong () && nodeB == lastNodeB ) {
137
- nodeB = neighboursAMain .nextVLong ();
138
- }
141
+ // skip until the next neighbour B of A with id > (current) B
142
+ nodeB = skipUntil (neighboursAMain , nodeB );
139
143
}
140
144
}
141
145
0 commit comments