hashlib.c File Reference
the implementation of the hashing library
More...
#include "config.h"
#include "defines.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <stddef.h>
#include "hashlib.h"
Go to the source code of this file.
|
Functions |
| ub4 | lookup (register ub1 *k, register ub4 length, register ub4 level) |
| t_cf_hash * | cf_hash_new (t_cf_hash_cleanup cl) |
| int | cf_hash_set (t_cf_hash *hsh, unsigned char *key, size_t keylen, void *data, size_t datalen) |
| int | cf_hash_set_static (t_cf_hash *hsh, unsigned char *key, size_t keylen, void *data) |
| void * | cf_hash_get (t_cf_hash *hsh, unsigned char *key, size_t keylen) |
| int | cf_hash_entry_delete (t_cf_hash *hsh, unsigned char *key, size_t keylen) |
| void | cf_hash_destroy (t_cf_hash *hsh) |
Detailed Description
the implementation of the hashing library
- Author:
- Christian Kruse, <cjk@wwwtech.de>
The hashing library was developed within the Classic Forum project, <http://cforum.teamone.de/>
I use a hashing algorithm developed by Bob Jenkins, December 1996. This is (directly after the SDBM algorithm) the fastest hashing algorithm at this time, but the SDBM algorithm has more duplicates. The Fowler/Noll/Vo algorithm has no duplicates, but it is also the slowest of these three algorithms. So the Bob-Jenkins algorithm should be a moderate compromiss.
Definition in file hashlib.c.
Function Documentation
|
|
This function destroys a hash and frees all of its values. After this function call you have to create a new hash with cf_hash_new()! - Parameters:
-
| hsh | The hash table to destroy. |
Definition at line 601 of file hashlib.c. |
| int cf_hash_entry_delete |
( |
t_cf_hash * |
hsh, |
|
|
unsigned char * |
key, |
|
|
size_t |
keylen |
|
) |
|
|
|
|
This function deletes a hash entry in a hashtable. - Parameters:
-
| hsh | The hash table |
| key | The key of the entry |
| keylen | The length of the key |
- Returns:
- It returns 0 if the entry could not be found and 1 if the entry has been deleted successfully.
Definition at line 555 of file hashlib.c. |
| void* cf_hash_get |
( |
t_cf_hash * |
hsh, |
|
|
unsigned char * |
key, |
|
|
size_t |
keylen |
|
) |
|
|
|
|
This function looks up a hash entry in a hash table. If an entry with the key could not be found, NULL is returned. - Parameters:
-
| hsh | The hash table |
| key | The key of the entry |
| keylen | The length of the key |
- Returns:
- The data of the entry if it has been found or NULL if it could not be found.
Definition at line 527 of file hashlib.c. |
|
|
This function constructs a new hash. It expects a pointer to a destructor function. This function will be called when a hash entry will be destroyed. This can happen if you call 'cf_hash_entry_delete' or if you call 'cf_hash_destroy'. You MUST NOT free the data object itself! This will be done internaly. You only should cleanup the structure if it is a complex data structure like a struct or an array of arrays. - Parameters:
-
| cl | The destructor for a data entry of the hash table. If the function pointer is NULL, no cleanup function will be called. |
- Returns:
- It returns the new created hash table object on success or NULL on failure
Definition at line 175 of file hashlib.c. |
| int cf_hash_set |
( |
t_cf_hash * |
hsh, |
|
|
unsigned char * |
key, |
|
|
size_t |
keylen, |
|
|
void * |
data, |
|
|
size_t |
datalen |
|
) |
|
|
|
|
This function saves a hash entry with the given key in the hash table. It can happen that the table has to be resized, but this should not happen very often (there's one double hashvalue in a 32 bit keylen and we accept 5 double hashvalues per entry). But *when* it happens, this call is very expensive... - Parameters:
-
| hsh | The hash table |
| key | The key of the entry |
| keylen | The length of the key |
| data | The data of the entry |
| datalen | The size of the data |
- Returns:
- 0 on failure, 1 if successful
Definition at line 382 of file hashlib.c. |
| int cf_hash_set_static |
( |
t_cf_hash * |
hsh, |
|
|
unsigned char * |
key, |
|
|
size_t |
keylen, |
|
|
void * |
data |
|
) |
|
|
|
|
This function saves a hash entry with the given key in the hash table. It can happen that the table has to be resized, but this should not happen very often (there's one double hashvalue in a 32 bit keylen and we accept 5 double hashvalues per entry). But *when* it happens, this call is very expensive... The difference between cf_hash_set() is, that cf_hash_set() makes a copy from the data and cf_hash_set_static() assumes static data which needs not to be copied and needs no free() call - Parameters:
-
| hsh | The hash table |
| key | The key of the entry |
| keylen | The length of the key |
| data | The data of the entry |
- Returns:
- 0 on failure, 1 if successful
Definition at line 457 of file hashlib.c. |
| ub4 lookup |
( |
register ub1 * |
k, |
|
|
register ub4 |
length, |
|
|
register ub4 |
level |
|
) |
|
|
|
|
This function is used to generate a hash sum from a given key. - Parameters:
-
| k | The key to calculate the hashsum from |
| length | The length of the key |
| level | The entropy level. It is used to mix a little bit random into the keys. Not used by this hash table library. |
- Returns:
- the hash sum
Definition at line 114 of file hashlib.c. |
Generated on Sun Apr 25 16:37:39 2004 for Classic Forum by
1.3.5