Skip to content

Commit bd2cf24

Browse files
Fix community count computation for long based ids
Co-Authored-By: Paul Horn <[email protected]>
1 parent 0c80df0 commit bd2cf24

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

algo-common/src/main/java/org/neo4j/graphalgo/result/AbstractCommunityResultBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private void buildCommunityCount() {
100100
long communityCount = 0L;
101101

102102
SparseNodeMapping componentSizes = buildComponentSizes();
103-
for (int communityId = 0; communityId < componentSizes.getCapacity(); communityId++) {
103+
for (long communityId = 0; communityId < componentSizes.getCapacity(); communityId++) {
104104
long communitySize = componentSizes.get(communityId);
105105
if (communitySize > 0) {
106106
communityCount++;

proc/common/src/test/java/org/neo4j/graphalgo/result/AbstractCommunityResultBuilderTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,24 @@ void oneCommunityFromHugeMap() {
176176
assertEquals(4.0, histogram.getValueAtPercentile(100D), 0.01);
177177
}
178178

179+
@Test
180+
void buildCommunityCountWithHugeCommunityCount() {
181+
AbstractCommunityResultBuilder<Void> builder = builder(
182+
procedureCallContext("communityCount"),
183+
(maybeCommunityCount, maybeHistogram) -> {
184+
assertTrue(maybeCommunityCount.isPresent());
185+
assertFalse(maybeHistogram.isPresent());
186+
long communityCount = maybeCommunityCount.orElse(-1);
187+
assertEquals(2L, communityCount, "should build 2 communities");
188+
});
189+
190+
LongUnaryOperator communityFunction = n -> n % 2 == 0 ? 0 : ((long) Integer.MAX_VALUE) + 2;
191+
builder
192+
.withCommunityFunction(communityFunction)
193+
.withNodeCount(2)
194+
.build();
195+
}
196+
179197
@Test
180198
void buildCommunityHistogramWithHugeCommunityCount() {
181199
AbstractCommunityResultBuilder<Void> builder = builder(

0 commit comments

Comments
 (0)