2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
16 #include "libhashkit/common.h"
18 static inline void _hashkit_init(hashkit_st
*self
) {
19 self
->base_hash
.function
= hashkit_one_at_a_time
;
20 self
->base_hash
.context
= NULL
;
22 self
->distribution_hash
.function
= hashkit_one_at_a_time
;
23 self
->distribution_hash
.context
= NULL
;
25 self
->flags
.is_base_same_distributed
= true;
29 static inline hashkit_st
*_hashkit_create(hashkit_st
*self
) {
31 self
->options
.is_allocated
= false;
33 self
= (hashkit_st
*) calloc(1, sizeof(hashkit_st
));
38 self
->options
.is_allocated
= true;
44 hashkit_st
*hashkit_create(hashkit_st
*self
) {
45 self
= _hashkit_create(self
);
55 void hashkit_free(hashkit_st
*self
) {
56 if (self
and self
->_key
) {
61 if (hashkit_is_allocated(self
)) {
66 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
) {
79 destination
->base_hash
= source
->base_hash
;
80 destination
->distribution_hash
= source
->distribution_hash
;
81 destination
->flags
= source
->flags
;
82 destination
->_key
= aes_clone_key(static_cast<aes_key_t
*>(source
->_key
));
87 bool hashkit_compare(const hashkit_st
*first
, const hashkit_st
*second
) {
88 if (not first
or not second
)
91 if (first
->base_hash
.function
== second
->base_hash
.function
92 and first
->base_hash
.context
== second
->base_hash
.context
93 and first
->distribution_hash
.function
== second
->distribution_hash
.function
94 and first
->distribution_hash
.context
== second
->distribution_hash
.context
95 and first
->flags
.is_base_same_distributed
== second
->flags
.is_base_same_distributed
)