summaryrefslogtreecommitdiff
path: root/src/nirvana_conhash.h
blob: 42320b149240685d9938070cbbadc7a3fd8c55e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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