skiplistnode 变量“span"是什么意思?在redis.h中是什么意思? [英] What does the skiplistnode variable "span" mean in redis.h?

查看:51
本文介绍了skiplistnode 变量“span"是什么意思?在redis.h中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

redis.h中,skipnode定义如下:

In redis.h, the skipnode is defined as below:

typedef struct zskiplistNode {
    robj *obj;
    double score;
    struct zskiplistNode *backward;
    struct zskiplistLevel {
        struct zskiplistNode *forward;
        unsigned int span;
    } level[];
} zskiplistNode;

var span 是什么意思?这个 var 存储什么?

What does the var span mean? What does this var store?

推荐答案

span 在特定节点存储当前节点和当前级别的节点->转发之间的节点数.span 用于计算跳跃列表中元素的从 1 开始的排名.

span at a particular node stores the number of nodes between the current node and node->forward at the current level. span is used to calculate the 1-based rank of element in the skip list.

例如,考虑以下跳过列表:

For example, consider the following skip list :

考虑头节点.所有级别的跨度将为 1.

Consider the head node. The span at all levels will be 1.

考虑节点 1.在级别 0,跨度为 1,因为如果您跟随前向指针,您将 跨度 1 个元素.在第 1 级,span 为 2,因为如果您跟随前向指针,您将 span 2 个元素(节点 2 和节点 3).

Consider node 1. At level 0, the span is 1, because you will span 1 element if you follow the forward pointer. At level 1, span is 2 because you will span 2 elements (node 2 and node 3) if you follow the forward pointer.

看看t_zet.c中的函数zslGetRank.您可以看到如何根据每个级别的跨度值计算排名.

Take a look at the function zslGetRank in t_zet.c. You can see how the rank is calculated from the value of span at each level.

这篇关于skiplistnode 变量“span"是什么意思?在redis.h中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆