use of com.facebook.presto.array.LongBigArray in project presto by prestodb.
the class BigintGroupByHash method rehash.
private void rehash() {
expectedHashCollisions += estimateNumberOfHashCollisions(getGroupCount(), hashCapacity);
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;
int newMask = newCapacity - 1;
LongBigArray newValues = new LongBigArray();
newValues.ensureCapacity(newCapacity);
IntBigArray newGroupIds = new IntBigArray(-1);
newGroupIds.ensureCapacity(newCapacity);
for (int groupId = 0; groupId < nextGroupId; groupId++) {
if (groupId == nullGroupId) {
continue;
}
long value = valuesByGroupId.get(groupId);
// find an empty slot for the address
long hashPosition = getHashPosition(value, newMask);
while (newGroupIds.get(hashPosition) != -1) {
hashPosition = (hashPosition + 1) & newMask;
hashCollisions++;
}
// record the mapping
newValues.set(hashPosition, value);
newGroupIds.set(hashPosition, groupId);
}
mask = newMask;
hashCapacity = newCapacity;
maxFill = calculateMaxFill(hashCapacity);
values = newValues;
groupIds = newGroupIds;
this.valuesByGroupId.ensureCapacity(maxFill);
}
use of com.facebook.presto.array.LongBigArray in project presto by prestodb.
the class TypedHistogram method addAll.
public void addAll(TypedHistogram other) {
Block otherValues = other.getValues();
LongBigArray otherCounts = other.getCounts();
for (int i = 0; i < otherValues.getPositionCount(); i++) {
long count = otherCounts.get(i);
if (count > 0) {
add(i, otherValues, count);
}
}
}
use of com.facebook.presto.array.LongBigArray in project presto by prestodb.
the class BenchmarkGroupByHash method baselineBigArray.
@Benchmark
@OperationsPerInvocation(POSITIONS)
public long baselineBigArray(BaselinePagesData data) {
int hashSize = arraySize(GROUP_COUNT, 0.9f);
int mask = hashSize - 1;
LongBigArray table = new LongBigArray(-1);
table.ensureCapacity(hashSize);
long groupIds = 0;
for (Page page : data.getPages()) {
Block block = page.getBlock(0);
int positionCount = block.getPositionCount();
for (int position = 0; position < positionCount; position++) {
long value = BIGINT.getLong(block, position);
int tablePosition = (int) XxHash64.hash(value) & mask;
while (table.get(tablePosition) != -1 && table.get(tablePosition) != value) {
tablePosition++;
}
if (table.get(tablePosition) == -1) {
table.set(tablePosition, value);
groupIds++;
}
}
}
return groupIds;
}
Aggregations