@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 …

X AI KOLs Timeline Tools

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.

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
Original Article
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

Value Numbering

Hacker News Top

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

Lobsters Hottest

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 r/LocalLLaMA

Reddit post compares quantized Qwen3.6-27B variants (INT4, NVFP4, BF16-INT4) showing trade-offs between memory size and accuracy for different use-cases.