summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Anthony <johnanthony@lavabit.com>2013-06-16 01:30:16 +0100
committerJohn Anthony <johnanthony@lavabit.com>2013-06-16 01:30:16 +0100
commite1502d862fec495b9fdd29131a30050e82c3d390 (patch)
treeacd728146dfac28349891a45a01fd9b90c704d63
parent4fe5bbb2df856cdc83a13648e943c27f44c71e48 (diff)
downloadnyancat-e1502d862fec495b9fdd29131a30050e82c3d390.tar.gz
nyancat-e1502d862fec495b9fdd29131a30050e82c3d390.tar.bz2
nyancat-e1502d862fec495b9fdd29131a30050e82c3d390.zip
Updated list implementation
-rw-r--r--list.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/list.h b/list.h
index 936fbac..bb4473e 100644
--- a/list.h
+++ b/list.h
@@ -18,6 +18,8 @@
* using the generic single-entry routines.
*/
+#include <stdbool.h>
+
struct list_head {
struct list_head *next, *prev;
};
@@ -135,7 +137,7 @@ list_move_tail(struct list_head *list, struct list_head *head) {
* list_empty - tests whether a list is empty
* @head: the list to test.
*/
-static inline int
+static inline bool
list_empty(struct list_head *head) {
return head->next == head;
}
@@ -272,4 +274,19 @@ list_splice_init(struct list_head *list, struct list_head *head) {
&pos->member != (head); \
pos = n, n = list_entry(n->member.prev, typeof(*n), member))
+/**
+ * list_len - count number of elements in the given list
+ * @head: the head for your list
+ * Note: This is a O(1) time operation and should be used sparingly
+ */
+static inline size_t
+list_len(struct list_head *head) {
+ struct list_head *iter;
+ size_t count = 0;
+
+ list_for_each(iter, head)
+ ++count;
+ return count;
+}
+
#endif