RFR: [6904367]: (coll) IdentityHashMap is resized before exceeding the expected maximum size
Martin Buchholz
martinrb at google.com
Tue Jul 8 07:27:09 UTC 2014
Ah, yes, now I see.
My latest attempt at this method looks like:
private static int capacity(int expectedMaxSize) {
// assert expectedMaxSize >= 0;
return
(expectedMaxSize > MAXIMUM_CAPACITY / 3) ? MAXIMUM_CAPACITY :
(expectedMaxSize <= 2 * MINIMUM_CAPACITY / 3) ?
MINIMUM_CAPACITY :
Integer.highestOneBit(expectedMaxSize + (expectedMaxSize << 1));
}
On Mon, Jul 7, 2014 at 6:12 PM, Ivan Gerasimov <ivan.gerasimov at oracle.com>
wrote:
>
> On 08.07.2014 4:47, Martin Buchholz wrote:
>
>> I think this code has an off-by-factor-of-2 bug.
>>
>> + if (expectedMaxSize > MAXIMUM_CAPACITY / 3)
>> + return MAXIMUM_CAPACITY;
>>
>>
> No, even though it looks like a bug.
>
> (MAXIMUM_CAPACITY / 3) * (3 / 2) == MAXIMUM_CAPACITY / 2.
>
> if expected size > MAXIMUM_CAPACITY / 3,
> then the minimum capacity must be > MAXIMUM_CAPACITY / 2
> then the minimum capacity == MAXIMUM_CAPACITY.
>
>
>
More information about the core-libs-dev
mailing list