Skip to content

Commit 8f09af7

Browse files
Store relationship cursor caches as list
1 parent c8b49cc commit 8f09af7

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

cypher/api/storage-engine-adapter/src/main/java/org/neo4j/gds/compat/AbstractInMemoryRelationshipPropertyCursor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package org.neo4j.gds.compat;
2121

22+
import org.eclipse.collections.api.list.primitive.DoubleList;
2223
import org.neo4j.gds.core.cypher.CypherGraphStore;
2324
import org.neo4j.token.TokenHolders;
2425
import org.neo4j.values.storable.Value;
@@ -30,7 +31,7 @@ public abstract class AbstractInMemoryRelationshipPropertyCursor extends Abstrac
3031
protected final CypherGraphStore graphStore;
3132
protected final TokenHolders tokenHolders;
3233
protected InMemoryPropertySelection selection;
33-
private double[] propertyValues;
34+
private DoubleList propertyValues;
3435
private int[] propertyIds;
3536
private int index;
3637

@@ -41,7 +42,7 @@ protected AbstractInMemoryRelationshipPropertyCursor(CypherGraphStore graphStore
4142
reset();
4243
}
4344

44-
public void initRelationshipPropertyCursor(long id, int[] propertyIds, double[] propertyValues, InMemoryPropertySelection selection) {
45+
public void initRelationshipPropertyCursor(long id, int[] propertyIds, DoubleList propertyValues, InMemoryPropertySelection selection) {
4546
setId(id);
4647
setRelId(id);
4748
this.index = -1;
@@ -82,7 +83,7 @@ public ValueGroup propertyType() {
8283
@Override
8384
public Value propertyValue() {
8485
if (getRelId() != NO_ID && this.index < propertyIds.length) {
85-
return Values.doubleValue(propertyValues[this.index]);
86+
return Values.doubleValue(propertyValues.get(this.index));
8687
}
8788
throw new IllegalStateException("Property cursor is not initialized.");
8889
}

cypher/api/storage-engine-adapter/src/main/java/org/neo4j/gds/storageengine/InMemoryRelationshipCursor.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
package org.neo4j.gds.storageengine;
2121

22+
import org.eclipse.collections.api.list.primitive.MutableDoubleList;
23+
import org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList;
2224
import org.neo4j.gds.api.AdjacencyCursor;
2325
import org.neo4j.gds.api.AdjacencyProperties;
2426
import org.neo4j.gds.api.PropertyCursor;
@@ -35,22 +37,23 @@
3537

3638
import java.util.Arrays;
3739
import java.util.List;
40+
import java.util.stream.Collectors;
3841

3942
public abstract class InMemoryRelationshipCursor extends RelationshipRecord implements RelationshipVisitor<RuntimeException>, StorageRelationshipCursor {
4043

4144
protected final CypherGraphStore graphStore;
4245
protected final TokenHolders tokenHolders;
4346
private final List<RelationshipIds.RelationshipIdContext> relationshipIdContexts;
44-
private final AdjacencyCursor[] adjacencyCursorCache;
45-
private final PropertyCursor[][] propertyCursorCache;
47+
private final List<AdjacencyCursor> adjacencyCursorCache;
48+
private final List<PropertyCursor[]> propertyCursorCache;
49+
private final MutableDoubleList propertyValuesCache;
4650

4751
protected long sourceId;
4852
protected long targetId;
4953
protected RelationshipSelection selection;
5054

5155
private AdjacencyCursor adjacencyCursor;
5256
private PropertyCursor[] propertyCursors;
53-
private final double[] propertyValuesCache;
5457
private int relationshipTypeOffset;
5558
private int relationshipContextIndex;
5659
private int[] propertyIds;
@@ -62,18 +65,18 @@ public InMemoryRelationshipCursor(CypherGraphStore graphStore, TokenHolders toke
6265
this.relationshipIdContexts = this.graphStore.relationshipIds().relationshipIdContexts();
6366
this.adjacencyCursorCache = relationshipIdContexts.stream()
6467
.map(context -> context.adjacencyList().rawAdjacencyCursor())
65-
.toArray(AdjacencyCursor[]::new);
68+
.collect(Collectors.toList());
6669

6770
this.propertyCursorCache = relationshipIdContexts.stream()
6871
.map(context -> Arrays
6972
.stream(context.adjacencyProperties())
7073
.map(AdjacencyProperties::rawPropertyCursor)
7174
.toArray(PropertyCursor[]::new)
7275
)
73-
.toArray(PropertyCursor[][]::new);
76+
.collect(Collectors.toList());
7477

75-
var maxPropertySize = Arrays.stream(propertyCursorCache).mapToInt(a -> a.length).max().orElse(0);
76-
this.propertyValuesCache = new double[maxPropertySize];
78+
var maxPropertySize = propertyCursorCache.stream().mapToInt(a -> a.length).max().orElse(0);
79+
this.propertyValuesCache = new DoubleArrayList(new double[maxPropertySize]);
7780
}
7881

7982
@Override
@@ -117,7 +120,7 @@ public boolean next() {
117120
setId(getId() + 1);
118121

119122
for (int i = 0; i < propertyCursors.length; i++) {
120-
propertyValuesCache[i] = Double.longBitsToDouble(propertyCursors[i].nextLong());
123+
propertyValuesCache.set(i, Double.longBitsToDouble(propertyCursors[i].nextLong()));
121124
}
122125

123126
return true;
@@ -178,14 +181,14 @@ private boolean progressToNextContext() {
178181
setType(context.relationshipTypeId());
179182

180183
// initialize the adjacency cursor
181-
var reuseCursor = adjacencyCursorCache[relationshipContextIndex];
184+
var reuseCursor = adjacencyCursorCache.get(relationshipContextIndex);
182185
this.adjacencyCursor = context
183186
.adjacencyList()
184187
.adjacencyCursor(reuseCursor, this.sourceId);
185188

186189
// initialize the property cursors
187190
this.propertyIds = context.propertyIds();
188-
this.propertyCursors = propertyCursorCache[relationshipContextIndex];
191+
this.propertyCursors = propertyCursorCache.get(relationshipContextIndex);
189192
var adjacencyProperties = context.adjacencyProperties();
190193
for (int i = 0; i < propertyCursors.length; i++) {
191194
adjacencyProperties[i].propertyCursor(propertyCursors[i], this.sourceId);

0 commit comments

Comments
 (0)