Need help with hash?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

clibs
148 Stars 51 Forks 23 Commits 3 Opened issues

Description

C hash implementation based on khash

Services available

!
?

Need anything else?

Contributors list

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.