itable.h File Reference

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.
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, UINT64_T key, const void *value)
 Insert a key and value.
void * itable_lookup (struct itable *h, UINT64_T key)
 Look up a value by key.
void * itable_remove (struct itable *h, UINT64_T key)
 Remove a value by key.
void itable_firstkey (struct itable *h)
 Begin iteration over all keys.
int itable_nextkey (struct itable *h, UINT64_T *key, void **value)
 Continue iteration over all keys.

Detailed Description

An integer-indexed hash table.

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 like this:

UINT64_T  key;
void *value;
itable_firstkey(h);
while(itable_nextkey(h,&key,&value)) {
	printf("table contains: %d\n",key);
}

Function Documentation

struct itable* itable_create ( int  buckets  )  [read]

Create a new integer table.

Parameters:
buckets The number of buckets in the table. If zero, a default value will be used.
Returns:
A pointer to a new integer table.
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.

Parameters:
h The integer table to delete.
int itable_size ( struct itable *  h  ) 

Count the entries in an integer table.

Returns:
The number of entries in the table.
Parameters:
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.

Parameters:
h A pointer to an integer table.
key An integer key
value A pointer to store with the key.
Returns:
One if the insert succeeded, failure otherwise
void* itable_lookup ( struct itable *  h,
UINT64_T  key 
)

Look up a value by key.

Parameters:
h A pointer to an integer table.
key An integer key to search for.
Returns:
If found, the pointer associated with the key, otherwise null.
void* itable_remove ( struct itable *  h,
UINT64_T  key 
)

Remove a value by key.

Parameters:
h A pointer to an integer table.
key An integer key to remove.
Returns:
If found, the pointer associated with the key, otherwise null.
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.

Parameters:
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.

Parameters:
h A pointer to an integer table.
key A pointer to a key integer.
value A pointer to a value pointer.
Returns:
Zero if there are no more elements to visit, one otherwise.
Generated on Sun Aug 14 20:55:54 2011 for cctools by  doxygen 1.6.3