private static int getPackedCapacity(int capacity, int length) {
        if (capacity < MIN_CAPACITY || capacity > MAX_CAPACITY) {
          throw new IllegalArgumentException("capacity(" + capacity + ") must be in [" + MIN_CAPACITY + ".." + MAX_CAPACITY + "]");
        }
        if (length < 0 || length > MAX_CAPACITY) {
          throw new IllegalArgumentException("length(" + length + ") must be in [0, " + MAX_CAPACITY + "]");
        }
        final int capacityOverFirstBucket = capacity - MIN_CAPACITY;
        if ((capacityOverFirstBucket % OFFSET_BUCKET) != 0) {
          throw new IllegalArgumentException("capacity-MIN (=" + capacityOverFirstBucket + ") must be rounded up to " + OFFSET_BUCKET);
        }
        return capacityOverFirstBucket >> OFFSET_BUCKET_BITS;
      }
private static int getPackedCapacity(int capacity, int length)