Redis source reading-adlist doubly linked list

Source: Internet
Author: User

Redis Source Reading-List part-

Linked list data structure in Adlist.h adlist.c

The Redis list is a doubly linked list, and an iterator is defined internally.

The functions of a doubly linked list are mainly linked list creation, deletion, node insertion, head insertion, tail insertion, nth node, node iteration traversal, linked list replication, linked list rotate, node deletion

typedefstructListNode {structListNode *prev; structListNode *Next; void*value;//defined as void * types, allowing users to use their own data structures on their own} listnode;typedefstructListiter {ListNode*Next; intdirection;} Listiter;typedefstructList {ListNode*Head; ListNode*tail; void* (*dup) (void*PTR);//when copying a linked list, the node copy function    void(* Free)(void*PTR);//Node Release function    int(*match) (void*ptr,void*key);//function to compare node value equalityUnsignedLongLen;} list;/*Functions implemented as macros*/#defineListlength (L) ((l)->len)#defineListfirst (L) ((l)->head)#defineListlast (L) ((l)->tail)#defineListprevnode (n) ((n)->prev)#defineListnextnode (n) ((n)->next)#defineListnodevalue (n) ((n)->value)#defineListsetdupmethod (L,m) ((l)->dup = (m))#defineListsetfreemethod (L,m) ((l)->free = (m))#defineListsetmatchmethod (L,m) ((l)->match = (m))#defineListgetdupmethod (L) ((l)->dup)#defineListgetfree (L) ((l)->free)#defineListgetmatchmethod (L) ((l)->match)/*prototypes*//*Create a linked list*/List*listcreate (void);/*release linked list*/voidListrelease (List *list);/*adding nodes to the head*/List*listaddnodehead (List *list,void*value);/*Add a node at the tail*/List*listaddnodetail (List *list,void*value);/*Insert a node that is value before or after the Old_node*/List*listinsertnode (list *list, ListNode *old_node,void*value,intAfter );/*Insert a node that is value before or after the Old_node*/voidListdelnode (list *list, ListNode *node);/*Create a list iterator that direction represents the direction of the iterator, forward or backward*/Listiter*listgetiterator (List *list,intdirection);/*the iterator moves to the next*/ListNode*listnext (Listiter *iter);/*releasing a list iterator*/voidListreleaseiterator (Listiter *iter);/*copy linked list, return the linked list after replication*/List*listdup (List *orig);/*look for a node with a value of key, and if the match function is defined, use the match function to compare if the key is equal*/ListNode*listsearchkey (List *list,void*key);/*returns the index node of the linked list, with index starting from 0*/ListNode*listindex (List *list,Longindex);/*List iterator reset, point to head node*/voidListrewind (list *list, Listiter *Li);/*List iterator reset, point to tail node*/voidListrewindtail (list *list, Listiter *Li);/*The last node of the list is moved to the front, rotate*/voidListrotate (List *list);/*Directions for Iterators*//*iterator direction: backwards or forwards*/#defineAl_start_head 0#defineAl_start_tail 1

Redis source reading-adlist doubly linked list

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.