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);

            try {
                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++;
                }
            }
            catch (NotSupportedException e) {
                throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
            }
        }
    }
@Test
    public void testUniqueness()
    {
        assertEquals(valueStore.addAndGetPosition(type, block, 0, TypeUtils.hashPosition(type, block, 0)), 0);
        assertEquals(valueStore.addAndGetPosition(type, block, 1, TypeUtils.hashPosition(type, block, 1)), 1);
        assertEquals(valueStore.addAndGetPosition(type, block, 2, TypeUtils.hashPosition(type, block, 2)), 2);
        assertEquals(valueStore.addAndGetPosition(type, block, 1, TypeUtils.hashPosition(type, block, 1)), 1);
        assertEquals(valueStore.addAndGetPosition(type, block, 3, TypeUtils.hashPosition(type, block, 1)), 3);
    }