Skip to content

Commit 590fe70

Browse files
committed
Remove lead, follow, s, t
With the removal of the longer-cursor optimisation we do not need these. Added more comments to explain the flow.
1 parent b94e069 commit 590fe70

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

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

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,20 @@ public void intersectAll(long nodeIdA, IntersectionConsumer consumer) {
6666
AdjacencyList adjacency = this.adjacency;
6767

6868
AdjacencyList.DecompressingCursor mainDecompressingCursor = cursor(nodeIdA, cache, offsets, adjacency);
69+
6970
// find first neighbour B of A id > A
7071
long nodeIdB = mainDecompressingCursor.skipUntil(nodeIdA);
7172
if (nodeIdA > nodeIdB) {
7273
return;
7374
}
7475

75-
AdjacencyList.DecompressingCursor lead, follow, decompressingCursorA = cacheA, decompressingCursorB = cacheB;
76+
AdjacencyList.DecompressingCursor decompressingCursorA = cacheA, decompressingCursorB = cacheB;
7677

77-
long CfromB;
7878
long CfromA;
79-
79+
long CfromB;
8080
long lastNodeB;
8181
long lastNodeC;
8282

83-
long s,t;
84-
8583
// for all neighbours of A
8684
while (mainDecompressingCursor.hasNextVLong()) {
8785
lastNodeC = -1;
@@ -103,32 +101,29 @@ public void intersectAll(long nodeIdA, IntersectionConsumer consumer) {
103101
lastNodeC = CfromB;
104102
}
105103

106-
lead = decompressingCursorB;
107-
s = CfromB;
108-
follow = decompressingCursorA;
109-
t = CfromA;
110-
111104
// 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);
116111
}
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;
120116
}
121117
}
122118

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);
132127
}
133128
}
134129
}

0 commit comments

Comments
 (0)