Replies: 3 comments 2 replies
-
Possibly @kevinb9n can comment in more detail. I found an internal commit (for Googlers: cl/40155455) where Kevin wrote "use a hash calculation that was found by [another person] to perform far better than |
Beta Was this translation helpful? Give feedback.
-
Although I don't remember the details.... it is kind of exactly like me to shift things over a golden-ratio fraction of the way. Though that might argue for a multiplier of 898,459, so I guess I also thought it should be a nice simple number to the human eye. But yeah, the idea of making it bigger was just to eat up all those initial zeros more quickly and get the bits to come back around and interfere with each other. |
Beta Was this translation helpful? Give feedback.
-
Thanks, @kevinb9n & @eamonnmcmanus for the super quick answers and internal insight on this. |
Beta Was this translation helpful? Give feedback.
-
There is a Stack Overflow question asking why AutoValue uses 1000003 as its prime, rather than some other number. The code base, including the initial commit, doesn't appear to give any hints. Java's built-in
Object.hash
,Arrays.hashCode
, andList.hashCode
by contrast all use the much smaller number 31 for their hash function.Is there any particular reason — mathematical or otherwise — that this particular value was chosen for AutoValue? 1000003 is the first prime after one million, so one might guess is that's why it was chosen. Is there some value to using a larger prime like this, over a smaller one like 31?
Beta Was this translation helpful? Give feedback.
All reactions