diff options
author | John Anthony <johnanthony@lavabit.com> | 2013-06-16 01:30:16 +0100 |
---|---|---|
committer | John Anthony <johnanthony@lavabit.com> | 2013-06-16 01:30:16 +0100 |
commit | e1502d862fec495b9fdd29131a30050e82c3d390 (patch) | |
tree | acd728146dfac28349891a45a01fd9b90c704d63 | |
parent | 4fe5bbb2df856cdc83a13648e943c27f44c71e48 (diff) | |
download | nyancat-e1502d862fec495b9fdd29131a30050e82c3d390.tar.gz nyancat-e1502d862fec495b9fdd29131a30050e82c3d390.tar.bz2 nyancat-e1502d862fec495b9fdd29131a30050e82c3d390.zip |
Updated list implementation
-rw-r--r-- | list.h | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -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 |