/** * The bucket number that contains this range number * Caller must hold read lock or write lock * @return 0 to max-1 or -1 for us */ private int pickBucket(int range) { // If B is small, a linear search from back to front // is most efficient since most of the keys are at the end... // If B is larger, there's a lot of sub-buckets // of equal size to be checked so a binary search is better if (B_VALUE <= 3) { for (int i = _buckets.size() - 1; i >= 0; i--) { KBucket<T> b = _buckets.get(i); if (range >= b.getRangeBegin() && range <= b.getRangeEnd()) return i; } return -1; } else { KBucket<T> dummy = new DummyBucket<T>(range); return Collections.binarySearch(_buckets, dummy, new BucketComparator<T>()); } }