Change to HashMap hash function in Java 8

后端 未结 3 1869
青春惊慌失措
青春惊慌失措 2021-02-04 11:41

In java 8 java.util.Hashmap I noticed a change from:

static int hash(int h) {
    h ^= (h >>> 20) ^ (h >>> 12);
    return h ^ (h >>>          


        
3条回答
  •  忘掉有多难
    2021-02-04 12:16

    When I ran hash implementation diffences I see time difference in nano seconds as below (not great but can have some effect when the size is huge ~1million+)-

    7473 ns – java 7

    3981 ns– java 8

    If we are talking about well formed keys and hashmap of big size (~million), this might have some impact and this is because of simplified logic.

提交回复
热议问题