当前位置:网站首页>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 三个属性为节点值设置类型特定函数,所以链表可以用于保存各种不同类型的数据
边栏推荐
- 在工作中学习的三个方法
- How to use note taking software flowus and note for interval repetition? Based on formula template
- What are the top ten securities companies in China? Is it safe to open a mobile account?
- 坚持五件事,带你走出迷茫困境!
- MySQL在一个字段中匹配多个值
- Tensorrt notes (4) Modèle de segmentation du raisonnement
- Video data annotation tools and platforms (data annotation company)
- 华为云如何实现实时音视频全球低时延网络架构
- “芯”有灵“蜥”,万人在线!龙蜥社区走进 Intel MeetUp 精彩回顾
- The simplest DIY serial port Bluetooth hardware implementation scheme
猜你喜欢

直播带货app源码搭建中,直播CDN的原理是什么?

攻防演练合集 | 3个阶段,4大要点,蓝队防守全流程纲要解读

Comment Huawei Cloud réalise l'architecture mondiale de réseau audio - vidéo en temps réel à faible latence

Rancher 2.6 new monitoring QuickStart

Rancher 2.6 全新 Monitoring 快速入门

32路电话+2路千兆以太网32路PCM电话光端机支持FXO口FXS语音电话转光纤

【ML】QuantileRegressor

Deveco device tool helps openharmony device development

汉源高科1路非压缩4K-DVI光端机4K高清非压缩DVI转光纤4K-DVI高清视频光端机

quarkus+saas多租户动态数据源切换实现简单完美
随机推荐
Voice data annotation tools and platforms
[Architect (Part 40)] connecting mongodb database developed by server
安卓安全/逆向面试题
Tensorrt notes (4) Modèle de segmentation du raisonnement
【ML】QuantileRegressor
Tensorrt筆記(四)推理分割模型
Tensorrt notes (IV) reasoning segmentation model
quarkus+saas多租户动态数据源切换实现简单完美
Does the inductance have polarity?
Design and implementation of stm32f103zet6 single chip microcomputer dual serial port mutual sending program
After repeated pressure, Apple may significantly increase the price of iphone14
Which securities company has the lowest Commission for opening a mobile account? Is it safe to open an account online now?
At 14:00 today, 12 Chinese scholars started ICLR 2022
互联网奇迹-小米究竟是怎么盈利
CIFAR公开第二阶段泛加拿大AI战略
ESP32-C3入门教程 问题篇⑧——blufi_example.c:244: undefined reference to `esp_ble_gap_start_advertising
Is it difficult to register stocks and open accounts online? Is it safe to open an account online now?
Analysis of LinkedList source code
Surprise! Amd acquires Xilinx with USD 35billion!
The simplest DIY pca9685 steering gear control program based on the integration of upper and lower computers of C # and 51 single chip microcomputer