uthash iconuthash 1.9.7

A hash for C structures
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 */
}

last updated on:
October 9th, 2012, 23:49 GMT
price:
FREE!
developed by:
Troy D. Hanson
license type:
BSD License 
category:
ROOT \ Utilities

FREE!

In a hurry? Add it to your Download Basket!

user rating 9

UNRATED
3.0/5
 

0/5

1 Screenshot
uthash
What's New in This Release:
  • A number of small enhancements were made to the supplemental utilities included with uthash, including new list operations (prepend, replace, and support for structures that use different naming conventions), new dynamic string features (KMP substring search, format checking), compatibility improvements, and improved documentation.
read full changelog

Add your review!

SUBMIT