| 1 |
#ifndef __CMPH_HASH_H__ |
| 2 |
#define __CMPH_HASH_H__ |
| 3 |
|
| 4 |
#include "cmph_types.h" |
| 5 |
|
| 6 |
typedef union __hash_state_t hash_state_t; |
| 7 |
|
| 8 |
hash_state_t *hash_state_new(CMPH_HASH, cmph_uint32 hashsize); |
| 9 |
|
| 10 |
/** \fn cmph_uint32 hash(hash_state_t *state, const char *key, cmph_uint32 keylen); |
| 11 |
* \param state is a pointer to a hash_state_t structure |
| 12 |
* \param key is a pointer to a key |
| 13 |
* \param keylen is the key length |
| 14 |
* \return an integer that represents a hash value of 32 bits. |
| 15 |
*/ |
| 16 |
cmph_uint32 hash(hash_state_t *state, const char *key, cmph_uint32 keylen); |
| 17 |
|
| 18 |
/** \fn void hash_vector(hash_state_t *state, const char *key, cmph_uint32 keylen, cmph_uint32 * hashes); |
| 19 |
* \param state is a pointer to a hash_state_t structure |
| 20 |
* \param key is a pointer to a key |
| 21 |
* \param keylen is the key length |
| 22 |
* \param hashes is a pointer to a memory large enough to fit three 32-bit integers. |
| 23 |
*/ |
| 24 |
void hash_vector(hash_state_t *state, const char *key, cmph_uint32 keylen, cmph_uint32 * hashes); |
| 25 |
|
| 26 |
void hash_state_dump(hash_state_t *state, char **buf, cmph_uint32 *buflen); |
| 27 |
|
| 28 |
hash_state_t * hash_state_copy(hash_state_t *src_state); |
| 29 |
|
| 30 |
hash_state_t *hash_state_load(const char *buf, cmph_uint32 buflen); |
| 31 |
|
| 32 |
void hash_state_destroy(hash_state_t *state); |
| 33 |
|
| 34 |
/** \fn void hash_state_pack(hash_state_t *state, void *hash_packed); |
| 35 |
* \brief Support the ability to pack a hash function into a preallocated contiguous memory space pointed by hash_packed. |
| 36 |
* \param state points to the hash function |
| 37 |
* \param hash_packed pointer to the contiguous memory area used to store the hash function. The size of hash_packed must be at least hash_state_packed_size() |
| 38 |
* |
| 39 |
* Support the ability to pack a hash function into a preallocated contiguous memory space pointed by hash_packed. |
| 40 |
* However, the hash function type must be packed outside. |
| 41 |
*/ |
| 42 |
void hash_state_pack(hash_state_t *state, void *hash_packed); |
| 43 |
|
| 44 |
/** \fn cmph_uint32 hash_packed(void *hash_packed, CMPH_HASH hashfunc, const char *k, cmph_uint32 keylen); |
| 45 |
* \param hash_packed is a pointer to a contiguous memory area |
| 46 |
* \param hashfunc is the type of the hash function packed in hash_packed |
| 47 |
* \param key is a pointer to a key |
| 48 |
* \param keylen is the key length |
| 49 |
* \return an integer that represents a hash value of 32 bits. |
| 50 |
*/ |
| 51 |
cmph_uint32 hash_packed(void *hash_packed, CMPH_HASH hashfunc, const char *k, cmph_uint32 keylen); |
| 52 |
|
| 53 |
/** \fn cmph_uint32 hash_state_packed_size(CMPH_HASH hashfunc) |
| 54 |
* \brief Return the amount of space needed to pack a hash function. |
| 55 |
* \param hashfunc function type |
| 56 |
* \return the size of the packed function or zero for failures |
| 57 |
*/ |
| 58 |
cmph_uint32 hash_state_packed_size(CMPH_HASH hashfunc); |
| 59 |
|
| 60 |
|
| 61 |
/** \fn hash_vector_packed(void *hash_packed, CMPH_HASH hashfunc, const char *k, cmph_uint32 keylen, cmph_uint32 * hashes); |
| 62 |
* \param hash_packed is a pointer to a contiguous memory area |
| 63 |
* \param key is a pointer to a key |
| 64 |
* \param keylen is the key length |
| 65 |
* \param hashes is a pointer to a memory large enough to fit three 32-bit integers. |
| 66 |
*/ |
| 67 |
void hash_vector_packed(void *hash_packed, CMPH_HASH hashfunc, const char *k, cmph_uint32 keylen, cmph_uint32 * hashes); |
| 68 |
|
| 69 |
|
| 70 |
/** \fn CMPH_HASH hash_get_type(hash_state_t *state); |
| 71 |
* \param state is a pointer to a hash_state_t structure |
| 72 |
* \return the hash function type pointed by state |
| 73 |
*/ |
| 74 |
CMPH_HASH hash_get_type(hash_state_t *state); |
| 75 |
|
| 76 |
#endif |