public boolean add(Block block, int position)
    {
        requireNonNull(block, "block must not be null");
        checkArgument(position >= 0, "position must be >= 0");

        // containsNullElement flag is maintained so contains() method can have shortcut for null value
        if (block.isNull(position)) {
            if (containNullElements) {
                return false;
            }
            containNullElements = true;
        }

        int hashPosition = getHashPositionOfElement(block, position);
        if (blockPositionByHash.get(hashPosition) == EMPTY_SLOT) {
            addNewElement(hashPosition, block, position);
            return true;
        }

        return false;
    }
@Test
    public void testMemoryExceeded()
    {
        try {
            TypedSet typedSet = new TypedSet(BIGINT, 10, FUNCTION_NAME);
            for (int i = 0; i <= MAX_FUNCTION_MEMORY.toBytes() + 1; i++) {
                Block block = createLongsBlock(nCopies(1, (long) i));
                typedSet.add(block, 0);
            }
            fail("expected exception");
        }
        catch (PrestoException e) {
            assertEquals(e.getErrorCode(), EXCEEDED_FUNCTION_MEMORY_LIMIT.toErrorCode());
        }
    }