diff mbox

[07/34] ptrlist: add forward iterator

Message ID 20170707134002.49500-8-luc.vanoostenryck@gmail.com (mailing list archive)
State Rejected, archived
Headers show

Commit Message

Luc Van Oostenryck July 7, 2017, 1:39 p.m. UTC
---
 ptrlist.c | 27 +++++++++++++++++++++++++++
 ptrlist.h |  3 +++
 2 files changed, 30 insertions(+)
diff mbox

Patch

diff --git a/ptrlist.c b/ptrlist.c
index 5dc1117c5..5798aec43 100644
--- a/ptrlist.c
+++ b/ptrlist.c
@@ -246,3 +246,30 @@  void __free_ptr_list(struct ptr_list **listp)
 
 	*listp = NULL;
 }
+
+
+int ptr_cur_next(struct ptr_cur *cur)
+{
+	do {
+		struct ptr_list *curl = cur->l;
+
+		if (++cur->n < curl->nr)
+			return 1;
+
+		cur->l = curl->next;
+		cur->n = -1;
+	} while (cur->l != cur->h);
+
+	return 0;
+}
+
+int ptr_cur_beg(struct ptr_cur *cur, struct ptr_list *head)
+{
+	if (!head)
+		return 0;
+
+	cur->h = head;
+	cur->l = head;
+	cur->n = -1;
+	return 1;
+}
diff --git a/ptrlist.h b/ptrlist.h
index d271f9e04..ff38538cb 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -51,6 +51,9 @@  extern void __free_ptr_list(struct ptr_list **);
 extern int ptr_list_size(struct ptr_list *);
 extern int linearize_ptr_list(struct ptr_list *, void **, int);
 
+int ptr_cur_beg(struct ptr_cur *cur, struct ptr_list *head);
+int ptr_cur_next(struct ptr_cur *cur);
+
 /*
  * Hey, who said that you can't do overloading in C?
  *