@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.
SequenceHash: multihashing for the rest of us
Trail of Bits introduces SequenceHash and SequenceMAC, open-source multihashing constructions that work with any standard cryptographic hash function (SHA2, BLAKE, RIPEMD) rather than being tied to Keccak like NIST's TupleHash. The C2SP-approved spec ships with Rust, Go, and Python implementations plus test vectors, aimed at preventing ambiguous-input attacks in protocols like the Fiat-Shamir transform.
@msimoni: Hash table code from my new language for Wasm GC. It's completely static, and you must write all types manually (there …
A developer shares code for a hash table in a new static language designed for WebAssembly GC, highlighting manual type requirements and decent performance with a toy compiler.
Heavenly delights of hashing numbers under EQUALP
A technical deep-dive into optimizing hashing of numbers under the EQUALP predicate in ECL (Embedded Common Lisp), covering new hash table and hash function implementations that significantly speed up hash tables and generic function dispatch.
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.