1919 */
2020package org .neo4j .gds .core .utils .paged ;
2121
22- import org .eclipse .collections .api .block .HashingStrategy ;
23- import org .eclipse .collections .api .map .primitive .MutableObjectLongMap ;
24- import org .eclipse .collections .api .map .primitive .ObjectLongMap ;
22+ import com .carrotsearch .hppc .BitMixer ;
23+ import com .carrotsearch .hppc .ObjectLongHashMap ;
24+ import com .carrotsearch .hppc .ObjectLongMap ;
25+ import com .carrotsearch .hppc .procedures .ObjectLongProcedure ;
2526import org .eclipse .collections .impl .collection .mutable .AbstractMultiReaderMutableCollection ;
26- import org .eclipse .collections .impl .map .mutable .primitive .ObjectLongHashMapWithHashingStrategy ;
2727import org .neo4j .gds .api .IdMap ;
2828import org .neo4j .gds .collections .ha .HugeObjectArray ;
2929import org .neo4j .gds .core .concurrency .Concurrency ;
@@ -60,7 +60,7 @@ private ShardedByteArrayLongMap(
6060
6161 public long toMappedNodeId (byte [] nodeId ) {
6262 var shard = findShard (nodeId , this .originalNodeMappingShards , this .shardShift );
63- return shard .getIfAbsent (nodeId , IdMap .NOT_FOUND );
63+ return shard .getOrDefault (nodeId , IdMap .NOT_FOUND );
6464 }
6565
6666 public boolean contains (byte [] originalId ) {
@@ -116,7 +116,7 @@ private static <S extends MapShard> ShardedByteArrayLongMap build(
116116 mapShards , idx -> {
117117 var shard = shards [idx ];
118118 var mapping = shard .intoMapping ();
119- mapping .forEachKeyValue ( (originalId , mappedId ) -> {
119+ mapping .forEach (( ObjectLongProcedure <? super byte []>) (originalId , mappedId ) -> {
120120 internalNodeMapping .set (mappedId , originalId );
121121 });
122122 return mapping ;
@@ -132,33 +132,39 @@ private static <S extends MapShard> ShardedByteArrayLongMap build(
132132
133133 abstract static class MapShard {
134134
135- private static class ArrayHashingStrategy implements HashingStrategy <byte []> {
135+ private static final class Map extends ObjectLongHashMap <byte []> {
136+
137+ Map () {
138+ super ();
139+ }
140+
141+ Map (int initialCapacity ) {
142+ super (initialCapacity );
143+ }
144+
136145 @ Override
137- public int computeHashCode (byte [] object ) {
138- return Arrays .hashCode (object );
146+ protected int hashKey (byte [] key ) {
147+ return BitMixer . mix ( Arrays .hashCode (key ), this . keyMixer );
139148 }
140149
141150 @ Override
142- public boolean equals (byte [] object1 , byte [] object2 ) {
143- return Arrays .equals (object1 , object2 );
151+ protected boolean equals (Object v1 , Object v2 ) {
152+ return Arrays .equals (( byte []) v1 , ( byte []) v2 );
144153 }
145154 }
146155
147156 private final ReentrantLock lock ;
148157 private final AbstractMultiReaderMutableCollection .LockWrapper lockWrapper ;
149- final MutableObjectLongMap <byte []> mapping ;
158+ final ObjectLongMap <byte []> mapping ;
150159
151160 MapShard () {
152- this .mapping = new ObjectLongHashMapWithHashingStrategy <>( new ArrayHashingStrategy () );
161+ this .mapping = new Map ( );
153162 this .lock = new ReentrantLock ();
154163 this .lockWrapper = new AbstractMultiReaderMutableCollection .LockWrapper (lock );
155164 }
156165
157166 MapShard (long capacity ) {
158- this .mapping = new ObjectLongHashMapWithHashingStrategy <>(
159- new ArrayHashingStrategy (),
160- Math .toIntExact (capacity )
161- );
167+ this .mapping = new Map (Math .toIntExact (capacity ));
162168 this .lock = new ReentrantLock ();
163169 this .lockWrapper = new AbstractMultiReaderMutableCollection .LockWrapper (lock );
164170 }
@@ -172,7 +178,7 @@ void assertIsUnderLock() {
172178 assert this .lock .isHeldByCurrentThread () : "addNode must only be called while holding the lock" ;
173179 }
174180
175- MutableObjectLongMap <byte []> intoMapping () {
181+ ObjectLongMap <byte []> intoMapping () {
176182 return mapping ;
177183 }
178184 }
@@ -240,12 +246,12 @@ private Shard(AtomicLong nextId, long capacity) {
240246
241247 long addNode (byte [] nodeId ) {
242248 this .assertIsUnderLock ();
243- long mappedId = mapping .getIfAbsent (nodeId , IdMap . NOT_FOUND );
244- if (mappedId != IdMap . NOT_FOUND ) {
245- return -mappedId - 1 ;
249+ int index = mapping .indexOf (nodeId );
250+ if (mapping . indexExists ( index ) ) {
251+ return -mapping . indexGet ( index ) - 1 ;
246252 }
247- mappedId = nextId .getAndIncrement ();
248- mapping .put ( nodeId , mappedId );
253+ long mappedId = nextId .getAndIncrement ();
254+ mapping .indexInsert ( index , nodeId , mappedId );
249255 return mappedId ;
250256 }
251257 }
0 commit comments