Comment
Comment by innagadadavida
The optimal algorithm is the CHD algorithm - the function can use as little as 1.6bits per key. http://cmph.sourceforge.net/papers/esa09.pdf
There are implementations in Python: python chd perfect hashing
and in go: https://github.com/alecthomas/mph
In addition to the author's C code.