public void set(long index, E value) {
        assert index >= 0;
        assert value != null;
        int prefix = (int) (index >>> Integer.SIZE);

        if (prefix == lastPrefix) {
            lastStorage.set((int) index, value);
        } else {
            lastPrefix = prefix;
            SparseIntArray<E> storage = storages.get(prefix);
            if (storage == null) {
                SparseIntArray<E> createdStorage = new SparseIntArray<>();
                createdStorage.set((int) index, value);
                lastStorage = createdStorage;
                storages.set(prefix, createdStorage);
            } else {
                storage.set((int) index, value);
                lastStorage = storage;
            }
        }
    }
@Test
    public void testSet() {
        // try empty array
        verify();

        // at the beginning
        for (long i = 0; i < 1000; ++i) {
            set(i);
            verify();
            set(i, 100 + i);
            verify();
        }

        // offset
        for (long i = 1000000; i < 1000000 + 1000; ++i) {
            set(i);
            verify();
            set(i, 100 + i);
            verify();
        }

        // clear everything we have added
        for (long i = 0; i < 1000; ++i) {
            clear(i);
            verify();
        }
        for (long i = 1000000; i < 1000000 + 1000; ++i) {
            clear(i);
            verify();
        }

        // test empty again
        verify();

        // try gaps
        for (long i = 0; i < 1000; ++i) {
            set(i * i);
            verify();
            set(i * i, 100 + i * i);
            verify();
        }

        // try larger gaps
        for (long i = (long) Math.sqrt(Long.MAX_VALUE) - 1000; i < (long) Math.sqrt(Long.MAX_VALUE); ++i) {
            set(i * i);
            verify();
            set(i * i, 100 + i * i);
            verify();
        }

        // try some edge cases
        for (long i = 0; i <= 2; ++i) {
            set(i);
            verify();
        }
        for (long i = Short.MAX_VALUE - 2; i <= Short.MAX_VALUE + 2; ++i) {
            set(i);
            verify();
        }
        for (long i = Integer.MAX_VALUE - 2; i <= (long) Integer.MAX_VALUE + 2; ++i) {
            set(i);
            verify();
        }
        for (long i = Long.MAX_VALUE; i >= Long.MAX_VALUE - 2; --i) {
            set(i);
            verify();
        }
    }