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;
23 static inline hashkit_st
*_hashkit_create(hashkit_st
*self
)
27 self
->options
.is_allocated
= false;
31 self
= (hashkit_st
*)calloc(1, sizeof(hashkit_st
));
37 self
->options
.is_allocated
= true;
43 hashkit_st
*hashkit_create(hashkit_st
*self
)
45 self
= _hashkit_create(self
);
57 void hashkit_free(hashkit_st
*self
)
59 if (self
and self
->_key
)
65 if (hashkit_is_allocated(self
))
71 hashkit_st
*hashkit_clone(hashkit_st
*destination
, const hashkit_st
*source
)
75 return hashkit_create(destination
);
78 /* new_clone will be a pointer to destination */
79 destination
= _hashkit_create(destination
);
81 // Should only happen on allocation failure.
82 if (destination
== NULL
)
87 destination
->base_hash
= source
->base_hash
;
88 destination
->distribution_hash
= source
->distribution_hash
;
89 destination
->flags
= source
->flags
;
90 destination
->_key
= aes_clone_key(static_cast<aes_key_t
*>(source
->_key
));
95 bool hashkit_compare(const hashkit_st
*first
, const hashkit_st
*second
)
97 if (not first
or not second
)
100 if (first
->base_hash
.function
== second
->base_hash
.function
and
101 first
->base_hash
.context
== second
->base_hash
.context
and
102 first
->distribution_hash
.function
== second
->distribution_hash
.function
and
103 first
->distribution_hash
.context
== second
->distribution_hash
.context
and
104 first
->flags
.is_base_same_distributed
== second
->flags
.is_base_same_distributed
)