|
19 | 19 | */
|
20 | 20 | package org.neo4j.gds.core.loading;
|
21 | 21 |
|
| 22 | +import org.neo4j.gds.collections.ArrayUtil; |
22 | 23 | import org.neo4j.gds.collections.DrainingIterator;
|
23 |
| -import org.neo4j.gds.collections.hsl.HugeSparseByteArrayList; |
24 | 24 | import org.neo4j.gds.collections.hsa.HugeSparseCollections;
|
| 25 | +import org.neo4j.gds.collections.hsl.HugeSparseByteArrayList; |
25 | 26 | import org.neo4j.gds.collections.hsl.HugeSparseIntList;
|
26 | 27 | import org.neo4j.gds.collections.hsl.HugeSparseLongArrayList;
|
27 | 28 | import org.neo4j.gds.collections.hsl.HugeSparseLongList;
|
@@ -220,15 +221,31 @@ private long[] ensurePropertyCapacity(long index, int pos, int required, int pro
|
220 | 221 | )
|
221 | 222 | );
|
222 | 223 | } else if (currentProperties.length <= pos + required) {
|
223 |
| -// int newLength = ArrayUtil.oversize(pos + required, Long.BYTES); |
224 |
| - int newLength = BitUtil.nextHighestPowerOfTwo(pos + required); |
| 224 | + var newLength = getNewLength(pos + required); |
225 | 225 | currentProperties = Arrays.copyOf(currentProperties, newLength);
|
226 | 226 | this.properties[propertyIndex].set(index, currentProperties);
|
227 | 227 | }
|
228 | 228 |
|
229 | 229 | return currentProperties;
|
230 | 230 | }
|
231 | 231 |
|
| 232 | + static int getNewLength(int minLength) { |
| 233 | + int newLength = BitUtil.nextHighestPowerOfTwo(minLength); |
| 234 | + if (newLength < 0) { |
| 235 | + // If we overflow, we try to grow by ~1/8th and :fingers_crossed: it's enough. |
| 236 | + newLength = ArrayUtil.oversize(minLength, Long.BYTES); |
| 237 | + } |
| 238 | + if (newLength < 0) { |
| 239 | + throw new IllegalArgumentException( |
| 240 | + formatWithLocale( |
| 241 | + "Encountered numeric overflow in compressed buffer. Required a minimum length of %d.", |
| 242 | + minLength |
| 243 | + ) |
| 244 | + ); |
| 245 | + } |
| 246 | + return newLength; |
| 247 | + } |
| 248 | + |
232 | 249 | public long capacity() {
|
233 | 250 | return targetLists.capacity();
|
234 | 251 | }
|
|
0 commit comments