explaingit

troydhanson/uthash

4,715CAudience · developerComplexity · 2/5Setup · easy

TLDR

A single-header C library that adds hash tables and other data structures to C programs through macros, no compilation step, no linking, just include one file and start using fast key-value lookups.

Mindmap

mindmap
  root((uthash))
    What it is
      Header-only library
      C macros
      Hash tables
    Features
      No linking needed
      Key-value lookup
      Fast constant-time access
    Use cases
      Systems software
      Embedded devices
      C applications
    Audience
      C developers
      Systems programmers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add fast key-value lookup to a C program by including one header file and using HASH_ADD and HASH_FIND macros.

USE CASE 2

Store and retrieve structs by a string key in a systems program without pulling in a larger external dependency.

USE CASE 3

Use uthash in an embedded C project where linking against external libraries is not practical.

Tech stack

C

Getting it running

Difficulty · easy Time to first run · 5min

Include one header file, no changes to your build system required.

In plain English

uthash is a C library that provides hash tables through macros, which are a form of code shorthand built into the C language. A hash table is a data structure that lets a program store and look up items by a key, such as finding a user record by username in roughly constant time no matter how many records exist. This kind of lookup speed is useful in systems software, embedded devices, and any program written in C that needs to manage large collections of named data. The library delivers this through macros rather than functions. That means you include a single header file in your project and then use the provided macros directly in your code. There is no separate compilation step and no additional library to link against. The header file is the entire library. The repository description mentions hash tables and more, suggesting additional data structures are included, but the README itself is minimal. It points to external documentation at the project website for details on usage and supported structures. The project has been around long enough to accumulate a substantial number of stars, and it includes continuous integration checks on multiple platforms, which suggests it is actively maintained and tested. For anyone working in C who needs a hash table without pulling in a larger dependency, this appears to be a focused and self-contained option. Because the README in the repository is essentially a pointer to external documentation, full usage details and the complete list of supported data structures are not available here.

Copy-paste prompts

Prompt 1
Show me a complete C example using uthash that stores user structs by username, looks one up by name, and then removes it from the hash table.
Prompt 2
How do I iterate over every entry in a uthash hash table and free all the memory correctly when I'm done?
Prompt 3
Write a C program with uthash where the key is an integer ID and the value is a struct containing a name and a timestamp.
Prompt 4
What macros do I need to use uthash with a composite key made of two integers instead of a single string?
Open on GitHub → Explain another repo

← troydhanson on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.