Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • This is always going to be faster than DIV/IDIV, however I don't think it answers my question-- index will be in the range [0..255]. I need something in the range [0..n-1], where n is the number of buckets. Commented Sep 10, 2016 at 21:37
  • @JamesKo But if you're implementing a dictionary, you also control the number of buckets (to a certain degree). So, instead of prime numbers, you could choose powers of two. (Whether doing so would be actually a good idea, I can't tell you.) Commented Sep 11, 2016 at 19:28
  • @svick For powers of 2 we could do a simple mask operation. As mentioned in the question, I am looking for a cheap way to do this with prime numbers so even poorly-distributed hashes are accomodated. Commented Sep 20, 2016 at 3:16