Skip to content

Commit 3caabcd

Browse files
committed
Update documentation to reflect actual implementation and adapt usage accordingly
1 parent a50889e commit 3caabcd

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

algo/src/main/java/org/neo4j/gds/triangle/intersect/GraphIntersect.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,25 @@ public void intersectAll(long nodeA, IntersectionConsumer consumer) {
126126
if (neighboursB.hasNextVLong()) {
127127
// we take the next neighbour Cb of B with id >= Ca
128128
nodeCFromB = neighboursB.advance(nodeCFromA);
129-
if (degreeFilter.test(degree(nodeCFromB))) {
130-
checkForAndEmitTriangle(consumer, nodeA, nodeB, nodeCFromA, nodeCFromB, triangleC);
129+
// B had some more nodes, but none of them were >= Ca, so we skip it
130+
if (nodeCFromB != NOT_FOUND) {
131+
var degreeCFromB = degree(nodeCFromB);
132+
133+
if (degreeFilter.test(degreeCFromB)) {
134+
checkForAndEmitTriangle(consumer, nodeA, nodeB, nodeCFromA, nodeCFromB, triangleC);
135+
}
131136
}
132137
}
133138
}
134139
}
135140

136141
// skip until the next neighbour B of A with id > (current) B
137142
nodeB = neighboursAMain.skipUntil(nodeB);
143+
144+
// There are no more neighbors that are relevant to us
145+
if (nodeB == NOT_FOUND) {
146+
return;
147+
}
138148
}
139149

140150
cacheA = neighboursA;
@@ -151,6 +161,7 @@ private long checkForAndEmitTriangle(
151161
) {
152162
// if Ca = Cb there exists a triangle
153163
// if Ca = triangleC we have already counted it
164+
// Ca might also be NOT_FOUND, we ignore those as well
154165
if (nodeCa == nodeCb && nodeCa > triangleC) {
155166
consumer.accept(nodeA, nodeB, nodeCa);
156167
return nodeCa;

core/src/main/java/org/neo4j/gds/api/AdjacencyCursor.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,15 @@ public interface AdjacencyCursor extends AutoCloseable {
7171
*/
7272
int remaining();
7373

74-
// DOCTODO: I think this documentation if either out of date or misleading.
75-
// Either we skip all blocks and return -1 or we find a value that is strictly larger.
7674
/**
7775
* Read and decode target ids until it is strictly larger than ({@literal >}) the provided {@code target}.
78-
* Might return an id that is less than or equal to {@code target} iff the cursor did exhaust before finding an
79-
* id that is large enough.
80-
* {@code skipUntil(target) <= target} can be used to distinguish the no-more-ids case and afterwards {@link #hasNextVLong()}
81-
* will return {@code false}
76+
* If there are no such targets before this cursor is exhausted, {@link org.neo4j.gds.api.AdjacencyCursor#NOT_FOUND -1} is returned.
8277
*/
8378
long skipUntil(long nodeId);
8479

8580
/**
8681
* Read and decode target ids until it is larger than or equal ({@literal >=}) the provided {@code target}.
87-
* Might return an id that is less than {@code target} iff the cursor did exhaust before finding an
88-
* id that is large enough.
89-
* {@code advance(target) < target} can be used to distinguish the no-more-ids case and afterwards {@link #hasNextVLong()}
90-
* will return {@code false}
82+
* If there are no such targets before this cursor is exhausted, {@link org.neo4j.gds.api.AdjacencyCursor#NOT_FOUND -1} is returned.
9183
*/
9284
long advance(long nodeId);
9385

core/src/main/java/org/neo4j/gds/core/huge/TransientCompressedList.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,9 @@ public long peekVLong() {
213213
return decompress.peek(remaining);
214214
}
215215

216-
// TODO: I think this documentation if either out of date or misleading.
217-
// Either we skip all blocks and return -1 or we find a value that is strictly larger.
218216
/**
219217
* Read and decode target ids until it is strictly larger than ({@literal >}) the provided {@code target}.
220-
* Might return an id that is less than or equal to {@code target} iff the cursor did exhaust before finding an
221-
* id that is large enough.
222-
* {@code skipUntil(target) <= target} can be used to distinguish the no-more-ids case and afterwards {@link #hasNextVLong()}
223-
* will return {@code false}
218+
* If there are no such targets before this cursor is exhausted, {@link org.neo4j.gds.api.AdjacencyCursor#NOT_FOUND -1} is returned.
224219
*/
225220
@Override
226221
public long skipUntil(long target) {
@@ -231,10 +226,7 @@ public long skipUntil(long target) {
231226

232227
/**
233228
* Read and decode target ids until it is larger than or equal ({@literal >=}) the provided {@code target}.
234-
* Might return an id that is less than {@code target} iff the cursor did exhaust before finding an
235-
* id that is large enough.
236-
* {@code advance(target) < target} can be used to distinguish the no-more-ids case and afterwards {@link #hasNextVLong()}
237-
* will return {@code false}
229+
* If there are no such targets before this cursor is exhausted, {@link org.neo4j.gds.api.AdjacencyCursor#NOT_FOUND -1} is returned.
238230
*/
239231
@Override
240232
public long advance(long target) {

0 commit comments

Comments
 (0)