-
Notifications
You must be signed in to change notification settings - Fork 0
/
skiplist.h
51 lines (43 loc) · 1.57 KB
/
skiplist.h
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
51
#include <stdlib.h>
typedef struct skiplistNode {
void *obj;
double score;
struct skiplistNode *backward;
struct skiplistLevel {
struct skiplistNode *forward;
unsigned int span;
}level[];
} skiplistNode;
typedef struct skiplist {
struct skiplistNode *header, *tail;
unsigned long length;
int level;
int maxlevel;
} skiplist;
typedef struct skiplistiter {
skiplist *parent;
skiplistNode *node;
int forward;
double min;
double max;
} skiplistiter;
typedef void (*slDeleteCb) (void *ud, void *obj);
void* slCreateObj(const char* ptr, size_t length);
void slFreeObj(void *obj);
skiplist *slCreate(int maxlevel);
void slFree(skiplist *sl);
void slDump(skiplist *sl);
void slInsert(skiplist *sl, double score, void *obj, int level);
int slDelete(skiplist *sl, double score, void *obj, double change);
unsigned long slLength(skiplist *sl);
unsigned long slDeleteByRank(skiplist *sl, unsigned int start, unsigned int end, slDeleteCb cb, void* ud);
unsigned long slGetRank(skiplist *sl, double score, void *o);
skiplistNode* slGetNodeByRank(skiplistNode* x, int level, unsigned long rank);
skiplistNode *slFirstInRange(skiplist *sl, double min, double max);
skiplistNode *slLastInRange(skiplist *sl, double min, double max);
skiplistiter *slIterNew(skiplist *sl, skiplistNode* head);
skiplistiter* slIterNewFromHead(skiplist *sl);
skiplistiter *slIterNewFromRange(skiplist *sl, double min, double max);
void slIterDel(skiplistiter *it);
int slIterGet(skiplistiter *it, double *score, const void **obj);
int slIterNext(skiplistiter *it);