What is a sensible prime for hashcode calculation?

后端 未结 6 784
故里飘歌
故里飘歌 2020-11-29 16:27

Eclipse 3.5 has a very nice feature to generate Java hashCode() functions. It would generate for example (slightly shortened:)

class HashTest {
    int i;
           


        
6条回答
  •  Happy的楠姐
    2020-11-29 16:41

    You need to define your range for i and j. You could use a prime number for both.

    public int hashCode() {
       http://primes.utm.edu/curios/ ;)
       return 97654321 * i ^ 12356789 * j;
    }
    

提交回复
热议问题