Perfect hash function
A perfect hash function for a set S is a hash function that maps distinct elements in S to a set of integers, with no collisions. A perfect hash function has many of the same applications as other hash functions, but with the advantage that no collision resolution has to be implemented. In mathematical terms, it is a total injective function.
Properties and uses
A perfect hash function for a specific set S that can be evaluated in constant time, and with values in a small range, can be found by a randomized algorithm in a number of operations that is proportional to the size of S. Any perfect hash functions suitable for use with a hash table require at least a number of bits that is proportional to the size of S.
A perfect hash function with values in a limited range can be used for efficient lookup operations, by placing keys from S (or other associated values) in a table indexed by the output of the function. Using a perfect hash function is best in situations where there is a frequently queried large set, S, which is seldom updated. Efficient solutions to performing updates are known as dynamic perfect hashing, but these methods are relatively complicated to implement. A simple alternative to perfect hashing, which also allows dynamic updates, is cuckoo hashing.
Minimal perfect hash function
A minimal perfect hash function is a perfect hash function that maps keys to consecutive integers—usually or . A more formal way of expressing this is: Let and be elements of some finite set . F is a minimal perfect hash function iff implies (injectivity) and there exists an integer such that the range of is . It has been proved that a general purpose minimal perfect hash scheme requires at least 1.44 bits/key. However, the most effective currently known minimal perfect hashing schemes use around 2.6 bits/key.
A minimal perfect hash function F is order preserving if keys are given in some order and for any keys and , . Order-preserving minimal perfect hash functions require necessarily bits to be represented.
- Fredman, M. L.; Komlós, J. N.; Szemerédi, E. (1984). "Storing a Sparse Table with 0(1) Worst Case Access Time". Journal of the ACM 31 (3): 538. doi:10.1145/828.1884.
- Belazzougui, D.; Botelho, F. C.; Dietzfelbinger, M. (2009). "Hash, Displace, and Compress". Algorithms - ESA 2009. Lecture Notes in Computer Science 5757. p. 682. doi:10.1007/978-3-642-04128-0_61. ISBN 978-3-642-04127-3.
- Baeza-Yates, Ricardo; Poblete, Patricio V. (2010), "Searching", in Atallah, Mikhail J.; Blanton, Marina, Algorithms and Theory of Computation Handbook: General Concepts and Techniques (2nd ed.), CRC Press, ISBN 9781584888239. See in particular p. 2-10.
- Jenkins, Bob (14 April 2009), "order-preserving minimal perfect hashing", in Black, Paul E., Dictionary of Algorithms and Data Structures, U.S. National Institute of Standards and Technology, retrieved 2013-03-05
- Fox, E. A.; Chen, Q. F.; Daoud, A. M.; Heath, L. S. (1990). "Order preserving minimal perfect hash functions and information retrieval". Proceedings of the 13th annual international ACM SIGIR conference on Research and development in information retrieval - SIGIR '90. p. 279. doi:10.1145/96749.98233. ISBN 0897914082.
- Richard J. Cichelli. Minimal Perfect Hash Functions Made Simple, Communications of the ACM, Vol. 23, Number 1, January 1980.
- Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 11.5: Perfect hashing, pp. 245–249.
- Fabiano C. Botelho, Rasmus Pagh and Nivio Ziviani. "Perfect Hashing for Data Management Applications".
- Fabiano C. Botelho and Nivio Ziviani. "External perfect hashing for very large key sets". 16th ACM Conference on Information and Knowledge Management (CIKM07), Lisbon, Portugal, November 2007.
- Djamal Belazzougui, Paolo Boldi, Rasmus Pagh, and Sebastiano Vigna. "Monotone minimal perfect hashing: Searching a sorted table with O(1) accesses". In Proceedings of the 20th Annual ACM-SIAM Symposium On Discrete Mathematics (SODA), New York, 2009. ACM Press.
- Djamal Belazzougui, Paolo Boldi, Rasmus Pagh, and Sebastiano Vigna. "Theory and practise of monotone minimal perfect hashing". In Proceedings of the Tenth Workshop on Algorithm Engineering and Experiments (ALENEX). SIAM, 2009.
- Douglas C. Schmidt, GPERF: A Perfect Hash Function Generator, C++ Report, SIGS, Vol. 10, No. 10, November/December, 1998.
- Minimal Perfect Hashing by Bob Jenkins
- gperf is an Open Source C and C++ perfect hash generator
- cmph is Open Source implementing many perfect hashing methods
- Sux4J is Open Source implementing perfect hashing, including monotone minimal perfect hashing in Java
- MPHSharp is Open Source implementing many perfect hashing methods in C#