2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
9 #include <libhashkit/common.h>
11 static inline void _hashkit_init(hashkit_st
*self
)
13 self
->base_hash
.function
= hashkit_one_at_a_time
;
14 self
->base_hash
.context
= NULL
;
16 self
->distribution_hash
.function
= hashkit_one_at_a_time
;
17 self
->distribution_hash
.context
= NULL
;
19 self
->flags
.is_base_same_distributed
= true;
22 static inline hashkit_st
*_hashkit_create(hashkit_st
*self
)
32 self
->options
.is_allocated
= true;
36 self
->options
.is_allocated
= false;
42 hashkit_st
*hashkit_create(hashkit_st
*self
)
44 self
= _hashkit_create(self
);
54 void hashkit_free(hashkit_st
*self
)
56 if (hashkit_is_allocated(self
))
62 hashkit_st
*hashkit_clone(hashkit_st
*destination
, const hashkit_st
*source
)
66 return hashkit_create(destination
);
69 /* new_clone will be a pointer to destination */
70 destination
= _hashkit_create(destination
);
72 // Should only happen on allocation failure.
73 if (destination
== NULL
)
78 destination
->base_hash
= source
->base_hash
;
79 destination
->distribution_hash
= source
->distribution_hash
;
80 destination
->flags
= source
->flags
;
85 bool hashkit_compare(const hashkit_st
*first
, const hashkit_st
*second
)
87 if (not first
or not second
)
90 if (first
->base_hash
.function
== second
->base_hash
.function
and
91 first
->base_hash
.context
== second
->base_hash
.context
and
92 first
->distribution_hash
.function
== second
->distribution_hash
.function
and
93 first
->distribution_hash
.context
== second
->distribution_hash
.context
and
94 first
->flags
.is_base_same_distributed
== second
->flags
.is_base_same_distributed
)