Skip to content

Commit

Permalink
Merge pull request #8243 from IoannisPanagiotas/composite-adj-fix-onc…
Browse files Browse the repository at this point in the history
…e-and-for-all

Composite adj fix once and for all
  • Loading branch information
IoannisPanagiotas authored Oct 11, 2023
2 parents e2adad6 + 0711a68 commit cc9de01
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ public List<AdjacencyCursor> cursors() {
return cursors;
}

void updateCursorsQueue() {
void reinitializeCursors() {
cursorQueue.clear();
cursorQueue.addAll(cursors);
initializeQueue();

}
@Override
public int size() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ public CompositeAdjacencyCursor adjacencyCursor(@Nullable AdjacencyCursor reuse,
if (reuse instanceof CompositeAdjacencyCursor) {
var compositeReuse = (CompositeAdjacencyCursor) reuse;
var iter = compositeReuse.cursors().listIterator();
boolean cursorsAreUpdated = false;

while (iter.hasNext()) {
var index = iter.nextIndex();
var cursor = iter.next();
var newCursor = adjacencyLists.get(index).adjacencyCursor(cursor, node, fallbackValue);
if (newCursor != cursor) {
iter.set(adjacencyCursorWrapperFactory.create(newCursor));
cursorsAreUpdated = true;
}
}
if (cursorsAreUpdated) {
compositeReuse.updateCursorsQueue();
}
//we must update all the cursors all the time because old cursor might be further ahead instead of start
//then, object equality can be then the same, but in reality not so much
compositeReuse.reinitializeCursors();

return compositeReuse;
}
return adjacencyCursor(node, fallbackValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
package org.neo4j.gds.core.huge;

import org.junit.jupiter.api.Test;
import org.neo4j.gds.api.Graph;
import org.neo4j.gds.extension.GdlExtension;
import org.neo4j.gds.extension.GdlGraph;
import org.neo4j.gds.extension.Inject;
import org.neo4j.gds.api.Graph;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

@GdlExtension
Expand All @@ -47,4 +48,26 @@ void shouldIgnoreInputDegreeForCursor() {
var cursor = adjacencyList.adjacencyCursor(0);
assertEquals(2, cursor.remaining());
}

@Test
void shouldReuseCursor() {

var adjacencyList = ((UnionGraph) graph).relationshipTopology();
var cursor = adjacencyList.adjacencyCursor(null, 0);
assertThat(cursor.peekVLong()).isEqualTo(1L);
cursor.nextVLong();

cursor = adjacencyList.adjacencyCursor(cursor, 0);
assertThat(cursor.peekVLong()).isEqualTo(1L);


cursor.nextVLong();
cursor.nextVLong();

cursor = adjacencyList.adjacencyCursor(cursor, 0);
assertThat(cursor.hasNextVLong()).isTrue();


}

}

0 comments on commit cc9de01

Please sign in to comment.