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
;
57 return HASHKIT_SUCCESS
;
60 hashkit_return_t
hashkit_set_function(hashkit_st
*self
, hashkit_hash_algorithm_t hash_algorithm
)
62 return _set_function(&self
->base_hash
, hash_algorithm
);
65 hashkit_return_t
hashkit_set_distribution_function(hashkit_st
*self
, hashkit_hash_algorithm_t hash_algorithm
)
67 return _set_function(&self
->distribution_hash
, hash_algorithm
);
70 static hashkit_return_t
_set_custom_function(struct hashkit_function_st
*self
, hashkit_hash_fn function
, void *context
)
74 self
->function
= function
;
75 self
->context
= context
;
77 return HASHKIT_SUCCESS
;
80 return HASHKIT_FAILURE
;
83 hashkit_return_t
hashkit_set_custom_function(hashkit_st
*self
, hashkit_hash_fn function
, void *context
)
85 return _set_custom_function(&self
->base_hash
, function
, context
);
88 hashkit_return_t
hashkit_set_custom_distribution_function(hashkit_st
*self
, hashkit_hash_fn function
, void *context
)
90 return _set_custom_function(&self
->distribution_hash
, function
, context
);
93 static hashkit_hash_algorithm_t
get_function_type(const hashkit_hash_fn function
)
95 if (function
== hashkit_one_at_a_time
)
97 return HASHKIT_HASH_DEFAULT
;
99 else if (function
== hashkit_md5
)
101 return HASHKIT_HASH_MD5
;
103 else if (function
== hashkit_crc32
)
105 return HASHKIT_HASH_CRC
;
107 else if (function
== hashkit_fnv1_64
)
109 return HASHKIT_HASH_FNV1_64
;
111 else if (function
== hashkit_fnv1a_64
)
113 return HASHKIT_HASH_FNV1A_64
;
115 else if (function
== hashkit_fnv1_32
)
117 return HASHKIT_HASH_FNV1_32
;
119 else if (function
== hashkit_fnv1a_32
)
121 return HASHKIT_HASH_FNV1A_32
;
123 #ifdef HAVE_HSIEH_HASH
124 else if (function
== hashkit_hsieh
)
126 return HASHKIT_HASH_HSIEH
;
129 else if (function
== hashkit_murmur
)
131 return HASHKIT_HASH_MURMUR
;
133 else if (function
== hashkit_jenkins
)
135 return HASHKIT_HASH_JENKINS
;
138 return HASHKIT_HASH_CUSTOM
;
141 hashkit_hash_algorithm_t
hashkit_get_function(const hashkit_st
*self
)
143 return get_function_type(self
->base_hash
.function
);
146 hashkit_hash_algorithm_t
hashkit_get_distribution_function(const hashkit_st
*self
)
148 return get_function_type(self
->distribution_hash
.function
);