private void append(long id, BytesRef key, int code) { assert size == id; final long startOffset = startOffsets.get(size); bytes = bigArrays.grow(bytes, startOffset + key.length); bytes.set(startOffset, key.bytes, key.offset, key.length); startOffsets = bigArrays.grow(startOffsets, size + 2); startOffsets.set(size + 1, startOffset + key.length); hashes = bigArrays.grow(hashes, id + 1); hashes.set(id, code); }
public final void mergeBuckets(long[] mergeMap, long newNumBuckets) { try (IntArray oldDocCounts = docCounts) { docCounts = bigArrays.newIntArray(newNumBuckets, true); docCounts.fill(0, newNumBuckets, 0); for (int i = 0; i < oldDocCounts.size(); i++) { int docCount = oldDocCounts.get(i); if (docCount != 0) { docCounts.increment(mergeMap[i], docCount); } } } }
/** * Get the id associated with <code>key</code> or -1 if the key is not contained in the hash. */ public long find(long key) { final long slot = slot(hash(key), mask); for (long index = slot; ; index = nextSlot(index, mask)) { final long id = id(index); if (id == -1 || keys.get(id) == key) { return id; } } }
public LongObjectPagedHashMap(long capacity, float maxLoadFactor, BigArrays bigArrays) { super(capacity, maxLoadFactor, bigArrays); keys = bigArrays.newLongArray(capacity(), false); values = bigArrays.newObjectArray(capacity()); }
/** Grow an array to a size that is larger than <code>minSize</code>, * preserving content, and potentially reusing part of the provided array. */ public <T> ObjectArray<T> grow(ObjectArray<T> array, long minSize) { if (minSize <= array.size()) { return array; } final long newSize = overSize(minSize, PageCacheRecycler.OBJECT_PAGE_SIZE, RamUsageEstimator.NUM_BYTES_OBJECT_REF); return resize(array, newSize); } }
/** Grow an array to a size that is larger than <code>minSize</code>, * preserving content, and potentially reusing part of the provided array. */ public ByteArray grow(ByteArray array, long minSize) { if (minSize <= array.size()) { return array; } final long newSize = overSize(minSize, PageCacheRecycler.BYTE_PAGE_SIZE, 1); return resize(array, newSize); }
/** Grow an array to a size that is larger than <code>minSize</code>, * preserving content, and potentially reusing part of the provided array. */ public IntArray grow(IntArray array, long minSize) { if (minSize <= array.size()) { return array; } final long newSize = overSize(minSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES); return resize(array, newSize); }
/** Grow an array to a size that is larger than <code>minSize</code>, * preserving content, and potentially reusing part of the provided array. */ public FloatArray grow(FloatArray array, long minSize) { if (minSize <= array.size()) { return array; } final long newSize = overSize(minSize, PageCacheRecycler.INT_PAGE_SIZE, Float.BYTES); return resize(array, newSize); }
/** Grow an array to a size that is larger than <code>minSize</code>, * preserving content, and potentially reusing part of the provided array. */ public LongArray grow(LongArray array, long minSize) { if (minSize <= array.size()) { return array; } final long newSize = overSize(minSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES); return resize(array, newSize); }
/** * Return the key at <code>0 <= index <= capacity()</code>. The result is undefined if the slot is unused. * <p>Beware that the content of the {@link BytesRef} may become invalid as soon as {@link #close()} is called</p> */ public BytesRef get(long id, BytesRef dest) { final long startOffset = startOffsets.get(id); final int length = (int) (startOffsets.get(id + 1) - startOffset); bytes.get(startOffset, length, dest); return dest; }
protected final byte[] newBytePage(int page) { if (recycler != null) { final Recycler.V<byte[]> v = recycler.bytePage(clearOnResize); return registerNewPage(v, page, PageCacheRecycler.BYTE_PAGE_SIZE); } else { return new byte[PageCacheRecycler.BYTE_PAGE_SIZE]; } }