Permalink
Browse files

Added ListIterator_newFromNode()

  • Loading branch information...
1 parent be46abc commit ef442396a7105fef421724384f32cdd51ee72641 @tj tj committed Aug 23, 2010
Showing with 16 additions and 4 deletions.
  1. +15 −4 src/iterator.c
  2. +1 −0 src/list.h
View
19 src/iterator.c
@@ -8,18 +8,29 @@
#include "list.h"
/*
- * Allocate a nwe ListIterator. NULL on failure.
+ * Allocate a new ListIterator. NULL on failure.
* Accepts a direction, which may be LIST_HEAD or LIST_TAIL.
*/
ListIterator *
ListIterator_new(List *list, ListDirection direction) {
+ ListNode *node = direction == LIST_HEAD
+ ? list->head
+ : list->tail;
+ return ListIterator_newFromNode(node, direction);
+}
+
+/*
+ * Allocate a new ListIterator with the given start
+ * node. NULL on failure.
+ */
+
+ListIterator *
+ListIterator_newFromNode(ListNode *node, ListDirection direction) {
ListIterator *self;
if (!(self = LIST_MALLOC(sizeof(ListIterator))))
return NULL;
- self->next = direction == LIST_HEAD
- ? list->head
- : list->tail;
+ self->next = node;
self->direction = direction;
return self;
}
View
1 src/list.h
@@ -83,6 +83,7 @@ void List_destroy(List *self);
// List iterator prototypes.
ListIterator *ListIterator_new(List *list, ListDirection direction);
+ListIterator *ListIterator_newFromNode(ListNode *node, ListDirection direction);
ListNode *ListIterator_next(ListIterator *self);
void ListIterator_destroy(ListIterator *self);

0 comments on commit ef44239

Please sign in to comment.