1 #ifndef __CMPH_HASH_H__
2 #define __CMPH_HASH_H__
4 #include "cmph_types.h"
6 typedef union __hash_state_t hash_state_t;
8 hash_state_t *hash_state_new(CMPH_HASH, cmph_uint32 hashsize);
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.
16 cmph_uint32 hash(hash_state_t *state, const char *key, cmph_uint32 keylen);
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.
24 void hash_vector(hash_state_t *state, const char *key, cmph_uint32 keylen, cmph_uint32 * hashes);
26 void hash_state_dump(hash_state_t *state, char **buf, cmph_uint32 *buflen);
28 hash_state_t * hash_state_copy(hash_state_t *src_state);
30 hash_state_t *hash_state_load(const char *buf, cmph_uint32 buflen);
32 void hash_state_destroy(hash_state_t *state);
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()
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.
42 void hash_state_pack(hash_state_t *state, void *hash_packed);
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.
51 cmph_uint32 hash_packed(void *hash_packed, CMPH_HASH hashfunc, const char *k, cmph_uint32 keylen);
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
58 cmph_uint32 hash_state_packed_size(CMPH_HASH hashfunc);
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.
67 void hash_vector_packed(void *hash_packed, CMPH_HASH hashfunc, const char *k, cmph_uint32 keylen, cmph_uint32 * hashes);
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
74 CMPH_HASH hash_get_type(hash_state_t *state);