RFR: [6904367]: (coll) IdentityHashMap is resized before exceeding the expected maximum size (original) (raw)
Martin Buchholz martinrb at google.com
Tue Jul 8 07:27:09 UTC 2014
- Previous message: RFR: [6904367]: (coll) IdentityHashMap is resized before exceeding the expected maximum size
- Next message: RFR: [6904367]: (coll) IdentityHashMap is resized before exceeding the expected maximum size
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 > MAXIMUMCAPACITY / 3) + return MAXIMUMCAPACITY;
No, even though it looks like a bug. (MAXIMUMCAPACITY / 3) * (3 / 2) == MAXIMUMCAPACITY / 2. if expected size > MAXIMUMCAPACITY / 3, then the minimum capacity must be > MAXIMUMCAPACITY / 2 then the minimum capacity == MAXIMUMCAPACITY.
- Previous message: RFR: [6904367]: (coll) IdentityHashMap is resized before exceeding the expected maximum size
- Next message: RFR: [6904367]: (coll) IdentityHashMap is resized before exceeding the expected maximum size
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]