diff options
| author | [email protected] <[email protected]> | 2021-11-02 12:34:05 +0800 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2021-11-02 12:34:05 +0800 |
| commit | 31f55f0b88d4af34a8a36497f5e49c69b88b2fbf (patch) | |
| tree | 63515b3ceb361369cdc88ae6db1a808fc80e5b42 /src/nirvana_conhash.h | |
Diffstat (limited to 'src/nirvana_conhash.h')
| -rw-r--r-- | src/nirvana_conhash.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/nirvana_conhash.h b/src/nirvana_conhash.h new file mode 100644 index 0000000..42320b1 --- /dev/null +++ b/src/nirvana_conhash.h @@ -0,0 +1,50 @@ +#ifndef __NVN_CONSISTENT_HASH_H__ +#define __NVN_CONSISTENT_HASH_H__ + +#include <stdint.h> + +#ifndef CONHASH_MAX_POINTS_PER_BUCKET +#define CONHASH_MAX_POINTS_PER_BUCKET 128 +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +enum CONHASH_ERRCODE +{ + CONHASH_OK = 0, + CONHASH_ERR_INVALID_ARGS = -1, + CONHASH_BUCKET_NOT_FOUND = -2, + CONHASH_BUCKET_ALREADY_EXIST=-3, + CONHASH_NO_VALID_BUCKETS=-4, +}; + +struct conhash_bucket +{ + uint32_t bucket_id; + uint32_t point_num; /*should be not more than CONHASH_MAX_POINTS_PER_BUCKET*/ + void* tag; +}; +struct consistent_hash; + +/*API�̲߳���ȫ*/ +struct consistent_hash *conhash_instance_new(const struct conhash_bucket *buckets, uint32_t bucket_num); +void conhash_instance_free(struct consistent_hash *ch); +struct consistent_hash *conhash_instance_copy(struct consistent_hash *ch); + +enum CONHASH_ERRCODE conhash_insert_bucket(struct consistent_hash *ch,const struct conhash_bucket* bucket); +enum CONHASH_ERRCODE conhash_remove_bucket(struct consistent_hash *ch, u_int32_t bucket_id, void (*free_cb)(void *tag, u_int32_t point_num)); +enum CONHASH_ERRCODE conhash_renew_bucket(struct consistent_hash *ch, struct conhash_bucket* bucket); /*����point_num��tag*/ +enum CONHASH_ERRCODE conhash_lookup_bucket(struct consistent_hash *ch, const void* key, int len, struct conhash_bucket *result/*OUT*/); +enum CONHASH_ERRCODE conhash_lookup_bucket_int(struct consistent_hash *ch, u_int64_t randint, struct conhash_bucket* result); + +double conhash_calulate_CVRSMD(struct consistent_hash *p); +u_int32_t conhash_get_bucket_num(struct consistent_hash *ch); + +#ifdef __cplusplus +} +#endif + +#endif |
