1919 */
2020package org .neo4j .gds .storageengine ;
2121
22+ import org .eclipse .collections .api .list .primitive .MutableDoubleList ;
23+ import org .eclipse .collections .impl .list .mutable .primitive .DoubleArrayList ;
2224import org .neo4j .gds .api .AdjacencyCursor ;
2325import org .neo4j .gds .api .AdjacencyProperties ;
2426import org .neo4j .gds .api .PropertyCursor ;
3537
3638import java .util .Arrays ;
3739import java .util .List ;
40+ import java .util .stream .Collectors ;
3841
3942public 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