/** * Same as {@link #chooseBetter(HashConfigWrapper, int, int, int, int, int)}. * * @see #chooseBetter(HashConfigWrapper, int, int, int, int, int) */ static long chooseBetter(HashConfigWrapper conf, long size, long desiredCapacity, long lesserCapacity, long greaterCapacity, long onFail) { assert 0L <= size; assert size < lesserCapacity && lesserCapacity < desiredCapacity; assert desiredCapacity < greaterCapacity; if (greaterCapacity - desiredCapacity <= desiredCapacity - lesserCapacity && greaterCapacity <= conf.maxCapacity(size)) { return greaterCapacity; } return lesserCapacity >= conf.minCapacity(size) ? lesserCapacity : onFail; }
/** * Same as {@link #chooseBetter(HashConfigWrapper, int, int, int, int, int)}. * * @see #chooseBetter(HashConfigWrapper, int, int, int, int, int) */ static long chooseBetter(HashConfigWrapper conf, long size, long desiredCapacity, long lesserCapacity, long greaterCapacity, long onFail) { assert 0L <= size; assert size < lesserCapacity && lesserCapacity < desiredCapacity; assert desiredCapacity < greaterCapacity; if (greaterCapacity - desiredCapacity <= desiredCapacity - lesserCapacity && greaterCapacity <= conf.maxCapacity(size)) { return greaterCapacity; } return lesserCapacity >= conf.minCapacity(size) ? lesserCapacity : onFail; }
assert desiredCapacity < greaterCapacity; if (greaterCapacity - desiredCapacity <= desiredCapacity - lesserCapacity && greaterCapacity <= conf.maxCapacity(size)) { return greaterCapacity;
assert desiredCapacity < greaterCapacity; if (greaterCapacity - desiredCapacity <= desiredCapacity - lesserCapacity && greaterCapacity <= conf.maxCapacity(size)) { return greaterCapacity;
static boolean configIsSuitableForImmutableHash(HashConfigWrapper conf, int size) { assert size >= 0; int desiredCapacity = conf.targetCapacity(size); if (desiredCapacity <= MIN_CAPACITY) return MIN_CAPACITY <= conf.maxCapacity(size); if (desiredCapacity < MAX_INT_CAPACITY) { if (isPowerOf2(desiredCapacity)) return true; int lesserCapacity = highestOneBit(desiredCapacity); int greaterCapacity = lesserCapacity << 1; int c = chooseBetter(conf, size, desiredCapacity, lesserCapacity, greaterCapacity, -1); return c > 0; } return false; }
static boolean configIsSuitableForImmutableHash(HashConfigWrapper conf, int size) { assert size >= 0; int desiredCapacity = conf.targetCapacity(size); if (desiredCapacity <= MIN_CAPACITY) return MIN_CAPACITY <= conf.maxCapacity(size); if (desiredCapacity < MAX_INT_CAPACITY) { if (isPowerOf2(desiredCapacity)) return true; int lesserCapacity = highestOneBit(desiredCapacity); int greaterCapacity = lesserCapacity << 1; int c = chooseBetter(conf, size, desiredCapacity, lesserCapacity, greaterCapacity, -1); return c > 0; } return false; }