presto-main/src/main/java/io/prestosql/operator/aggregation/histogram/ValueStore.java/ValueStore/addAndGetPosition
class ValueStore:    public int addAndGetPosition(Type type, Block block, int position, long valueHash)
    {
        if (values.getPositionCount() >= maxFill) {
            rehash();
        }

        int bucketId = getBucketId(valueHash, mask);
        int valuePointer;

        // look for an empty slot or a slot containing this key
        int probeCount = 1;
        int originalBucketId = bucketId;
        while (true) {
            checkState(probeCount < bucketCount, "could not find match for value nor empty slot in %s buckets", bucketCount);
            valuePointer = buckets.get(bucketId);

            if (valuePointer == EMPTY_BUCKET) {
                valuePointer = values.getPositionCount();
                valueHashes.set(valuePointer, (int) valueHash);
                type.appendTo(block, position, values);
                buckets.set(bucketId, valuePointer);

                return valuePointer;
            }
            else if (type.equalTo(block, position, values, valuePointer)) {
                // value at position
                return valuePointer;
            }
            else {
                int probe = nextProbe(probeCount);
                bucketId = nextBucketId(originalBucketId, mask, probe);
                probeCount++;
            }
        }
    }