summaryrefslogtreecommitdiff
path: root/adlist.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2009-04-20 23:51:51 +0200
committerantirez <antirez@gmail.com>2009-04-20 23:51:51 +0200
commit6208b3a77644afe5c7c28688cd6d7554a0281953 (patch)
tree964524ab45b932d1ee23612ee740eb2c63c51216 /adlist.c
parent40d224a9e3df29e27e967ec2f1b9b0ecf66df50f (diff)
downloadredis-6208b3a77644afe5c7c28688cd6d7554a0281953.tar.gz
Non blocking replication (finally!). C-side linked lists API improved.
Diffstat (limited to 'adlist.c')
-rw-r--r--adlist.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/adlist.c b/adlist.c
index 1f978c7b2..03bbfb793 100644
--- a/adlist.c
+++ b/adlist.c
@@ -143,7 +143,7 @@ void listDelNode(list *list, listNode *node)
}
/* Returns a list iterator 'iter'. After the initialization every
- * call to listNextElement() will return the next element of the list.
+ * call to listNext() will return the next element of the list.
*
* This function can't fail. */
listIter *listGetIterator(list *list, int direction)
@@ -164,6 +164,17 @@ void listReleaseIterator(listIter *iter) {
zfree(iter);
}
+/* Create an iterator in the list private iterator structure */
+void listRewind(list *list) {
+ list->iter.next = list->head;
+ list->iter.direction = AL_START_HEAD;
+}
+
+void listRewindTail(list *list) {
+ list->iter.next = list->tail;
+ list->iter.direction = AL_START_TAIL;
+}
+
/* Return the next element of an iterator.
* It's valid to remove the currently returned element using
* listDelNode(), but not to remove other elements.
@@ -178,7 +189,7 @@ void listReleaseIterator(listIter *iter) {
* }
*
* */
-listNode *listNextElement(listIter *iter)
+listNode *listNext(listIter *iter)
{
listNode *current = iter->next;
@@ -191,6 +202,11 @@ listNode *listNextElement(listIter *iter)
return current;
}
+/* List Yield just call listNext() against the list private iterator */
+listNode *listYield(list *list) {
+ return listNext(&list->iter);
+}
+
/* Duplicate the whole list. On out of memory NULL is returned.
* On success a copy of the original list is returned.
*
@@ -211,7 +227,7 @@ list *listDup(list *orig)
copy->free = orig->free;
copy->match = orig->match;
iter = listGetIterator(orig, AL_START_HEAD);
- while((node = listNextElement(iter)) != NULL) {
+ while((node = listNext(iter)) != NULL) {
void *value;
if (copy->dup) {
@@ -248,7 +264,7 @@ listNode *listSearchKey(list *list, void *key)
listNode *node;
iter = listGetIterator(list, AL_START_HEAD);
- while((node = listNextElement(iter)) != NULL) {
+ while((node = listNext(iter)) != NULL) {
if (list->match) {
if (list->match(node->value, key)) {
listReleaseIterator(iter);