Skip to content

Commit ae6b81e

Browse files
committed
Move LabelInformation.Builder factory methods out of the interface
1 parent 4684d77 commit ae6b81e

File tree

12 files changed

+73
-38
lines changed

12 files changed

+73
-38
lines changed

algo/src/test/java/org/neo4j/gds/embeddings/fastrp/FastRPTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import org.neo4j.gds.core.ImmutableGraphDimensions;
4141
import org.neo4j.gds.core.concurrency.Pools;
4242
import org.neo4j.gds.core.loading.ArrayIdMap;
43-
import org.neo4j.gds.core.loading.LabelInformation;
43+
import org.neo4j.gds.core.loading.LabelInformationBuilders;
4444
import org.neo4j.gds.core.loading.construction.GraphFactory;
4545
import org.neo4j.gds.core.loading.construction.RelationshipsBuilder;
4646
import org.neo4j.gds.core.utils.Intersections;
@@ -635,7 +635,7 @@ void shouldBeDeterministicGivenSameOriginalIds() {
635635
var firstIdMap = new ArrayIdMap(
636636
firstMappedToOriginal,
637637
firstOriginalToMappedBuilder.build(),
638-
LabelInformation.single(new NodeLabel("hello")).build(nodeCount, firstMappedToOriginal::get),
638+
LabelInformationBuilders.singleLabel(NodeLabel.of("hello")).build(nodeCount, firstMappedToOriginal::get),
639639
nodeCount,
640640
nodeCount - 1
641641
);
@@ -658,7 +658,7 @@ void shouldBeDeterministicGivenSameOriginalIds() {
658658
var secondIdMap = new ArrayIdMap(
659659
secondMappedToOriginal,
660660
secondOriginalToMappedBuilder.build(),
661-
LabelInformation.single(new NodeLabel("hello")).build(nodeCount, secondMappedToOriginal::get),
661+
LabelInformationBuilders.singleLabel(NodeLabel.of("hello")).build(nodeCount, secondMappedToOriginal::get),
662662
nodeCount,
663663
nodeCount - 1
664664
);

algo/src/test/java/org/neo4j/gds/embeddings/hashgnn/HashGNNTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.neo4j.gds.compat.TestLog;
3737
import org.neo4j.gds.core.concurrency.Pools;
3838
import org.neo4j.gds.core.loading.ArrayIdMap;
39-
import org.neo4j.gds.core.loading.LabelInformation;
39+
import org.neo4j.gds.core.loading.LabelInformationBuilders;
4040
import org.neo4j.gds.core.loading.construction.GraphFactory;
4141
import org.neo4j.gds.core.loading.construction.RelationshipsBuilder;
4242
import org.neo4j.gds.core.utils.Intersections;
@@ -366,7 +366,7 @@ void shouldBeDeterministicGivenSameOriginalIds() {
366366
var firstIdMap = new ArrayIdMap(
367367
firstMappedToOriginal,
368368
firstOriginalToMappedBuilder.build(),
369-
LabelInformation.single(new NodeLabel("hello")).build(nodeCount, firstMappedToOriginal::get),
369+
LabelInformationBuilders.singleLabel(new NodeLabel("hello")).build(nodeCount, firstMappedToOriginal::get),
370370
nodeCount,
371371
nodeCount - 1
372372
);
@@ -389,7 +389,7 @@ void shouldBeDeterministicGivenSameOriginalIds() {
389389
var secondIdMap = new ArrayIdMap(
390390
secondMappedToOriginal,
391391
secondOriginalToMappedBuilder.build(),
392-
LabelInformation.single(new NodeLabel("hello")).build(nodeCount, secondMappedToOriginal::get),
392+
LabelInformationBuilders.singleLabel(NodeLabel.of("hello")).build(nodeCount, secondMappedToOriginal::get),
393393
nodeCount,
394394
nodeCount - 1
395395
);

algo/src/test/java/org/neo4j/gds/embeddings/node2vec/Node2VecTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import org.neo4j.gds.core.GraphDimensions;
4646
import org.neo4j.gds.core.concurrency.Pools;
4747
import org.neo4j.gds.core.loading.ArrayIdMap;
48-
import org.neo4j.gds.core.loading.LabelInformation;
48+
import org.neo4j.gds.core.loading.LabelInformationBuilders;
4949
import org.neo4j.gds.core.loading.construction.GraphFactory;
5050
import org.neo4j.gds.core.loading.construction.RelationshipsBuilder;
5151
import org.neo4j.gds.core.utils.Intersections;
@@ -271,7 +271,7 @@ void shouldBeFairlyConsistentUnderOriginalIds(EmbeddingInitializer embeddingInit
271271
var firstIdMap = new ArrayIdMap(
272272
firstMappedToOriginal,
273273
firstOriginalToMappedBuilder.build(),
274-
LabelInformation.single(new NodeLabel("hello")).build(nodeCount, firstMappedToOriginal::get),
274+
LabelInformationBuilders.singleLabel(NodeLabel.of("hello")).build(nodeCount, firstMappedToOriginal::get),
275275
nodeCount,
276276
nodeCount - 1
277277
);
@@ -292,7 +292,7 @@ void shouldBeFairlyConsistentUnderOriginalIds(EmbeddingInitializer embeddingInit
292292
var secondIdMap = new ArrayIdMap(
293293
secondMappedToOriginal,
294294
secondOriginalToMappedBuilder.build(),
295-
LabelInformation.single(new NodeLabel("hello")).build(nodeCount, secondMappedToOriginal::get),
295+
LabelInformationBuilders.singleLabel(NodeLabel.of("hello")).build(nodeCount, secondMappedToOriginal::get),
296296
nodeCount,
297297
nodeCount - 1
298298
);

algo/src/test/java/org/neo4j/gds/similarity/filtering/NodeFilterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.neo4j.gds.NodeLabel;
2626
import org.neo4j.gds.core.huge.DirectIdMap;
2727
import org.neo4j.gds.core.loading.ArrayIdMapBuilder;
28-
import org.neo4j.gds.core.loading.LabelInformation;
28+
import org.neo4j.gds.core.loading.LabelInformationBuilders;
2929

3030
import java.util.Collections;
3131
import java.util.List;
@@ -45,7 +45,7 @@ void shouldFilterBasedOnLabel() {
4545
labelTokenNodeLabelMappings.put(1, Collections.singletonList(labelOne));
4646
labelTokenNodeLabelMappings.put(2, Collections.singletonList(labelTwo));
4747

48-
var labelInformationBuilder = LabelInformation.builder(4, labelTokenNodeLabelMappings);
48+
var labelInformationBuilder = LabelInformationBuilders.multiLabelWithCapacityAndLabelInformation(4, labelTokenNodeLabelMappings);
4949
labelInformationBuilder.addNodeIdToLabel(labelOne, 0);
5050
labelInformationBuilder.addNodeIdToLabel(labelTwo, 1);
5151
labelInformationBuilder.addNodeIdToLabel(labelOne, 2);

core/src/main/java/org/neo4j/gds/core/loading/LabelInformation.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.neo4j.gds.core.loading;
2121

2222
import com.carrotsearch.hppc.BitSet;
23-
import com.carrotsearch.hppc.IntObjectMap;
2423
import org.neo4j.gds.NodeLabel;
2524
import org.neo4j.gds.api.IdMap;
2625

@@ -31,20 +30,6 @@
3130
import java.util.function.LongUnaryOperator;
3231

3332
public interface LabelInformation {
34-
static Builder single(NodeLabel singleLabel) {
35-
return new SingleLabelInformation.Builder(singleLabel);
36-
}
37-
38-
static Builder builder(long expectedCapacity) {
39-
return MultiLabelInformation.Builder.of(expectedCapacity);
40-
}
41-
42-
static Builder builder(
43-
long expectedCapacity,
44-
IntObjectMap<List<NodeLabel>> labelTokenNodeLabelMapping
45-
) {
46-
return MultiLabelInformation.Builder.of(expectedCapacity, labelTokenNodeLabelMapping);
47-
}
4833

4934
boolean isEmpty();
5035

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) "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.gds.core.loading;
21+
22+
import com.carrotsearch.hppc.IntObjectMap;
23+
import org.neo4j.gds.NodeLabel;
24+
25+
import java.util.List;
26+
27+
public final class LabelInformationBuilders {
28+
29+
private LabelInformationBuilders() {}
30+
31+
public static LabelInformation.Builder allNodes() {
32+
return new SingleLabelInformation.Builder(NodeLabel.ALL_NODES);
33+
}
34+
35+
public static LabelInformation.Builder singleLabel(NodeLabel singleLabel) {
36+
return new SingleLabelInformation.Builder(singleLabel);
37+
}
38+
39+
public static LabelInformation.Builder multiLabelWithCapacity(long expectedCapacity) {
40+
return MultiLabelInformation.Builder.of(expectedCapacity);
41+
}
42+
43+
public static LabelInformation.Builder multiLabelWithCapacityAndLabelInformation(
44+
long expectedCapacity,
45+
IntObjectMap<List<NodeLabel>> labelTokenNodeLabelMapping
46+
) {
47+
return MultiLabelInformation.Builder.of(expectedCapacity, labelTokenNodeLabelMapping);
48+
}
49+
}

core/src/main/java/org/neo4j/gds/core/loading/ScanningNodesImporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public static ScanningNodesImporter scanningNodesImporter(
7878
LabelInformation.Builder labelInformationBuilder;
7979
if (graphProjectConfig.nodeProjections().allProjections().size() == 1) {
8080
var singleLabel = graphProjectConfig.nodeProjections().projections().keySet().iterator().next();
81-
labelInformationBuilder = LabelInformation.single(singleLabel);
81+
labelInformationBuilder = LabelInformationBuilders.singleLabel(singleLabel);
8282
} else {
83-
labelInformationBuilder = LabelInformation.builder(expectedCapacity, labelTokenNodeLabelMapping);
83+
labelInformationBuilder = LabelInformationBuilders.multiLabelWithCapacityAndLabelInformation(expectedCapacity, labelTokenNodeLabelMapping);
8484
}
8585

8686
var propertyMappings = IndexPropertyMappings.prepareProperties(

core/src/main/java/org/neo4j/gds/core/loading/construction/NodesBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.neo4j.gds.core.concurrency.ParallelUtil;
3232
import org.neo4j.gds.core.loading.IdMapBuilder;
3333
import org.neo4j.gds.core.loading.LabelInformation;
34+
import org.neo4j.gds.core.loading.LabelInformationBuilders;
3435
import org.neo4j.gds.core.loading.NodeImporter;
3536
import org.neo4j.gds.core.loading.NodesBatchBuffer;
3637
import org.neo4j.gds.core.loading.NodesBatchBufferBuilder;
@@ -97,8 +98,8 @@ public final class NodesBuilder {
9798
this.elementIdentifierLabelTokenMapping = elementIdentifierLabelTokenMapping;
9899
this.idMapBuilder = idMapBuilder;
99100
this.labelInformationBuilder = !hasLabelInformation
100-
? LabelInformation.single(NodeLabel.ALL_NODES)
101-
: LabelInformation.builder(maxOriginalId + 1);
101+
? LabelInformationBuilders.allNodes()
102+
: LabelInformationBuilders.multiLabelWithCapacity(maxOriginalId + 1);
102103
this.labelTokenNodeLabelMapping = labelTokenNodeLabelMapping;
103104
this.nextLabelId = 0;
104105
this.lock = new ReentrantLock(true);

core/src/test/java/org/neo4j/gds/core/loading/ArrayIdMapTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void shouldStoreCorrectHighestNeoId() {
102102
int length = 1337;
103103
int highestNeoId = length - 1;
104104
var arrayIdMapBuilder = ArrayIdMapBuilder.of(length);
105-
var emptyLabelInformationBuilder = LabelInformation.single(NodeLabel.ALL_NODES);
105+
var emptyLabelInformationBuilder = LabelInformationBuilders.allNodes();
106106
var hugeIdMap = ArrayIdMapBuilderOps.build(
107107
arrayIdMapBuilder.array(),
108108
length,

core/src/test/java/org/neo4j/gds/core/loading/LabelInformationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void testLabelAssignment(Collection<Long> nodeIds, LongUnaryOperator nod
9898

9999
private LabelInformation buildLabelInformation(Collection<Long> nodeIds, LongUnaryOperator nodeIdMap, LabelProducer labelProducer) {
100100
var nodeCount = nodeIds.size();
101-
var builder = LabelInformation.builder(nodeCount, new IntObjectHashMap<>());
101+
var builder = LabelInformationBuilders.multiLabelWithCapacityAndLabelInformation(nodeCount, new IntObjectHashMap<>());
102102

103103
for (var nodeId : nodeIds) {
104104
for (NodeLabel nodeLabel : labelProducer.get(nodeId)) {

test-utils/src/main/java/org/neo4j/gds/core/idmap/IdMapBuilderTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import org.neo4j.gds.core.concurrency.ParallelUtil;
3232
import org.neo4j.gds.core.concurrency.Pools;
3333
import org.neo4j.gds.core.loading.IdMapBuilder;
34-
import org.neo4j.gds.core.loading.LabelInformation;
35-
import org.neo4j.gds.mem.HugeArrays;
34+
import org.neo4j.gds.core.loading.LabelInformationBuilders;
3635
import org.neo4j.gds.core.utils.partition.PartitionUtils;
36+
import org.neo4j.gds.mem.HugeArrays;
3737

3838
import java.util.Arrays;
3939
import java.util.HashMap;
@@ -243,7 +243,7 @@ void testBuildParallel(
243243

244244
ParallelUtil.run(tasks, Pools.DEFAULT);
245245

246-
var idMap = idMapBuilder.build(LabelInformation.single(NodeLabel.ALL_NODES), highestOriginalId, concurrency);
246+
var idMap = idMapBuilder.build(LabelInformationBuilders.allNodes(), highestOriginalId, concurrency);
247247

248248
assertThat(idMap.nodeCount()).as("node count").isEqualTo(nodeCount);
249249
assertThat(idMap.highestOriginalId()).as("highest original id").isEqualTo(highestOriginalId);
@@ -329,12 +329,12 @@ private IdMapAndHighestId buildFromWithLabels(
329329
idMapAllocator.insert(originalIds);
330330

331331
var labelInformationBuilder = labelFn.map(lFn -> {
332-
var multiLabelBuilder = LabelInformation.builder(originalIds.length);
332+
var multiLabelBuilder = LabelInformationBuilders.multiLabelWithCapacity(originalIds.length);
333333
for (long originalNodeId : originalIds) {
334334
lFn.apply(originalNodeId).forEach(label -> multiLabelBuilder.addNodeIdToLabel(label, originalNodeId));
335335
}
336336
return multiLabelBuilder;
337-
}).orElseGet(() -> LabelInformation.single(NodeLabel.ALL_NODES));
337+
}).orElseGet(LabelInformationBuilders::allNodes);
338338

339339
return ImmutableIdMapAndHighestId.builder()
340340
.idMap(builder.build(labelInformationBuilder, highestOriginalId, concurrency))

test-utils/src/main/java/org/neo4j/gds/core/loading/TestIdMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static final class Builder {
9898
public Builder() {
9999
this.forwardMap = new LongLongHashMap();
100100
this.reverseMap = new LongLongHashMap();
101-
this.labelInformationBuilder = LabelInformation.builder(42);
101+
this.labelInformationBuilder = LabelInformationBuilders.multiLabelWithCapacity(42);
102102
}
103103

104104
public Builder addAll(long... mappings) {

0 commit comments

Comments
 (0)