@TrisH0x2A: a hash map in 25 lines of C FNV-1a handles the hashing, start with a fixed value and XOR each byte multiply by a prime …
Summary
A concise implementation of a hash map in 25 lines of C using FNV-1a hashing and bitwise AND for efficient modulo operation, with void pointers for type-generic storage.
View Cached Full Text
Cached at: 06/25/26, 05:19 AM
a hash map in 25 lines of C
FNV-1a handles the hashing, start with a fixed value and XOR each byte multiply by a prime and repeat
the interesting part is the last line
instead of using hash % cap it uses hash & (cap - 1)
same result when the capacity is a power of two
and a bitwise AND is generally cheaper than a modulo operation
another neat detail is the use of void pointers for values
the hash map does not care what type you store
integers strings structs anything works
the caller handles the casting when storing and retrieving data
Similar Articles
A C++ implementation of a fast hash map and hash set using hopscotch hashing
The hopscotch-map library is a C++ implementation of fast hash map and hash set using hopscotch hashing, offering better performance than std::unordered_map in most cases.
Chopped, Stored, Secured – The Story of the Hash Function
A detailed historical and mathematical explanation of hash functions, from their invention by Arnold Dumey in 1956 as a memory indexing technique to modern cryptographic hashes, including Python implementations.
Value Numbering
The article explains value numbering, a compiler optimization technique that identifies identical computations to avoid redundancy, building on Static Single Assignment (SSA) form and using hash-consing for efficient comparison.
Every byte matters
This article explains the importance of understanding CPU cache lines and data structure layout for performance optimization in programming, using examples in Java and C. It discusses the overhead of unnecessary bytes and the trade-offs between Array of Structs and Struct of Arrays.
Qwen3.6-27B KLDs - INTs and NVFPs
Reddit post compares quantized Qwen3.6-27B variants (INT4, NVFP4, BF16-INT4) showing trade-offs between memory size and accuracy for different use-cases.