X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libhashkit%2Fhashkit.h;h=2d8ad3a2d38aafdaa66737a29921227b96deedc7;hb=32837dc24fd35afdc5855b3a7540270991b17611;hp=8b7985ac6050cd6b2684af82f51adcc0a101dd68;hpb=c15e27789bf0ba95ae05e70628a1eb39016159c9;p=m6w6%2Flibmemcached diff --git a/libhashkit/hashkit.h b/libhashkit/hashkit.h index 8b7985ac..2d8ad3a2 100644 --- a/libhashkit/hashkit.h +++ b/libhashkit/hashkit.h @@ -16,17 +16,16 @@ #include #include #include +#include #include #include #include #include #include +#include #include #ifdef __cplusplus - -#include - extern "C" { #endif @@ -63,65 +62,68 @@ struct hashkit_st struct { bool is_allocated:1; } options; +}; #ifdef __cplusplus - hashkit_st() : - base_hash(), - distribution_hash(), - flags(), - options() +#include + +class Hashkit { + +public: + + Hashkit() { - hashkit_create(this); + hashkit_create(&self); } - hashkit_st(const hashkit_st& source) : - base_hash(), - distribution_hash(), - flags(), - options() + Hashkit(const Hashkit& source) { - hashkit_clone(this, &source); + hashkit_clone(&self, &source.self); } - hashkit_st& operator=(const hashkit_st& source) - { - hashkit_clone(this, &source); + Hashkit& operator=(const Hashkit& source) + { + hashkit_free(&self); + hashkit_clone(&self, &source.self); return *this; } - friend bool operator==(const hashkit_st &left, const hashkit_st &right) + friend bool operator==(const Hashkit &left, const Hashkit &right) { - return hashkit_compare(&left, &right); + return hashkit_compare(&left.self, &right.self); } uint32_t digest(std::string& str) { - return hashkit_digest(this, str.c_str(), str.length()); + return hashkit_digest(&self, str.c_str(), str.length()); } uint32_t digest(const char *key, size_t key_length) { - return hashkit_digest(this, key, key_length); + return hashkit_digest(&self, key, key_length); } hashkit_return_t set_function(hashkit_hash_algorithm_t hash_algorithm) { - return hashkit_set_function(this, hash_algorithm); + return hashkit_set_function(&self, hash_algorithm); } hashkit_return_t set_distribution_function(hashkit_hash_algorithm_t hash_algorithm) { - return hashkit_set_function(this, hash_algorithm); + return hashkit_set_function(&self, hash_algorithm); } - ~hashkit_st() + ~Hashkit() { - hashkit_free(this); + hashkit_free(&self); } -#endif +private: + + hashkit_st self; }; +#endif #endif /* HASHKIT_H */