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 bool _hashkit_init(hashkit_st
*self
)
13 self
->base_hash
.function
= hashkit_one_at_a_time
;
14 self
->base_hash
.context
= NULL
;
15 self
->distribution_hash
.function
= self
->base_hash
.function
;
16 self
->flags
.is_base_same_distributed
= false;
21 static inline hashkit_st
*_hashkit_create(hashkit_st
*self
)
25 self
= (hashkit_st
*)malloc(sizeof(hashkit_st
));
31 self
->options
.is_allocated
= true;
35 self
->options
.is_allocated
= false;
41 hashkit_st
*hashkit_create(hashkit_st
*self
)
43 self
= _hashkit_create(self
);
47 if (! _hashkit_init(self
))
56 void hashkit_free(hashkit_st
*self
)
58 if (hashkit_is_allocated(self
))
64 hashkit_st
*hashkit_clone(hashkit_st
*destination
, const hashkit_st
*source
)
68 return hashkit_create(destination
);
71 /* new_clone will be a pointer to destination */
72 destination
= _hashkit_create(destination
);
74 // Should only happen on allocation failure.
75 if (destination
== NULL
)
80 destination
->base_hash
= source
->base_hash
;
81 destination
->distribution_hash
= source
->distribution_hash
;
82 destination
->flags
= source
->flags
;
87 bool hashkit_compare(const hashkit_st
*first
, const hashkit_st
*second
)
89 if (first
->base_hash
.function
== second
->base_hash
.function
&&
90 first
->base_hash
.context
== second
->base_hash
.context
&&
91 first
->distribution_hash
.function
== second
->distribution_hash
.function
&&
92 first
->distribution_hash
.context
== second
->distribution_hash
.context
&&
93 first
->flags
.is_base_same_distributed
== second
->flags
.is_base_same_distributed
)