Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> What do you mean? Modulo is not a perfect hash function

It's a perfect hash function for the case where you work with ints and know the maximal min-max range beforehand; then you can modulo by the size of the range as long as it's not too large. In your example 33-21 --> mod 12

This comes up for me surprisingly often but obviously depends a lot on what you work on. It is often tempting to reach for a hashtable, but it's a lot less efficient in this case.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: