Redis 整型集合相关源码阅读笔记,源码文件 intset.h
& intset.c
。
1. intset 相关数据结构
1
2
3
4
5
|
typedef struct intset {
uint32_t encoding;
uint32_t length;
int8_t contents[];
} intset;
|
2. intset APIs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
/* Create an empty intset. */
intset *intsetNew(void);
/* Insert an integer in the intset, upgrade encoding if necessary.*/
intset *intsetAdd(intset *is, int64_t value, uint8_t *success);
/* Delete integer from intset */
intset *intsetRemove(intset *is, int64_t value, int *success);
/* Determine whether a value belongs to this set */
uint8_t intsetFind(intset *is, int64_t value);
/* Return random member */
int64_t intsetRandom(intset *is);
/* Get the value at the given position. When this position is
* out of range the function returns 0, when in range it returns 1. */
uint8_t intsetGet(intset *is, uint32_t pos, int64_t *value);
/* Return intset length */
uint32_t intsetLen(const intset *is);
/* Return intset blob size in bytes. */
size_t intsetBlobLen(intset *is);
|