Example 1. Adding an item to a hash.
#include "uthash.h" struct my_struct { int id; /* we'll use this field as the key */ char name[10]; UT_hash_handle hh; /* makes this structure hashable */ }; struct my_struct *users = NULL; void add_user(struct my_struct *s) { HASH_ADD_INT( users, id, s ); }
Example 2. Looking up an item in a hash.
struct my_struct *find_user(int user_id) { struct my_struct *s; HASH_FIND_INT( users, &user_id, s ); return s; }
Example 3. Deleting an item from a hash.
This hash can work with any kind of key, not just integer keys as shown here.
For a more thorough explanation and more examples, please read the
User Guide.
void delete_user(struct my_struct *user) { HASH_DEL( users, user); }