Updated for custom hash functions/setting functions.
[awesomized/libmemcached] / libhashkit / hashkit.h
1 /* HashKit
2 * Copyright (C) 2009 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 #ifndef HASHKIT_H
10 #define HASHKIT_H
11
12 #if !defined(__cplusplus)
13 # include <stdbool.h>
14 #endif
15 #include <inttypes.h>
16 #include <sys/types.h>
17 #include <libhashkit/visibility.h>
18 #include <libhashkit/types.h>
19 #include <libhashkit/algorithm.h>
20 #include <libhashkit/behavior.h>
21 #include <libhashkit/strerror.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 struct hashkit_st
28 {
29 struct {
30 hashkit_hash_fn function;
31 void *context;
32 } base_hash;
33
34 struct {
35 bool is_allocated:1;
36 } options;
37 };
38
39 HASHKIT_API
40 hashkit_st *hashkit_create(hashkit_st *hash);
41
42 HASHKIT_API
43 hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *ptr);
44
45 HASHKIT_API
46 void hashkit_free(hashkit_st *hash);
47
48 HASHKIT_API
49 uint32_t hashkit_generate_value(const hashkit_st *self, const char *key, size_t key_length);
50
51 HASHKIT_API
52 hashkit_return_t hashkit_set_base_function(hashkit_st *hash, hashkit_hash_algorithm_t hash_algorithm);
53
54 HASHKIT_API
55 hashkit_return_t hashkit_set_base_function_custom(hashkit_st *hash, hashkit_hash_fn function, void *context);
56
57 HASHKIT_API
58 uint32_t libhashkit_generate_value(const char *key, size_t key_length, hashkit_hash_algorithm_t hash_algorithm);
59
60 #define hashkit_is_allocated(__object) ((__object)->options.is_allocated)
61 #define hashkit_is_initialized(__object) ((__object)->options.is_initialized)
62
63 /** @} */
64
65 #ifdef __cplusplus
66 }
67 #endif
68
69 #endif /* HASHKIT_H */