java - Why does the method hash(int h) of HashMap like this? -
this question has answer here:
- understanding strange java hash function 6 answers
static int hash(int h) { // function ensures hashcodes differ // constant multiples @ each bit position have bounded // number of collisions (approximately 8 @ default load factor). h ^= (h >>> 20) ^ (h >>> 12); return h ^ (h >>> 7) ^ (h >>> 4); }
could tell me why hash method designned this?what benefit?
if see open jdk source,
this method have comments...
/** * applies supplemental hash function given hashcode, * defends against poor quality hash functions. critical * because hashmap uses power-of-two length hash tables, * otherwise encounter collisions hashcodes not differ * in lower bits. note: null keys map hash 0, index 0. */
Comments
Post a Comment