public GapEncodedVariableLengthIntegerReader[] split(int numSplits) {
        if (numSplits<=0 || !((numSplits&(numSplits-1))==0)) {
            throw new IllegalStateException("Split should only be called with powers of 2, it was called with " + numSplits);
        }
        final int toMask = numSplits - 1;
        final int toOrdinalShift = 31 - Integer.numberOfLeadingZeros(numSplits);
        GapEncodedVariableLengthIntegerReader[] to = new GapEncodedVariableLengthIntegerReader[numSplits];

        List<Integer> ordinals = new ArrayList<>();
        reset();
        while(nextElement() != Integer.MAX_VALUE) {
            ordinals.add(nextElement());
            advance();
        }

        ByteDataArray[] splitOrdinals = new ByteDataArray[numSplits];
        int previousSplitOrdinal[] = new int[numSplits];
        for (int ordinal : ordinals) {
            int toIndex = ordinal & toMask;
            int toOrdinal = ordinal >> toOrdinalShift;
            if (splitOrdinals[toIndex] == null) {
                splitOrdinals[toIndex] = new ByteDataArray(WastefulRecycler.DEFAULT_INSTANCE);
            }
            VarInt.writeVInt(splitOrdinals[toIndex], toOrdinal - previousSplitOrdinal[toIndex]);
            previousSplitOrdinal[toIndex] = toOrdinal;
        }
        for(int i=0;i<numSplits;i++) {
            if (splitOrdinals[i] == null) {
                to[i] = EMPTY_READER;
            } else {
                to[i] = new GapEncodedVariableLengthIntegerReader(splitOrdinals[i].getUnderlyingArray(), (int) splitOrdinals[i].length());
            }
        }

        return to;
    }
@Test
    public void testSplit() {
        GapEncodedVariableLengthIntegerReader reader = reader(1, 10, 100, 105, 107, 200);

        GapEncodedVariableLengthIntegerReader[] splitBy2 = reader.split(2);
        assertEquals(2, splitBy2.length);
        assertValues(splitBy2[0], 5, 50, 100); // (split[i]*numSplits + i) is the original ordinal
        assertValues(splitBy2[1], 0, 52, 53);

        GapEncodedVariableLengthIntegerReader[] splitBy256 = reader.split(256);
        assertEquals(256, splitBy256.length);
        assertValues(splitBy256[1], 0);
        assertValues(splitBy256[200], 0);
        assertEquals(EMPTY_READER, splitBy256[0]);
        assertEquals(EMPTY_READER, splitBy256[255]);

        GapEncodedVariableLengthIntegerReader[] splitBy2Empty = EMPTY_READER.split(2);
        assertEquals(2, splitBy2Empty.length);
        assertEquals(EMPTY_READER, splitBy2Empty[0]);
        assertEquals(EMPTY_READER, splitBy2Empty[1]);

        assertIllegalStateException(() ->reader.split(0));
        assertIllegalStateException(() -> reader.split(3));
    }