当前位置:网站首页>Redis 入门-第二篇-数据结构与对象-链表
Redis 入门-第二篇-数据结构与对象-链表
2022-06-23 11:34:00 【tiger’s bytes】
链表在 Redis 中的应用非常广泛,比如列表键的底层实现之一就是链表。当一个列表键包含了数量比较多的元素,或者列表中包含的元素都是比较长的字符串时,Redis 就会使用链表作为列表键的底层实现。
链表和链表节点的实现:
typedef struct listNode {
struct listNode * prev; // 前置节点指针
struct listNode * next; // 后置节点指针
void * value; // 节点值
}listNode;typedef struct list {
listNode * head; // 表头结点
listNode * tail; // 表尾节点
unsigned long len; // 节点数量
void *(*dup)(void *ptr); // 节点复制函数
void (*free)(void *ptr); // 节点释放函数
void (*match)(void *ptr, void *key); // 节点值对比函数
}list;
Redis 的链表实现可以总结为:
- 双端:链表节点有 prev 和 next 指针,获取某个节点前置节点和后置节点时间复杂度为 O(1)
- 无环:表头节点的 prev 和表尾节点的 next 指针都指向 NULL,对链表的访问以 NULL 为终点
- 带表头和表尾指针:通过 list 的 head 和 tail 属性获取表头和表尾节点的时间复杂度为 O(1)
- 带有链表长度计数器:通过 list 的 len 属性,获取链表节点数量的时间复杂度为 O(1)
- 多态:链表使用 void * 指针来保存节点值,并且可以通过 list 结构的 dup、free、match 三个属性为节点值设置类型特定函数,所以链表可以用于保存各种不同类型的数据
边栏推荐
- 华为云如何实现实时音视频全球低时延网络架构
- 电感有极性吗?
- 十大劵商如何开户?在线开户安全么?
- 我在佛山,到哪里开户比较好?手机开户安全么?
- Vone news | wanglian technology empowers the public to enjoy the self-organization management of the chain network, creating an enterprise level alliance Dao
- 强化责任意识和底线思维 全力筑牢抗洪抢险“安全堤”
- EasyGBS如何解决对讲功能使用异常?
- 你真的理解LDO的輸出電容嗎!?
- What are the top ten securities companies in China? Is it safe to open a mobile account?
- 过采样系列一:采样定理与过采样率
猜你喜欢

Gradienttape of tensorflow2

【云原生&微服务八】Ribbon负载均衡策略之WeightedResponseTimeRule源码剖析(响应时间加权)

4路电话+1路千兆以太网4路PCM电话光端机
![[golden section] and [Fibonacci series]](/img/6a/69dba98951d37cdb4793c3d49cbb1a.png)
[golden section] and [Fibonacci series]

Design and implementation of distribution network and Internet connection scheme for esp32-cam high cost performance temperature and humidity monitoring system

Vone news | wanglian technology empowers the public to enjoy the self-organization management of the chain network, creating an enterprise level alliance Dao

quarkus+saas多租户动态数据源切换实现简单完美

How Huawei cloud implements a global low latency network architecture for real-time audio and video

16路HD-SDI光端机多路HD-SDI高清视频光端机16路3G-SDI高清音视频光端机

A child process is created in the program, and then the parent and child processes run independently. The parent process reads lowercase letters on the standard input device and writes them to the pip
随机推荐
过采样系列二:傅里叶变换与信噪比
Analysis of LinkedList source code
Openharmony application development [01]
今天14:00 | 12位一作华人学者开启 ICLR 2022
Tensorrt笔记(四)推理分割模型
如何使用笔记软件 FlowUs、Notion 进行间隔重复?基于公式模版
華為雲如何實現實時音視頻全球低時延網絡架構
"Core" has spirit "lizard", ten thousand people are online! Dragon Dragon community walks into Intel meetup wonderful review
Necessary software for automation or electrical specialty
手机开户哪个证券公司佣金最低?现在网上开户安全么?
Daily question 7-1652 Defuse the bomb
汉源高科1路非压缩4K-DVI光端机4K高清非压缩DVI转光纤4K-DVI高清视频光端机
过采样系列一:采样定理与过采样率
[golden section] and [Fibonacci series]
基本数据类型和对应的包装类
使用tensorflow2创建神经网络
【云原生&微服务八】Ribbon负载均衡策略之WeightedResponseTimeRule源码剖析(响应时间加权)
汉源高科1路千兆光口转4路千兆以太网电口千兆1光4电光纤收发器
[use of Matlab graphical user interface controls]
Whether Changan Lumin has the ability to become a broken product in the micro electricity market