Hash tables, functions, collision resolution, and applications
Section 4 of 4
Discover how hash tables power the systems and applications we use every day
Hash tables are one of the most practical and widely-used data structures in computer science. Their O(1) average-case performance makes them ideal for applications requiring fast lookups.
Hash tables are fundamental to database indexing and query optimization
Database engines use hash tables for quick index page location
// Hash-based index lookup Map<PageId, IndexPage> pageCache = new HashMap<>(); IndexPage page = pageCache.get(hashKey(searchValue));
Hash joins are one of the most efficient join algorithms
// Hash join implementation HashMap<Key, List<Row>> buildTable = new HashMap<>(); // Build phase: hash smaller table // Probe phase: lookup matching rows
Cache query results using SQL statement hash as key
String sqlHash = hashFunction(sqlStatement); QueryResult cached = queryCache.get(sqlHash); if (cached != null) return cached;
Redis (hash table based): 100,000+ operations/second
PostgreSQL hash index: 50,000+ lookups/second
GCC: 1M+ symbol lookups during compilation
Most implementations resize at 75% capacity to maintain O(1) performance
Production systems often use MurmurHash or CityHash for speed and distribution
Cache-friendly implementations group related data and minimize pointer chasing
dictMap, ObjectHashMapunordered_mapmap