@Override
    public long put(long key, long value) {
        if (value > maxValue)
            throw new IllegalArgumentException("Value " + value + " exceeded max value: " + maxValue
                    + ". Increase bytesPerValue (" + bytesPerValue + ")");
        if (value == emptyValue)
            throw new IllegalArgumentException("Value cannot be the 'empty value' " + emptyValue);

        ReturnValue rv = root.put(key, value);
        if (rv.tree != null) {
            height++;
            root = rv.tree;
        }
        if (rv.oldValue == null) {
            // successfully inserted
            size++;
            if (size % 1000000 == 0)
                optimize();
        }
        return rv.oldValue == null ? emptyValue : toLong(rv.oldValue);
    }
@Test
    public void testPut() {
        GHLongLongBTree instance = new GHLongLongBTree(3, 4, -1);
        instance.put(2, 4);
        assertEquals(4, instance.get(2));

        instance.put(7, 14);
        assertEquals(4, instance.get(2));
        assertEquals(14, instance.get(7));

        instance.put(5, 10);
        instance.put(6, 12);
        instance.put(3, 6);
        instance.put(4, 8);
        instance.put(9, 18);
        instance.put(0, 0);
        instance.put(1, 2);
        instance.put(8, 16);

        check(instance, 0);

        instance.put(10, 20);
        instance.put(11, 22);

        assertEquals(12, instance.getSize());
        assertEquals(3, instance.height());

        assertEquals(12, instance.get(6));
        check(instance, 0);
    }