Linear hashing is a dynamic hash table algorithm invented by Witold Litwin (1980), and later popularized by Paul Larson. Linear hashing allows for the expansion of the hash table one slot at a time. The frequent single slot expansion can very effectively control the length of the collision chain. The cost of hash table expansion is spread out across each hash table insertion operation, as opposed to being incurred all at once. Linear hashing is therefore well suited for interactive applications.
First the initial hash table is set up with some arbitrary initial number of buckets. The following values need to be kept track of:
- : The initial number of buckets.
- : The current level which is an integer that indicates on a logarithmic scale approximately how much the table has grown. This is initially .
- : The step pointer which points to a bucket. It initially points to the first bucket in the table.
Bucket collisions can be handled in a variety of ways but it is typical to have space for two items in each bucket and to add more buckets whenever a bucket overflows. Addresses are calculated in the following way:
- Apply a hash function to the key and call the result .
- If is an address that comes before , the address is .
- If is or an address that comes after , the address is .
To add a bucket:
- Allocate a new bucket at the end of the table.
- If points to the th bucket in the table, reset and increment .
- Otherwise increment .
The effect of all of this is that the table is split into three sections; the section before , the section from to , and the section after . The first and last sections are stored using and the middle section is stored using . Each time reaches the table has doubled in size.
Adoption in language systems
Griswold and Townsend  discussed the adoption of linear hashing in the Icon language. They discussed the implementation alternatives of dynamic array algorithm used in linear hashing, and presented performance comparisons using a list of Icon benchmark applications.
Adoption in database systems
Linear hashing is used in the BDB Berkeley database system, which in turn is used by many software systems such as OpenLDAP, using a C implementation derived from the CACM article and first published on the Usenet in 1988 by Esmond Pitt.
- Litwin, Witold (1980), "Linear hashing: A new tool for file and table addressing" (PDF), Proc. 6th Conference on Very Large Databases: 212–223
- Larson, Per-Åke (April 1988), "Dynamic Hash Tables", Communications of the ACM 31 (4): 446–457, doi:10.1145/42404.42410
- Griswold, William G.; Townsend, Gregg M. (April 1993), "The Design and Implementation of Dynamic Hashing for Sets and Tables in Icon", Software - Practice and Experience 23 (4): 351–367
- Sorted Linear Hash Table, C++ implementation of a Linear Hashtable
- TommyDS, C implementation of a Linear Hashtable
- An in Memory Go Implementation with Explanation
- Paul E. Black, linear hashing at the NIST Dictionary of Algorithms and Data Structures.