zoukankan      html  css  js  c++  java
  • redis学习笔记(二): adlist

    adlist是redis中自己实现的一个双向链表,同时也提供迭代器操作。先上结构

    typedef struct listNode {
    struct listNode *prev;
    struct listNode *next;
    void *value;
    } listNode;
    
    typedef struct listIter {
    listNode *next;
    int direction;
    } listIter;
    
    typedef struct list {
    listNode *head;
    listNode *tail;
    void *(*dup)(void *ptr);
    void (*free)(void *ptr);
    int (*match)(void *ptr, void *key);
    unsigned long len;
    } list;

    对于list结构,可以看做是链表的头节点。相应地,内部提供了插入、删除、(利用迭代器)复制的操作。

    只是它的rotate操作有些不懂,按照字面意思,rotate应该是是链表上所有元素倒序,但是它的实现上只是把tail节点放到head节点前面

    void listRotate(list *list) {
    listNode *tail = list->tail;
    
    if (listLength(list) <= 1) return;
    
    /* Detach current tail */
    list->tail = tail->prev;
    list->tail->next = NULL;
    /* Move it as head */
    list->head->prev = tail;
    tail->prev = NULL;
    tail->next = list->head;
    list->head = tail;
    }
  • 相关阅读:
    java后端
    2017-12-11
    二叉树与分治法整理
    javaweb
    安装docker
    爬虫
    lintcode
    DEEPlearning
    剑指offer_by牛客网
    DFS
  • 原文地址:https://www.cnblogs.com/flypighhblog/p/7748229.html
Copyright © 2011-2022 走看看