-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OAK-11112 : replaced Maps.newHashMapWithExpectedSize() with new HashM… #1713
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe for the size calculation we should java common utility method, or even implement newHash* directly in CollectionUtils. @nfsantos ?
48e873a
to
ae71e3a
Compare
@@ -34,6 +36,8 @@ | |||
*/ | |||
public class CollectionUtils { | |||
|
|||
private static final int MAX_CAPACITY = 1 << 30; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the maximum capacity of hashmap
. Any value above this would be reverted to this value.
Also, we might hit negative values if we don't specify an upper limit.
See test below:
@Test public void ensureCapacityWithMaxValue() { int capacity = CollectionUtils.ensureCapacity(1908874369); }
it returns -2147483648
, which is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and maybe also add a comment with a short explanation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please separate the changes for CollectionUtils from the cases where we use them?
…ap<>(initialCapacity)
… collections with expected capacity
a65994f
to
0ec3fc8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't care that the maps will resize, it looks fine. Otherwise we might want to increase the initial capacity.
@mbaedke we are using |
Yes, of course. I was confused, sorry for the noise. |
…ap<>(initialCapacity)