|
QUARK
0.9.0
QUARK-QUeuingAndRuntimeforKernels
|
#include <stdlib.h>#include <stdio.h>#include <string.h>#include <assert.h>#include "icl_hash.h"#include <limits.h>
Go to the source code of this file.
Macros | |
| #define | BITS_IN_int ( sizeof(int) * CHAR_BIT ) |
| #define | THREE_QUARTERS ((int) ((BITS_IN_int * 3) / 4)) |
| #define | ONE_EIGHTH ((int) (BITS_IN_int / 8)) |
| #define | HIGH_BITS ( ~((unsigned int)(~0) >> ONE_EIGHTH )) |
Functions/Subroutines | |
| icl_hash_t * | icl_hash_create (int nbuckets, unsigned int(*hash_function)(void *), int(*hash_key_compare)(void *, void *)) |
| void * | icl_hash_find (icl_hash_t *ht, void *key) |
| icl_entry_t * | icl_hash_insert (icl_hash_t *ht, void *key, void *data) |
| icl_entry_t * | icl_hash_update_insert (icl_hash_t *ht, void *key, void *data, void **olddata) |
| int | icl_hash_delete (icl_hash_t *ht, void *key, void(*free_key)(void *), void(*free_data)(void *)) |
| int | icl_hash_destroy (icl_hash_t *ht, void(*free_key)(void *), void(*free_data)(void *)) |
| int | icl_hash_dump (FILE *stream, icl_hash_t *ht) |
Dependency free hash table implementation.
This simple hash table implementation should be easy to drop into any other peice of code, it does not depend on anything else :-)
Definition in file icl_hash.c.
| #define BITS_IN_int ( sizeof(int) * CHAR_BIT ) |
Definition at line 24 of file icl_hash.c.
| #define HIGH_BITS ( ~((unsigned int)(~0) >> ONE_EIGHTH )) |
Definition at line 27 of file icl_hash.c.
| #define ONE_EIGHTH ((int) (BITS_IN_int / 8)) |
Definition at line 26 of file icl_hash.c.
| #define THREE_QUARTERS ((int) ((BITS_IN_int * 3) / 4)) |
Definition at line 25 of file icl_hash.c.
| icl_hash_t* icl_hash_create | ( | int | nbuckets, |
| unsigned int(*)(void *) | hash_function, | ||
| int(*)(void *, void *) | hash_key_compare | ||
| ) |
Create a new hash table.
| [in] | nbuckets | – number of buckets to create |
| [in] | hash_function | – pointer to the hashing function to be used |
| [in] | hash_key_compare | – pointer to the hash key comparison function to be used |
Definition at line 73 of file icl_hash.c.
References icl_hash_s::buckets, icl_hash_s::hash_function, icl_hash_s::hash_key_compare, icl_hash_s::nbuckets, and icl_hash_s::nentries.

| int icl_hash_delete | ( | icl_hash_t * | ht, |
| void * | key, | ||
| void(*)(void *) | free_key, | ||
| void(*)(void *) | free_data | ||
| ) |
Free one hash table entry located by key (key and data are freed using functions).
| ht | – the hash table to be freed |
| key | – the key of the new item |
| free_key | – pointer to function that frees the key |
| free_data | – pointer to function that frees the data |
Definition at line 227 of file icl_hash.c.
References icl_hash_s::buckets, icl_entry_s::data, icl_hash_s::hash_function, icl_hash_s::hash_key_compare, icl_entry_s::key, icl_hash_s::nbuckets, icl_hash_s::nentries, and icl_entry_s::next.
| int icl_hash_destroy | ( | icl_hash_t * | ht, |
| void(*)(void *) | free_key, | ||
| void(*)(void *) | free_data | ||
| ) |
Free hash table structures (key and data are freed using functions).
| ht | – the hash table to be freed |
| free_key | – pointer to function that frees the key |
| free_data | – pointer to function that frees the data |
Definition at line 265 of file icl_hash.c.
References icl_hash_s::buckets, icl_entry_s::data, icl_entry_s::key, icl_hash_s::nbuckets, and icl_entry_s::next.

| int icl_hash_dump | ( | FILE * | stream, |
| icl_hash_t * | ht | ||
| ) |
Dump the hash table's contents to the given file pointer.
| stream | – the file to which the hash table should be dumped |
| ht | – the hash table to be dumped |
Definition at line 300 of file icl_hash.c.
References icl_hash_s::buckets, icl_entry_s::data, icl_entry_s::key, icl_hash_s::nbuckets, and icl_entry_s::next.
| void* icl_hash_find | ( | icl_hash_t * | ht, |
| void * | key | ||
| ) |
Search for an entry in a hash table.
| ht | – the hash table to be searched |
| key | – the key of the item to search for |
Definition at line 108 of file icl_hash.c.
References icl_hash_s::buckets, icl_entry_s::data, icl_hash_s::hash_function, icl_hash_s::hash_key_compare, icl_entry_s::key, icl_hash_s::nbuckets, and icl_entry_s::next.

| icl_entry_t* icl_hash_insert | ( | icl_hash_t * | ht, |
| void * | key, | ||
| void * | data | ||
| ) |
Insert an item into the hash table.
| ht | – the hash table |
| key | – the key of the new item |
| data | – pointer to the new item's data |
Definition at line 135 of file icl_hash.c.
References icl_hash_s::buckets, icl_entry_s::data, icl_hash_s::hash_function, icl_hash_s::hash_key_compare, icl_entry_s::key, icl_hash_s::nbuckets, icl_hash_s::nentries, and icl_entry_s::next.

| icl_entry_t* icl_hash_update_insert | ( | icl_hash_t * | ht, |
| void * | key, | ||
| void * | data, | ||
| void ** | olddata | ||
| ) |
Replace entry in hash table with the given entry.
| ht | – the hash table |
| key | – the key of the new item |
| data | – pointer to the new item's data |
| olddata | – pointer to the old item's data (set upon return) |
Definition at line 175 of file icl_hash.c.
References icl_hash_s::buckets, icl_entry_s::data, icl_hash_s::hash_function, icl_hash_s::hash_key_compare, icl_entry_s::key, icl_hash_s::nbuckets, icl_hash_s::nentries, and icl_entry_s::next.