Skip to content

Commit 8f1c465

Browse files
s1ckDarthMax
andcommitted
Fix size allocation in IdMapBuilder#buildSparseNodeMapping
We need to allocate `highestNodeId + 1` to be able to store an node with `id = highestNodeId`. The number of pages in the HugeSparseLongArray if based on the size. Co-authored-by: Max Kießling <[email protected]>
1 parent 1bb8650 commit 8f1c465

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

core/src/main/java/org/neo4j/graphalgo/core/loading/IdMapBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static SparseNodeMapping buildSparseNodeMapping(
5757
int concurrency,
5858
AllocationTracker tracker
5959
) {
60-
SparseNodeMapping.Builder nodeMappingBuilder = SparseNodeMapping.Builder.create(highestNodeId == 0 ? 1 : highestNodeId, tracker);
60+
SparseNodeMapping.Builder nodeMappingBuilder = SparseNodeMapping.Builder.create(highestNodeId + 1, tracker);
6161
ParallelUtil.readParallel(
6262
concurrency,
6363
graphIds.size(),
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2017-2020 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.graphalgo.core.loading;
21+
22+
import org.junit.jupiter.api.Test;
23+
import org.neo4j.graphalgo.core.utils.paged.AllocationTracker;
24+
import org.neo4j.graphalgo.core.utils.paged.HugeLongArray;
25+
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
27+
28+
class IdMapBuilderTest {
29+
30+
@Test
31+
void buildSparseNodeMappingWithPageSizeEntries() {
32+
long nodeId = 4096; // equals the PAGE_SIZE in a HugeSparseLongArray
33+
34+
HugeLongArray hugeLongArray = HugeLongArray.newArray(1, AllocationTracker.EMPTY);
35+
hugeLongArray.set(0, nodeId);
36+
37+
SparseNodeMapping hugeSparseLongArray = IdMapBuilder.buildSparseNodeMapping(
38+
hugeLongArray,
39+
nodeId,
40+
1,
41+
AllocationTracker.EMPTY
42+
);
43+
44+
assertTrue(hugeSparseLongArray.contains(nodeId));
45+
}
46+
}

0 commit comments

Comments
 (0)