use of com.facebook.presto.array.IntBigArray 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.IntBigArray in project presto by prestodb.
the class InMemoryHashAggregationBuilder method hashSortedGroupIds.
private IntIterator hashSortedGroupIds() {
IntBigArray groupIds = new IntBigArray();
groupIds.ensureCapacity(groupByHash.getGroupCount());
for (int i = 0; i < groupByHash.getGroupCount(); i++) {
groupIds.set(i, i);
}
groupIds.sort(0, groupByHash.getGroupCount(), (leftGroupId, rightGroupId) -> Long.compare(groupByHash.getRawHash(leftGroupId), groupByHash.getRawHash(rightGroupId)));
return new AbstractIntIterator() {
private final int totalPositions = groupByHash.getGroupCount();
private int position = 0;
@Override
public boolean hasNext() {
return position < totalPositions;
}
@Override
public int nextInt() {
return groupIds.get(position++);
}
};
}
use of com.facebook.presto.array.IntBigArray in project presto by prestodb.
the class TypedHistogram method rehash.
private void rehash(int size) {
int newSize = arraySize(size + 1, FILL_RATIO);
int newMask = newSize - 1;
IntBigArray newHashPositions = new IntBigArray(-1);
newHashPositions.ensureCapacity(newSize);
for (int i = 0; i < values.getPositionCount(); i++) {
// find an empty slot for the address
int hashPosition = getHashPosition(TypeUtils.hashPosition(type, values, i), newMask);
while (newHashPositions.get(hashPosition) != -1) {
hashPosition = (hashPosition + 1) & newMask;
}
// record the mapping
newHashPositions.set(hashPosition, i);
}
mask = newMask;
maxFill = calculateMaxFill(newSize);
hashPositions = newHashPositions;
this.counts.ensureCapacity(maxFill);
}
Aggregations