2 * Copyright (C) 2009 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_fn
*fetch_hash_fn(hashkit_hash_algorithm_t hash_algorithm
)
13 switch (hash_algorithm
)
15 case HASHKIT_HASH_DEFAULT
:
16 return hashkit_default
;
17 case HASHKIT_HASH_MD5
:
19 case HASHKIT_HASH_CRC
:
21 case HASHKIT_HASH_FNV1_64
:
22 return hashkit_fnv1_64
;
23 case HASHKIT_HASH_FNV1A_64
:
24 return hashkit_fnv1a_64
;
25 case HASHKIT_HASH_FNV1_32
:
26 return hashkit_fnv1_32
;
27 case HASHKIT_HASH_FNV1A_32
:
28 return hashkit_fnv1a_32
;
29 case HASHKIT_HASH_HSIEH
:
30 #ifdef HAVE_HSIEH_HASH
35 case HASHKIT_HASH_MURMUR
:
36 return hashkit_murmur
;
37 case HASHKIT_HASH_JENKINS
:
38 return hashkit_jenkins
;
39 case HASHKIT_HASH_MAX
:
42 fprintf(stderr
, "hashkit_hash_t was extended but hashkit_generate_value was not updated\n");
52 hashkit_return_t
hashkit_behavior_set_distribution(hashkit_st
*hashkit
, hashkit_distribution_t distribution
)
54 hashkit
->distribution
= distribution
;
56 return HASHKIT_SUCCESS
;
60 hashkit_distribution_t
hashkit_behavior_get_distribution(hashkit_st
*hashkit
)
62 return hashkit
->distribution
;
67 @note For the moment we will not allow the user to set the distribution hash type.
69 hashkit_return_t
hashkit_behavior_set_key_hash_algorithm(hashkit_st
*hashkit
, hashkit_hash_algorithm_t hash_algorithm
)
71 hashkit_fn
*hash_fn
= fetch_hash_fn(hash_algorithm
);
74 return HASHKIT_FAILURE
;
76 hashkit
->hash_fn
= hash_fn
;
77 hashkit
->for_key
= hash_algorithm
;
78 hashkit
->for_distribution
= hash_algorithm
;
80 return HASHKIT_SUCCESS
;
84 hashkit_hash_algorithm_t
hashkit_behavior_get_key_hash_algorithm(hashkit_st
*hashkit
)
86 return hashkit
->for_key
;
90 void hashkit_behavior_set_active_fn(hashkit_st
*hashkit
, hashkit_active_fn
*function
)
92 hashkit
->active_fn
= function
;
96 hashkit_active_fn
* hashkit_behavior_get_active_fn(hashkit_st
*hashkit
)
98 return hashkit
->active_fn
;
102 void hashkit_behavior_set_continuum_hash_fn(hashkit_st
*hashkit
, hashkit_fn
*function
)
104 hashkit
->continuum_hash_fn
= function
;
108 hashkit_fn
* hashkit_behavior_get_continuum_hash_fn(hashkit_st
*hashkit
)
110 return hashkit
->continuum_hash_fn
;
114 void hashkit_behavior_set_continuum_key_fn(hashkit_st
*hashkit
, hashkit_key_fn
*function
)
116 hashkit
->continuum_key_fn
= function
;
120 hashkit_key_fn
* hashkit_behavior_get_continuum_key_fn(hashkit_st
*hashkit
)
122 return hashkit
->continuum_key_fn
;
126 void hashkit_behavior_set_sort_fn(hashkit_st
*hashkit
, hashkit_sort_fn
*function
)
128 hashkit
->sort_fn
= function
;
132 hashkit_sort_fn
* hashkit_behavior_get_sort_fn(hashkit_st
*hashkit
)
134 return hashkit
->sort_fn
;
138 void hashkit_behavior_set_weight_fn(hashkit_st
*hashkit
, hashkit_weight_fn
*function
)
140 hashkit
->weight_fn
= function
;
144 hashkit_weight_fn
* hashkit_behavior_get_weight_fn(hashkit_st
*hashkit
)
146 return hashkit
->weight_fn
;