A new hash table for Lwan

· coding · Source ↗

TLDR

  • Lwan’s web server replaces its kmod-derived hash table with a SwissTable-inspired design using memchr() for portable SIMD-like probing.

Key Takeaways

  • New design splits the hash into tophash (low 8 bits, used with memchr()) and startpos (next bits, power-of-two masked) for two-phase probing.
  • Uses a single flat group instead of SwissTable’s multi-group layout, trading some theoretical worst-case for simplicity and portability.
  • Deletion tombstones with \0 and triggers a full hash_resize() when load drops below 50%; in-place or lazy rehash is future work.
  • Hash function is FNV-1a or Intel CRC32 (hardware-dependent); author reports key equality succeeds on first probe in practice.
  • SELF_TEST() macros run on every debug boot, catching regressions during experimentation without a separate test harness.

Hacker News Comment Review

  • No substantive HN discussion yet; the one comment reflects on hash tables as a conceptual milestone in CS education rather than on the implementation itself.

Original | Discuss on HN