public void encodeSortedArray(final int[] values, final int offset, final int subsize, int nextbit, int mask) {
        if (subsize == 1) { // last-choice shortcut
            while (nextbit != 0) {
                encodeBit((values[offset] & nextbit) != 0);
                nextbit >>= 1;
            }
        }
        if (nextbit == 0) {
            return;
        }

        final int data = mask & values[offset];
        mask |= nextbit;

        // count 0-bit-fraction
        int i = offset;
        final int end = subsize + offset;
        for (; i < end; i++) {
            if ((values[i] & mask) != data) {
                break;
            }
        }
        final int size1 = i - offset;
        final int size2 = subsize - size1;

        encodeBounded(subsize, size1);
        if (size1 > 0) {
            encodeSortedArray(values, offset, size1, nextbit >> 1, mask);
        }
        if (size2 > 0) {
            encodeSortedArray(values, i, size2, nextbit >> 1, mask);
        }
    }
encode an integer-array making use of the fact that it is sorted. This is
done, starting with the most significant bit, by recursively encoding the
number of values with the current bit being 0. This yields an number of
bits per value that only depends on the typical distance between subsequent
values and also benefits

@param values  the array to encode
@param offset  position in this array where to start
@param subsize number of values to encode
@param nextbit bitmask with the most significant bit set to 1
@param mask    should be 0
main/src/main/java/cgeo/geocaching/brouter/codec/StatCoderContext.java