uthash

1.9.7 BSD License    
3.0/5 9

  1,225 downloads

A hash for C structures

description

download

specs

changelog

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 */
}
read more   
Last updated on October 9th, 2012

#C structures hash #unique key field #hashed keys #uthash #C+ #structures #hash

uthash

0 User reviews so far.

SUBMIT