diff options
| author | Benedict <benedict@0xb8000.de> | 2017-02-02 00:32:26 +0100 |
|---|---|---|
| committer | Benedict <benedict@0xb8000.de> | 2017-02-21 13:00:27 +0100 |
| commit | 1fd84c7dc70a0a6e6d8651fafa50c51dd697ae77 (patch) | |
| tree | af5de3c7952e071c8e27800c41d9f945fa86c9e7 /lib/util/circulardoublelinkedlist.h | |
| parent | 9dcc7348ad53cab8fd9396699de0177bac6729d5 (diff) | |
added random stuff which hasn't beend added because yeah
Diffstat (limited to 'lib/util/circulardoublelinkedlist.h')
| -rw-r--r-- | lib/util/circulardoublelinkedlist.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/util/circulardoublelinkedlist.h b/lib/util/circulardoublelinkedlist.h new file mode 100644 index 0000000..3e5c524 --- /dev/null +++ b/lib/util/circulardoublelinkedlist.h @@ -0,0 +1,54 @@ +#ifndef __CIRCULARLIST__ +#define __CIRCULARLIST__ + +/** + * ciruclar double linked list implementation + * + **/ +#include "util.h" +#include<stdio.h> + +struct circular_list { + struct circular_list *next; + struct circular_list *prev; +}; + +#define CIRCULARLIST_INIT(name) do { (name)->next = (name); (name)->prev = (name); } while(0); + +static int inline __circular_list_insert(struct circular_list *prev, struct circular_list *new, struct circular_list *next) +{ + prev->next = new; + new->prev = prev; + new->next = next; + next->prev = new; +} + +static int inline circular_list_insert_after(struct circular_list *list, struct circular_list *new_elem) +{ + return __circular_list_insert(list, new_elem, list->next); +} + +static int inline circular_list_insert_before(struct circular_list *list, struct circular_list *new_elem) +{ + return __circular_list_insert(list->prev, new_elem, list); +} + +static void inline __circular_list_delete(struct circular_list *prev, struct circular_list *elem, struct circular_list *next) +{ + prev->next = next; + next->prev = prev; + elem->next = elem; + elem->prev = elem; +} +static void inline circular_list_delete(struct circular_list *elem) +{ + __circular_list_delete(elem->prev, elem, elem->next); +} + +#define circular_list_get_prev(elem) (elem)->prev +#define circular_list_get_next(elem) (elem)->next + +#define CIRCULARLIST_FOR_EACH(pos, head) for(pos = head->next; pos != head; pos = pos->next) +#define CONTAINER_OF(ptr, type, member) ((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member))) + +#endif |
