merge.
[m6w6/libmemcached] / libhashkit / digest.c
1 /* HashKit
2 * Copyright (C) 2010 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 */
8
9 #include "common.h"
10
11 uint32_t hashkit_digest(const hashkit_st *self, const char *key, size_t key_length)
12 {
13 return self->base_hash.function(key, key_length, self->base_hash.context);
14 }
15
16 uint32_t libhashkit_digest(const char *key, size_t key_length, hashkit_hash_algorithm_t hash_algorithm)
17 {
18 switch (hash_algorithm)
19 {
20 case HASHKIT_HASH_DEFAULT:
21 return libhashkit_one_at_a_time(key, key_length);
22 case HASHKIT_HASH_MD5:
23 return libhashkit_md5(key, key_length);
24 case HASHKIT_HASH_CRC:
25 return libhashkit_crc32(key, key_length);
26 case HASHKIT_HASH_FNV1_64:
27 return libhashkit_fnv1_64(key, key_length);
28 case HASHKIT_HASH_FNV1A_64:
29 return libhashkit_fnv1a_64(key, key_length);
30 case HASHKIT_HASH_FNV1_32:
31 return libhashkit_fnv1_32(key, key_length);
32 case HASHKIT_HASH_FNV1A_32:
33 return libhashkit_fnv1a_32(key, key_length);
34 case HASHKIT_HASH_HSIEH:
35 #ifdef HAVE_HSIEH_HASH
36 return libhashkit_hsieh(key, key_length);
37 #else
38 return 1;
39 #endif
40 case HASHKIT_HASH_MURMUR:
41 return libhashkit_murmur(key, key_length);
42 case HASHKIT_HASH_JENKINS:
43 return libhashkit_jenkins(key, key_length);
44 case HASHKIT_HASH_CUSTOM:
45 case HASHKIT_HASH_MAX:
46 default:
47 #ifdef HAVE_DEBUG
48 fprintf(stderr, "hashkit_hash_t was extended but libhashkit_generate_value was not updated\n");
49 fflush(stderr);
50 assert(0);
51 #endif
52 break;
53 }
54
55 return 1;
56 }