2 * Copyright (C) 2010 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
11 static hashkit_return_t
_set_function(struct hashkit_function_st
*self
, hashkit_hash_algorithm_t hash_algorithm
)
13 switch (hash_algorithm
)
15 case HASHKIT_HASH_DEFAULT
:
16 self
->function
= hashkit_one_at_a_time
;
18 case HASHKIT_HASH_MD5
:
19 self
->function
= hashkit_md5
;
21 case HASHKIT_HASH_CRC
:
22 self
->function
= hashkit_crc32
;
24 case HASHKIT_HASH_FNV1_64
:
25 self
->function
= hashkit_fnv1_64
;
27 case HASHKIT_HASH_FNV1A_64
:
28 self
->function
= hashkit_fnv1a_64
;
30 case HASHKIT_HASH_FNV1_32
:
31 self
->function
= hashkit_fnv1_32
;
33 case HASHKIT_HASH_FNV1A_32
:
34 self
->function
= hashkit_fnv1a_32
;
36 case HASHKIT_HASH_HSIEH
:
37 #ifdef HAVE_HSIEH_HASH
38 self
->function
= hashkit_hsieh
;
41 return HASHKIT_FAILURE
;
43 case HASHKIT_HASH_MURMUR
:
44 self
->function
= hashkit_murmur
;
46 case HASHKIT_HASH_JENKINS
:
47 self
->function
= hashkit_jenkins
;
49 case HASHKIT_HASH_CUSTOM
:
50 case HASHKIT_HASH_MAX
:
52 return HASHKIT_FAILURE
;
58 return HASHKIT_SUCCESS
;
61 hashkit_return_t
hashkit_set_function(hashkit_st
*self
, hashkit_hash_algorithm_t hash_algorithm
)
63 return _set_function(&self
->base_hash
, hash_algorithm
);
66 hashkit_return_t
hashkit_set_distribution_function(hashkit_st
*self
, hashkit_hash_algorithm_t hash_algorithm
)
68 return _set_function(&self
->distribution_hash
, hash_algorithm
);
71 static hashkit_return_t
_set_custom_function(struct hashkit_function_st
*self
, hashkit_hash_fn function
, void *context
)
75 self
->function
= function
;
76 self
->context
= context
;
78 return HASHKIT_SUCCESS
;
81 return HASHKIT_FAILURE
;
84 hashkit_return_t
hashkit_set_custom_function(hashkit_st
*self
, hashkit_hash_fn function
, void *context
)
86 return _set_custom_function(&self
->base_hash
, function
, context
);
89 hashkit_return_t
hashkit_set_custom_distribution_function(hashkit_st
*self
, hashkit_hash_fn function
, void *context
)
91 return _set_custom_function(&self
->distribution_hash
, function
, context
);
94 static hashkit_hash_algorithm_t
get_function_type(const hashkit_hash_fn function
)
96 if (function
== hashkit_one_at_a_time
)
98 return HASHKIT_HASH_DEFAULT
;
100 else if (function
== hashkit_md5
)
102 return HASHKIT_HASH_MD5
;
104 else if (function
== hashkit_crc32
)
106 return HASHKIT_HASH_CRC
;
108 else if (function
== hashkit_fnv1_64
)
110 return HASHKIT_HASH_FNV1_64
;
112 else if (function
== hashkit_fnv1a_64
)
114 return HASHKIT_HASH_FNV1A_64
;
116 else if (function
== hashkit_fnv1_32
)
118 return HASHKIT_HASH_FNV1_32
;
120 else if (function
== hashkit_fnv1a_32
)
122 return HASHKIT_HASH_FNV1A_32
;
124 #ifdef HAVE_HSIEH_HASH
125 else if (function
== hashkit_hsieh
)
127 return HASHKIT_HASH_HSIEH
;
130 else if (function
== hashkit_murmur
)
132 return HASHKIT_HASH_MURMUR
;
134 else if (function
== hashkit_jenkins
)
136 return HASHKIT_HASH_JENKINS
;
139 return HASHKIT_HASH_CUSTOM
;
142 hashkit_hash_algorithm_t
hashkit_get_function(const hashkit_st
*self
)
144 return get_function_type(self
->base_hash
.function
);
147 hashkit_hash_algorithm_t
hashkit_get_distribution_function(const hashkit_st
*self
)
149 return get_function_type(self
->distribution_hash
.function
);