Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/hashPublic

C hash implementation based on khash

NotificationsYou must be signed in to change notification settings

clibs/hash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C hash implementation based on khash.

Installation

Install withclib:

$ 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: ferretage: 2name: tobi

API

hash_t

The hash type.

hash_t *hash_new()

Allocate and initialize a new hash.

hash_free(hash_t *self)

Free the hash, you must free values appropriately.

unsigned int hash_size(hash_t *self)

Return the number of values in the hash table.

void hash_clear(hash_t *self)

Remove all values from the hash.

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

Setkey toval.

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

Get value forkey orNULL.

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

Check if the hash containskey.

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

Removekey from the hash.

hash_each(hash_t *self, block)

A macro for iterating key/value pairs.

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

hash_each_key(hash_t *self, block)

A macro for iterating keys only.

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

hash_each_val(hash_t *self, block)

A macro for iterating values only.

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

[8]ページ先頭

©2009-2025 Movatter.jp