Skip to content

Commit 126352c

Browse files
authored
Merge pull request #10295 from neo-technology/snowgraph-deduplicate-node-id-projections
Deduplicate snowgraph node ids
2 parents 20cb0e1 + ac999ad commit 126352c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

core/src/main/java/org/neo4j/gds/core/utils/paged/ShardedByteArrayLongMap.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,12 @@ private Shard(AtomicLong nextId, long capacity) {
246246

247247
long addNode(byte[] nodeId) {
248248
this.assertIsUnderLock();
249+
int index = mapping.indexOf(nodeId);
250+
if (mapping.indexExists(index)) {
251+
return -mapping.indexGet(index) - 1;
252+
}
249253
long mappedId = nextId.getAndIncrement();
250-
mapping.put(nodeId, mappedId);
254+
mapping.indexInsert(index, nodeId, mappedId);
251255
return mappedId;
252256
}
253257
}

core/src/test/java/org/neo4j/gds/core/utils/paged/ShardedByteArrayLongMapTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ void addNodesDifferentObject(@ForAll("nodes") @Size(100) byte[][] nodes) {
100100
}
101101

102102
@Test
103-
void doesNotActuallyDeduplicateNodes() {
103+
void addExistingNode() {
104104
byte[] node1 = "foobar".getBytes(StandardCharsets.UTF_8);
105105
byte[] node2 = "foobar".getBytes(StandardCharsets.UTF_8);
106106
var builder = ShardedByteArrayLongMap.builder(new Concurrency(1));
107107
long mappedNode1 = builder.addNode(node1);
108108
assertThat(mappedNode1).isGreaterThanOrEqualTo(0);
109109
long mappedNode2 = builder.addNode(node2);
110-
assertThat(mappedNode2).isGreaterThanOrEqualTo(0).isNotEqualTo(mappedNode1);
110+
assertThat(mappedNode2).isEqualTo(-(mappedNode1 + 1));
111111
}
112112

113113
@ParameterizedTest

0 commit comments

Comments
 (0)