cctools
|
An integer-indexed hash table. More...
#include "int_sizes.h"
Go to the source code of this file.
Functions | |
struct itable * | itable_create (int buckets) |
Create a new integer table. More... | |
void | itable_clear (struct itable *h) |
Remove all entries from an integer table. More... | |
void | itable_delete (struct itable *h) |
Delete an integer table. More... | |
int | itable_size (struct itable *h) |
Count the entries in an integer table. More... | |
int | itable_insert (struct itable *h, UINT64_T key, const void *value) |
Insert a key and value. More... | |
void * | itable_lookup (struct itable *h, UINT64_T key) |
Look up a value by key. More... | |
void * | itable_remove (struct itable *h, UINT64_T key) |
Remove a value by key. More... | |
void | itable_firstkey (struct itable *h) |
Begin iteration over all keys. More... | |
int | itable_nextkey (struct itable *h, UINT64_T *key, void **value) |
Continue iteration over all keys. More... | |
An integer-indexed hash table.
This hash table module maps integers to arbitrary objects (void pointers). For example, to store a filename using the file descriptor as a key:
struct itable *t; t = itable_create(0);
fd = open(pathname,O_RDONLY,0);
itable_insert(t,fd,pathname); pathname = itable_remove(h,id);
To list all of the items in an itable, use itable_firstkey and itable_nextkey like this:
UINT64_T key; void *value;
itable_firstkey(h);
while(itable_nextkey(h,&key,&value)) { printf("table contains: %d\n",key); }
struct itable* itable_create | ( | int | buckets | ) |
Create a new integer table.
buckets | The number of buckets in the table. If zero, a default value will be used. |
void itable_clear | ( | struct itable * | h | ) |
Remove all entries from an integer table.
Note that this function will not delete all of the objects contained within the integer table.
h | The integer table to delete. |
void itable_delete | ( | struct itable * | h | ) |
Delete an integer table.
Note that this function will not delete all of the objects contained within the integer table.
h | The integer table to delete. |
int itable_size | ( | struct itable * | h | ) |
Count the entries in an integer table.
h | A pointer to an integer table. |
int itable_insert | ( | struct itable * | h, |
UINT64_T | key, | ||
const void * | value | ||
) |
Insert a key and value.
This call will fail if the table already contains the same key. You must call itable_remove to remove it. Also note that you cannot insert a null value into the table.
h | A pointer to an integer table. |
key | An integer key |
value | A pointer to store with the key. |
void* itable_lookup | ( | struct itable * | h, |
UINT64_T | key | ||
) |
Look up a value by key.
h | A pointer to an integer table. |
key | An integer key to search for. |
void* itable_remove | ( | struct itable * | h, |
UINT64_T | key | ||
) |
Remove a value by key.
h | A pointer to an integer table. |
key | An integer key to remove. |
void itable_firstkey | ( | struct itable * | h | ) |
Begin iteration over all keys.
This function begins a new iteration over an integer table, allowing you to visit every key and value in the table. Next, invoke itable_nextkey to retrieve each value in order.
h | A pointer to an integer table. |
int itable_nextkey | ( | struct itable * | h, |
UINT64_T * | key, | ||
void ** | value | ||
) |
Continue iteration over all keys.
This function returns the next key and value in the iteration.
h | A pointer to an integer table. |
key | A pointer to a key integer. |
value | A pointer to a value pointer. (can be NULL) |