Skip to content

Commit

Permalink
Merge pull request #8888 from s1ck/targetlist-fallback-growth
Browse files Browse the repository at this point in the history
Fallback to ArrayUtil.oversize if we overvflow
  • Loading branch information
s1ck authored Apr 3, 2024
2 parents ce5abfd + ac57a43 commit 846f92b
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
*/
package org.neo4j.gds.core.loading;

import org.neo4j.gds.collections.ArrayUtil;
import org.neo4j.gds.collections.DrainingIterator;
import org.neo4j.gds.collections.hsl.HugeSparseByteArrayList;
import org.neo4j.gds.collections.hsa.HugeSparseCollections;
import org.neo4j.gds.collections.hsl.HugeSparseByteArrayList;
import org.neo4j.gds.collections.hsl.HugeSparseIntList;
import org.neo4j.gds.collections.hsl.HugeSparseLongArrayList;
import org.neo4j.gds.collections.hsl.HugeSparseLongList;
Expand Down Expand Up @@ -220,15 +221,31 @@ private long[] ensurePropertyCapacity(long index, int pos, int required, int pro
)
);
} else if (currentProperties.length <= pos + required) {
// int newLength = ArrayUtil.oversize(pos + required, Long.BYTES);
int newLength = BitUtil.nextHighestPowerOfTwo(pos + required);
var newLength = getNewLength(pos + required);
currentProperties = Arrays.copyOf(currentProperties, newLength);
this.properties[propertyIndex].set(index, currentProperties);
}

return currentProperties;
}

static int getNewLength(int minLength) {
int newLength = BitUtil.nextHighestPowerOfTwo(minLength);
if (newLength < 0) {
// If we overflow, we try to grow by ~1/8th and :fingers_crossed: it's enough.
newLength = ArrayUtil.oversize(minLength, Long.BYTES);
}
if (newLength < 0) {
throw new IllegalArgumentException(
formatWithLocale(
"Encountered numeric overflow in compressed buffer. Required a minimum length of %d.",
minLength
)
);
}
return newLength;
}

public long capacity() {
return targetLists.capacity();
}
Expand Down

0 comments on commit 846f92b

Please sign in to comment.