Updating for 1.0.2 release
[awesomized/libmemcached] / libhashkit / digest.cc
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 <libhashkit/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 #ifdef HAVE_MURMUR_HASH
42 return libhashkit_murmur(key, key_length);
43 #else
44 return 1;
45 #endif
46 case HASHKIT_HASH_JENKINS:
47 return libhashkit_jenkins(key, key_length);
48 case HASHKIT_HASH_CUSTOM:
49 case HASHKIT_HASH_MAX:
50 default:
51 if (DEBUG)
52 {
53 fprintf(stderr, "hashkit_hash_t was extended but libhashkit_generate_value was not updated\n");
54 fflush(stderr);
55 assert(0);
56 }
57 break;
58 }
59
60 return 1;
61 }