Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
hash.h File Reference
#include <stdlib.h>
#include <Inventor/C/basic.h>

Go to the source code of this file.

Typedefs

typedef uintptr_t cc_hash_key
 
typedef struct cc_hash cc_hash
 
typedef cc_hash_key cc_hash_func(const cc_hash_key key)
 
typedef void cc_hash_apply_func(cc_hash_key key, void *val, void *closure)
 

Functions

cc_hashcc_hash_construct (unsigned int size, float loadfactor)
 
void cc_hash_destruct (cc_hash *ht)
 
void cc_hash_clear (cc_hash *ht)
 
SbBool cc_hash_put (cc_hash *ht, cc_hash_key key, void *val)
 
SbBool cc_hash_get (cc_hash *ht, cc_hash_key key, void **val)
 
SbBool cc_hash_remove (cc_hash *ht, cc_hash_key key)
 
void cc_hash_apply (cc_hash *ht, cc_hash_apply_func *func, void *closure)
 
unsigned int cc_hash_get_num_elements (cc_hash *ht)
 
void cc_hash_set_hash_func (cc_hash *ht, cc_hash_func *func)
 
void cc_hash_print_stat (cc_hash *ht)
 

Typedef Documentation

◆ cc_hash_key

uintptr_t cc_hash_key

The type definition used locally for a hash key.

◆ cc_hash

struct cc_hash cc_hash

The type definition for the cc_hash structure.

◆ cc_hash_func

cc_hash_key cc_hash_func

A type definition for cc_hash_func function pointers.

◆ cc_hash_apply_func

void cc_hash_apply_func

A type definition for cc_hash_apply_func function pointers.

Function Documentation

◆ cc_hash_construct()

cc_hash* cc_hash_construct ( unsigned int  size,
float  loadfactor 
)

Construct a hash table.

size is the initial bucket size. The caller need not attempt to find a good (prime number) value for this argument to ensure good hashing. That will be taken care of internally.

loadfactor is the percentage the table should be filled before resizing, and should be a number from 0 to 1. It is of course possible to specify a number bigger than 1, but then there will be greater chance of having many elements on the same bucket (linear search for an element). If you supply a number <= 0 for loadfactor, the default value 0.75 will be used.

◆ cc_hash_destruct()

void cc_hash_destruct ( cc_hash ht)

Destruct the hash table ht.

◆ cc_hash_clear()

void cc_hash_clear ( cc_hash ht)

Clear/remove all elements in the hash table ht.

◆ cc_hash_put()

SbBool cc_hash_put ( cc_hash ht,
cc_hash_key  key,
void *  val 
)

Insert a new element in the hash table ht. key is the key used to identify the element, while val is the element value. If key is already used by another element, the element value will be overwritten, and FALSE is returned. Otherwise a new element is created and TRUE is returned.

◆ cc_hash_get()

SbBool cc_hash_get ( cc_hash ht,
cc_hash_key  key,
void **  val 
)

Find the element with key value key. If found, the value is written to val, and TRUE is returned. Otherwise FALSE is returned and val is not changed.

◆ cc_hash_remove()

SbBool cc_hash_remove ( cc_hash ht,
cc_hash_key  key 
)

Attempt to remove the element with key value key. Returns TRUE if found, FALSE otherwise.

◆ cc_hash_apply()

void cc_hash_apply ( cc_hash ht,
cc_hash_apply_func func,
void *  closure 
)

Call func for for each element in the hash table.

◆ cc_hash_get_num_elements()

unsigned int cc_hash_get_num_elements ( cc_hash ht)

Return the number of elements in the hash table.

◆ cc_hash_set_hash_func()

void cc_hash_set_hash_func ( cc_hash ht,
cc_hash_func func 
)

Set the hash func that is used to map key values into a bucket index.

◆ cc_hash_print_stat()

void cc_hash_print_stat ( cc_hash ht)

For debugging only. Prints information about hash with cc_debugerror.