hash

by clibs

clibs / hash

C hash implementation based on khash

133 Stars 47 Forks Last release: over 6 years ago (0.0.1) 23 Commits 1 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

hash

C hash implementation based on khash.

Installation

Install with clib:

$ clib install clibs/hash

Example

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

API

hash_t

The hash type.

hasht *hashnew()

Allocate and initialize a new hash.

hashfree(hasht *self)

Free the hash, you must free values appropriately.

unsigned int hashsize(hasht *self)

Return the number of values in the hash table.

void hashclear(hasht *self)

Remove all values from the hash.

void hashset(hasht *self, char *key, void *val);

Set

key
to
val
.

void *hashget(hasht *self, char *key);

Get value for

key
or NULL.

int hashhas(hasht *self, char *key);

Check if the hash contains

key
.

void hashdel(hasht *self, char *key);

Remove

key
from the hash.

hasheach(hasht *self, block)

A macro for iterating key/value pairs.

hash_each(users, {
  printf("%s: %s\n", key, (char *) val);
})

hasheachkey(hash_t *self, block)

A macro for iterating keys only.

hash_each_key(users, {
  printf("%s\n", key);
})

hasheachval(hash_t *self, block)

A macro for iterating values only.

hash_each_val(users, {
  printf("%s\n", (char *) val);
})

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.