This hash table module map 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 a itable, use itable_firstkey and itable_nextkey:
int key; void *value;
itable_firstkey(h);
while(itable_nextkey(h,&key,&value)) { printf("table contains: %d\n",key); }
Go to the source code of this file.
Functions | |
itable * | itable_create (int buckets) |
Create a new integer table. | |
void | itable_delete (struct itable *h) |
Delete an integer table. | |
int | itable_size (struct itable *h) |
Count the entries in an integer table. | |
int | itable_insert (struct itable *h, int key, const void *value) |
Insert a key and value. | |
void * | itable_lookup (struct itable *h, int key) |
Look up a value by key. | |
void * | itable_remove (struct itable *h, int key) |
Remove a value by key. | |
void | itable_firstkey (struct itable *h) |
Begin iteration over all keys. | |
int | itable_nextkey (struct itable *h, int *key, void **value) |
Continue iteration over all keys. |
|
Create a new integer table.
|
|
Delete an integer table. Note that this function will not delete all of the objects contained within the integer table.
|
|
Count the entries in an integer table.
|
|
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.
|
|
Look up a value by key.
|
|
Remove a value by key.
|
|
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.
|
|
Continue iteration over all keys. This function returns the next key and value in the iteration.
|