Skip to content

Commit

Permalink
add api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 17, 2012
1 parent 2f1105b commit fbd1069
Showing 1 changed file with 46 additions and 44 deletions.
90 changes: 46 additions & 44 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,67 +28,69 @@ name: tobi
## API
```c
/*
* Hash type.
*/
### hash_t
The hash type.
### hash_t *hash_new()
Allocate and initialize a new hash.
typedef khash_t(ptr) hash_t;
### hash_free(hash_t *self)
/*
* Allocate a new hash.
*/
Free the hash, you must free values appropriately.
#define hash_new() kh_init(ptr)
### unsigned int hash_size(hash_t *self)
/*
* Destroy the hash.
*/
Return the number of values in the hash table.
#define hash_free(self) kh_destroy(ptr, self)
### void hash_clear(hash_t *self)
/*
* Hash size.
*/
Remove all values from the hash.
#define hash_size kh_size
### void hash_set(hash_t *self, char *key, void *val);
/*
* Remove all pairs in the hash.
*/
Set `key` to `val`.
#define hash_clear(self) kh_clear(ptr, self)
### void *hash_get(hash_t *self, char *key);
/*
* Iterate hash keys and ptrs, populating
* `key` and `val`.
*/
Get value for `key` or __NULL__.
#define hash_each(self, block);
### int hash_has(hash_t *self, char *key);
/*
* Iterate hash keys, populating `key`.
*/
Check if the hash contains `key`.
#define hash_each_key(self, block);
### void hash_del(hash_t *self, char *key);
/*
* Iterate hash ptrs, populating `val`.
*/
Remove `key` from the hash.
#define hash_each_val(self, block);
### hash_each(hash_t *self, block)
// protos
A macro for iterating key/value pairs.
```c
hash_each(users, {
printf("%s: %s\n", key, (char *) val);
})
```

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

void *
hash_get(hash_t *self, char *key);
A macro for iterating keys only.

int
hash_has(hash_t *self, char *key);
```c
hash_each_key(users, {
printf("%s\n", key);
})
```
### hash_each_val(hash_t *self, block)
A macro for iterating values only.
```c
hash_each_val(users, {
printf("%s\n", (char *) val);
})
```

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

0 comments on commit fbd1069

Please sign in to comment.