[PATCH 09/34] ptrlist: add backward iterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 ptrlist.c | 32 ++++++++++++++++++++++++++++++++
 ptrlist.h |  2 ++
 2 files changed, 34 insertions(+)

diff --git a/ptrlist.c b/ptrlist.c
index 5798aec43..031c53262 100644
--- a/ptrlist.c
+++ b/ptrlist.c
@@ -273,3 +273,35 @@ int ptr_cur_beg(struct ptr_cur *cur, struct ptr_list *head)
 	cur->n = -1;
 	return 1;
 }
+
+int ptr_cur_prev(struct ptr_cur *cur)
+{
+	do {
+		struct ptr_list *curl = cur->l;
+
+		if (--cur->n >= 0)
+			return 1;
+
+		if (curl == cur->h)
+			break;
+		curl = curl->prev;
+		cur->l = curl;
+		cur->n = curl->nr;
+	} while (1);
+
+	return 0;
+}
+
+int ptr_cur_end(struct ptr_cur *cur, struct ptr_list *head)
+{
+	struct ptr_list *prev;
+
+	if (!head)
+		return 0;
+
+	prev = head->prev;
+	cur->h = head;
+	cur->l = prev;
+	cur->n = prev->nr;
+	return 1;
+}
diff --git a/ptrlist.h b/ptrlist.h
index b46967c58..883cca952 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -53,6 +53,8 @@ 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);
+int ptr_cur_end(struct ptr_cur *cur, struct ptr_list *head);
+int ptr_cur_prev(struct ptr_cur *cur);
 
 /*
  * Hey, who said that you can't do overloading in C?
-- 
2.13.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux