C hash implementation based on khash.
Install with clib:
$ clib install clibs/hash
hash_t *hash = hash_new();
hash_set(hash, "name", "tobi");
hash_set(hash, "species", "ferret");
hash_set(hash, "age", "2");
hash_each(hash, {
printf("%s: %s\n", key, (char *) val);
});
hash_free(hash);yields:
species: ferret
age: 2
name: tobi
The hash type.
Allocate and initialize a new hash.
Free the hash, you must free values appropriately.
Return the number of values in the hash table.
Remove all values from the hash.
Set key to val.
Get value for key or NULL.
Check if the hash contains key.
Remove key from the hash.
A macro for iterating key/value pairs.
hash_each(users, {
printf("%s: %s\n", key, (char *) val);
})A macro for iterating keys only.
hash_each_key(users, {
printf("%s\n", key);
})A macro for iterating values only.
hash_each_val(users, {
printf("%s\n", (char *) val);
})