Fix for bug #15450
[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 /**
10 * @file
11 * @brief HashKit Header
12 */
13
14 #ifndef HASHKIT_H
15 #define HASHKIT_H
16
17 #if !defined(__cplusplus)
18 # include <stdbool.h>
19 #endif
20 #include <inttypes.h>
21 #include <sys/types.h>
22 #include <libhashkit/visibility.h>
23 #include <libhashkit/types.h>
24 #include <libhashkit/algorithm.h>
25 #include <libhashkit/behavior.h>
26 #include <libhashkit/strerror.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /**
33 * @addtogroup hashkit_constants Constants
34 * @ingroup hashkit
35 * @{
36 */
37
38 /* Defines. */
39 #define HASHKIT_MAX_KEY 251
40 #define HASHKIT_POINTS_PER_NODE 100
41 #define HASHKIT_POINTS_PER_NODE_WEIGHTED 160
42 #define HASHKIT_CONTINUUM_ADDITION 10
43 #define HASHKIT_CONTINUUM_KEY_SIZE 86
44
45 /** @} */
46
47 /**
48 * @ingroup hashkit
49 */
50 struct hashkit_st
51 {
52 hashkit_options_st options;
53 hashkit_distribution_t distribution;
54 uint32_t continuum_count;
55 uint32_t continuum_points_count;
56 size_t list_size;
57 size_t context_size;
58
59 /**
60 @note There are two places we use hashing, one is for when we have a key
61 and we want to find out what server it should be placed on. The second is
62 for when we are placing a value into the continuum.
63 */
64 hashkit_hash_algorithm_t for_key;
65 hashkit_hash_algorithm_t for_distribution;
66
67 hashkit_continuum_point_st *continuum;
68 hashkit_fn *hash_fn;
69 hashkit_active_fn *active_fn;
70 hashkit_fn *continuum_hash_fn;
71 hashkit_key_fn *continuum_key_fn;
72 hashkit_sort_fn *sort_fn;
73 hashkit_weight_fn *weight_fn;
74 void *list;
75 };
76
77 /**
78 * @ingroup hashkit
79 */
80 struct hashkit_continuum_point_st
81 {
82 uint32_t index;
83 uint32_t value;
84 };
85
86 /**
87 * @addtogroup hashkit Pandora Hash Declarations
88 * @{
89 */
90
91 HASHKIT_API
92 hashkit_st *hashkit_create(hashkit_st *hash);
93
94 HASHKIT_API
95 hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *ptr);
96
97 HASHKIT_API
98 void hashkit_free(hashkit_st *hash);
99
100 HASHKIT_API
101 uint32_t hashkit_generate_value(const char *key, size_t key_length, hashkit_hash_algorithm_t hash_algorithm);
102
103 #define hashkit_is_allocated(__object) ((__object)->options.is_allocated)
104 #define hashkit_is_initialized(__object) ((__object)->options.is_initialized)
105
106 /** @} */
107
108 #ifdef __cplusplus
109 }
110 #endif
111
112 #endif /* HASHKIT_H */