uthash 1.2 review
Downloaduthash is a hash for C structures, allowing any C structure having a unique key field to be hashed. Structures can be deleted, add
|
|
uthash is a hash for C structures, allowing any C structure having a unique key field to be hashed.
Structures can be deleted, added or removed from the hash in constant time. The key field can have any data type.
Example 1. Adding an item to a hash.
#include "uthash.h"
struct my_struct {
int id; /* 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 ); /* hash, key field name, item */
}
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, s, id, &user_id );
return s;
}
Example 1. Deleting an item from a hash.
void delete_user(struct my_struct *user) {
HASH_DEL( users, user); /* hash, pointer to deletee */
}
What's New in This Release:
This release supports sorted iteration of the items in the hash using the new HASH_SORT macro.
Cygwin is now specifically supported by the built-in tests.
The documentation has been updated to include a table of contents and other enhancements.
uthash 1.2 keywords