Jun

Results 164 comments of Jun

# Layer 1 第1层是Python基于第0层简单包装而成的。`PyMem_` API接口提供统一的raw memory管理接口。 我们先看下`PyMem_Raw`前缀的函数族,定义在`Object/obmalloc.c`中: ```c void * PyMem_RawMalloc(size_t size) { if (size > (size_t)PY_SSIZE_T_MAX) return NULL; return _PyMem_Raw.malloc(_PyMem_Raw.ctx, size); } void * PyMem_RawCalloc(size_t nelem, size_t elsize) {...

# Layer 2 第2层的`PyObject_`前缀的函数族定义如下: ```c void * PyObject_Malloc(size_t size) { /* see PyMem_RawMalloc() */ if (size > (size_t)PY_SSIZE_T_MAX) return NULL; return _PyObject.malloc(_PyObject.ctx, size); } void * PyObject_Calloc(size_t nelem, size_t elsize)...

## 创建 ```c // 5.0.3/src/server.h #define ZSKIPLIST_MAXLEVEL 64 /* Should be enough for 2^64 elements */ // 5.0.3/src/t_zset.c /* Create a new skiplist. */ zskiplist *zslCreate(void) { int j; zskiplist...

## 查找 Redis 跳跃列表的实现有没有提供直接查询节点的函数。 可以通过节点排位计算和排位查找来理解: ### 节点排位计算 ```c // 5.0.3/src/t_zset.c /* Find the rank for an element by both score and key. * Returns 0 when the element cannot be...

## 插入 ```c // 5.0.3/src/t_zset.c /* Insert a new node in the skiplist. Assumes the element does not already * exist (up to the caller to enforce that). The skiplist...

## 删除 ```c // 5.0.3/src/t_zset.c /* Delete an element with matching score/element from the skiplist. * The function returns 1 if the node was found and deleted, otherwise * 0...

## 更新 ```c /* Update the score of an elmenent inside the sorted set skiplist. * Note that the element must exist and must match 'score'. * This function does...

@dvoprm 没太明白你的问题是什么

@dvoprm zslGetRank 确实没有检查 score,zslGetRank 是内部只在 zsetRank 被调用的函数,会通过 dict 来查找字符串的 score,不过理论上还是应该检查的

### 节点 一个压缩列表包括多个节点(entry),每个节点可以保存一个字符数组或者整数,节点大小不定。 节点内存表示: ![image](https://user-images.githubusercontent.com/8097526/80796594-2f3ad800-8bd2-11ea-897a-cf9bed5ee6e7.png) 节点包含了两个元数据: - prevlen: 前一个节点的长度 - encoding: 节点数据的编码类型信息 prevlen 以字节为单位,当反向遍历压缩列表时,可以定位到前一个节点的起始位置。prevlen 的大小可以是 1 字节或者 5 字节: 1. 如果前一节点的长度小于 254 字节,那么 prevlen 的大小为 1 字节。 2. 如果前一节点的长度大于等于 254...