Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

C hash implementation based on khash

tree: a49734e076

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .gitignore Initial commit June 17, 2012
Octocat-spinner-32 Makefile Initial commit June 17, 2012
Octocat-spinner-32 Readme.md
Octocat-spinner-32 hash.c
Octocat-spinner-32 hash.h
Octocat-spinner-32 package.conf
Readme.md

Hash

C pointer 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 type.
 */

typedef khash_t(ptr) hash_t;

/*
 * Allocate a new hash.
 */

#define hash_new() kh_init(ptr)

/*
 * Destroy the hash.
 */

#define hash_free(self) kh_destroy(ptr, self)

/*
 * Hash size.
 */

#define hash_size kh_size

/*
 * Iterate hash keys and ptrs, populating
 * `key` and `val`.
 */

#define hash_each(self, block);

/*
 * Iterate hash keys, populating `key`.
 */

#define hash_each_key(self, block);

/*
 * Iterate hash ptrs, populating `val`.
 */

#define hash_each_val(self, block);

// protos

void
hash_set(hash_t *self, char *key, void *val);

void *
hash_get(hash_t *self, char *key);

int
hash_has(hash_t *self, char *key);

void
hash_remove(hash_t *self, char *key);
Something went wrong with that request. Please try again.