public TypedSet(Type elementType, BlockBuilder blockBuilder, int expectedSize, String functionName) { checkArgument(expectedSize >= 0, "expectedSize must not be negative"); this.elementType = requireNonNull(elementType, "elementType must not be null"); this.elementBlock = requireNonNull(blockBuilder, "blockBuilder must not be null"); this.functionName = functionName; initialElementBlockOffset = elementBlock.getPositionCount(); initialElementBlockSizeInBytes = elementBlock.getSizeInBytes(); this.size = 0; this.hashCapacity = arraySize(expectedSize, FILL_RATIO); this.maxFill = calculateMaxFill(hashCapacity); this.hashMask = hashCapacity - 1; blockPositionByHash = new IntArrayList(hashCapacity); blockPositionByHash.size(hashCapacity); for (int i = 0; i < hashCapacity; i++) { blockPositionByHash.set(i, EMPTY_SLOT); } this.containsNullElement = false; }
private void rehash() { long newCapacityLong = hashCapacity * 2L; if (newCapacityLong > Integer.MAX_VALUE) { throw new PrestoException(GENERIC_INSUFFICIENT_RESOURCES, "Size of hash table cannot exceed 1 billion entries"); } int newCapacity = (int) newCapacityLong; hashCapacity = newCapacity; hashMask = newCapacity - 1; maxFill = calculateMaxFill(newCapacity); blockPositionByHash.size(newCapacity); for (int i = 0; i < newCapacity; i++) { blockPositionByHash.set(i, EMPTY_SLOT); } for (int blockPosition = initialElementBlockOffset; blockPosition < elementBlock.getPositionCount(); blockPosition++) { blockPositionByHash.set(getHashPositionOfElement(elementBlock, blockPosition), blockPosition); } }
public TypedSet(Type elementType, int expectedSize) { checkArgument(expectedSize > 0, "expectedSize must be > 0"); this.elementType = requireNonNull(elementType, "elementType must not be null"); this.elementBlock = elementType.createBlockBuilder(new BlockBuilderStatus(), expectedSize); int hashSize = arraySize(expectedSize, FILL_RATIO); this.maxFill = calculateMaxFill(hashSize); this.hashMask = hashSize - 1; blockPositionByHash.ensureCapacity(hashSize); for (int i = 0; i < hashSize; i++) { blockPositionByHash.set(i, EMPTY_SLOT); } this.containsNullElement = false; }
private void rehash(int size) { int newHashSize = arraySize(size + 1, FILL_RATIO); hashMask = newHashSize - 1; maxFill = calculateMaxFill(newHashSize); blockPositionByHash.ensureCapacity(newHashSize); for (int i = 0; i < newHashSize; i++) { blockPositionByHash.set(i, EMPTY_SLOT); } rehashBlock(elementBlock); }