Skip to content

Commit e6a8773

Browse files
committed
Use skipUntil instead of manual skipping
- Consistently use Ca when Ca = Cb - Remove redundant lastNodeB - Rename lastNodeC to triangleC - more comments
1 parent e731266 commit e6a8773

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

core/src/main/java/org/neo4j/graphalgo/core/huge/HugeGraphIntersectImpl.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,23 @@ public void intersectAll(long nodeA, IntersectionConsumer consumer) {
7373
return;
7474
}
7575

76-
AdjacencyList.DecompressingCursor neighboursA = cacheA, neighboursB = cacheB;
77-
76+
// iterates over neighbours of A
77+
AdjacencyList.DecompressingCursor neighboursA = cacheA;
78+
// current neighbour of A
7879
long nodeCa;
80+
// iterates over neighbours of B
81+
AdjacencyList.DecompressingCursor neighboursB = cacheB;
82+
// current neighbour of B
7983
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;
8288

8389
// for all neighbours of A
8490
while (neighboursAMain.hasNextVLong()) {
85-
lastNodeC = -1;
91+
// we have not yet seen a triangle
92+
triangleC = -1;
8693
// check the second node's degree
8794
if (degreeFilter.test(nodeB)) {
8895
neighboursB = cursor(nodeB, neighboursB, offsets, adjacency);
@@ -98,9 +105,9 @@ public void intersectAll(long nodeA, IntersectionConsumer consumer) {
98105

99106
// if Ca = Cb we have found a triangle
100107
// 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;
104111
}
105112

106113
// while both A and B have more neighbours
@@ -112,9 +119,9 @@ public void intersectAll(long nodeA, IntersectionConsumer consumer) {
112119
nodeCa = neighboursA.advance(nodeCb);
113120
}
114121
// 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;
118125
}
119126
}
120127

@@ -124,18 +131,15 @@ public void intersectAll(long nodeA, IntersectionConsumer consumer) {
124131
// we take the next neighbour Cb of B with id >= Ca
125132
nodeCb = neighboursB.advance(nodeCa);
126133
// 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);
129136
}
130137
}
131138
}
132139
}
133140

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);
139143
}
140144
}
141145

0 commit comments

Comments
 (0)