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.
11 static const hashkit_st global_default_hash
= {
13 .function
= hashkit_one_at_a_time
,
17 .is_base_same_distributed
= false,
21 static inline bool _hashkit_init(hashkit_st
*self
)
23 self
->base_hash
= global_default_hash
.base_hash
;
24 self
->distribution_hash
= global_default_hash
.base_hash
;
25 self
->flags
= global_default_hash
.flags
;
30 static inline hashkit_st
*_hashkit_create(hashkit_st
*self
)
34 self
= (hashkit_st
*)malloc(sizeof(hashkit_st
));
40 self
->options
.is_allocated
= true;
44 self
->options
.is_allocated
= false;
50 hashkit_st
*hashkit_create(hashkit_st
*self
)
52 self
= _hashkit_create(self
);
56 if (! _hashkit_init(self
))
65 void hashkit_free(hashkit_st
*self
)
67 if (hashkit_is_allocated(self
))
73 hashkit_st
*hashkit_clone(hashkit_st
*destination
, const hashkit_st
*source
)
77 return hashkit_create(destination
);
80 /* new_clone will be a pointer to destination */
81 destination
= _hashkit_create(destination
);
83 // Should only happen on allocation failure.
84 if (destination
== NULL
)
89 destination
->base_hash
= source
->base_hash
;
90 destination
->distribution_hash
= source
->distribution_hash
;
91 destination
->flags
= source
->flags
;
96 bool hashkit_compare(const hashkit_st
*first
, const hashkit_st
*second
)
98 if (first
->base_hash
.function
== second
->base_hash
.function
&&
99 first
->base_hash
.context
== second
->base_hash
.context
&&
100 first
->distribution_hash
.function
== second
->distribution_hash
.function
&&
101 first
->distribution_hash
.context
== second
->distribution_hash
.context
&&
102 first
->flags
.is_base_same_distributed
== second
->flags
.is_base_same_distributed
)