3 ms·
Actually it's worse. You're more likely to have hash collisions and if you have enough of them you'll overflow into a red-black tree which has an even higher me
by needusername 10y ago
Actually it's worse. You're more likely to have hash collisions and if you have enough of them you'll overflow into a red-black tree which has an even higher memory footprint.
If you care about memory footprint use Eclipse Collections.
- the8472 10y ago> You're more likely to have hash collisions You are? I know they introduced the tree nodes as fallback if you have a bad hashing algorithm or malicious inputs, but that doesn't mean the hash collision rate got worse by default.
- needusername 10y agoYes you are because HashMap.hash(Object) was changed.
- the8472 10y agoThat is only matters if your keys had badly distributed hashes in the first place.
- needusername 10y agoUhm no. The hash code of my keys may be perfectly distributed but then HashMap#getNode comes along and masks most of my bits away. HashMap#hash(Object) is supposed to make the impact of the masking less bad.
- the8472 10y agoIf your hashes are perfectly distributed, as in each bit having a 50% probability of being 1, independent of all other bits, then the low order bits will be just as random as the high order bits, no "making the impact less bad" required.