-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskiplist.h
37 lines (30 loc) · 957 Bytes
/
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
#ifndef __SKIPLIST_H__
#define __SKIPLIST_H__
#include <stdint.h>
#define ZSKIPLIST_MAXLEVEL 32 /* Should be enough for 2^32 elements */
#define ZSKIPLIST_P 0.5 /* Skiplist P = 1/2 */
#define sds char*
#define zmalloc malloc
#define zfree free
#define sdsfree free
#define sdscmp cmpfile
typedef struct zskiplistNode {
sds ele;
int64_t score;
struct zskiplistNode *backward;
struct zskiplistLevel {
struct zskiplistNode *forward;
unsigned int span;
} level[];
} zskiplistNode;
typedef struct zskiplist {
struct zskiplistNode *header, *tail;
unsigned long length;
int level;
} zskiplist;
zskiplist *zslCreate(void);
void zslFree(zskiplist *zsl);
zskiplistNode *zslInsert(zskiplist *zsl, int64_t score, sds ele);
int zslDelete(zskiplist *zsl, int64_t score, sds ele, zskiplistNode **node);
unsigned long zslGetRank(zskiplist *zsl, int64_t score, sds ele);
#endif