X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/af4e866dbb1455a50d51b3d5f46832f1a36e2080..7eb850ef0e437323e2d84157ddc2e6e82af57bbc:/src/adlist.c?ds=sidebyside diff --git a/src/adlist.c b/src/adlist.c index 015012f5..e48957e3 100644 --- a/src/adlist.c +++ b/src/adlist.c @@ -57,7 +57,7 @@ list *listCreate(void) * This function can't fail. */ void listRelease(list *list) { - unsigned int len; + unsigned long len; listNode *current, *next; current = list->head; @@ -310,7 +310,7 @@ listNode *listSearchKey(list *list, void *key) * and so on. Negative integers are used in order to count * from the tail, -1 is the last element, -2 the penultimante * and so on. If the index is out of range NULL is returned. */ -listNode *listIndex(list *list, int index) { +listNode *listIndex(list *list, long index) { listNode *n; if (index < 0) { @@ -323,3 +323,19 @@ listNode *listIndex(list *list, int index) { } return n; } + +/* Rotate the list removing the tail node and inserting it to the head. */ +void listRotate(list *list) { + listNode *tail = list->tail; + + if (listLength(list) <= 1) return; + + /* Detatch 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; +}