PROJECT DOSSIER // github.com

jamesroutley/write-a-hash-table

从零用 C 语言实现哈希表。该项目是讲解如何用 C 语言实现一个开放寻址和双重哈希的哈希表,代码约为 200 行,预计学习时间为 1 到 2 小时。

其他 VERIFIED C ★ 4400
README.md 更新于:2026-11-13 08:00:04

Write a hash table in C

Hash tables are one of the most useful data structures. Their quick and scalable
insert, search and delete make them relevant to a large number of computer
science problems.

In this tutorial, we implement an open-addressed, double-hashed hash table in
C. By working through this tutorial, you will gain:

  • Understanding of how a fundamental data structure works under the hood
  • Deeper knowledge of when to use hash tables, when not to use them, and how
    they can fail
  • Exposure to new C code

C is a great language to write a hash table in because:

  • The language doesn't come with one included
  • It is a low-level language, so you get deeper exposure to how things work at a
    machine level

This tutorial assumes some familiarity with programming and C syntax. The code
itself is relatively straightforward, and most issues should be solvable with a
web search. If you run into further problems, please open a GitHub
Issue.

The full implementation is around 200 lines of code, and should take around an
hour or two to work through.

Contents

  1. Introduction
  2. Hash table structure
  3. Hash functions
  4. Handling collisions
  5. Hash table methods
  6. Resizing tables
  7. Appendix: alternative collision handling

Credits

This tutorial was written by James Routley,
who blogs at routley.io.