diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-03 23:35:27 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-03 23:35:27 +0100 |
commit | 82c63a1f2422c3f4b1599bcb889e3ed1fc4f6ed0 (patch) | |
tree | c433dbc1621492794c6d9993f4939aa68c20940b /linked_list.h | |
parent | Loads of memmory fixes, among other. (diff) | |
download | calp-82c63a1f2422c3f4b1599bcb889e3ed1fc4f6ed0.tar.gz calp-82c63a1f2422c3f4b1599bcb889e3ed1fc4f6ed0.tar.xz |
Add linked list generic type.
Diffstat (limited to '')
-rw-r--r-- | linked_list.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/linked_list.h b/linked_list.h new file mode 100644 index 00000000..666524be --- /dev/null +++ b/linked_list.h @@ -0,0 +1,38 @@ +#ifndef LINKED_LIST_H +#define LINKED_LIST_H + +#include "macro.h" + +#define LLIST(T) TP(llist__, T) +#define LINK(T) TP(llist_link__, T) + +#define LLIST_INIT(T) CONSTRUCTOR_GEN(llist, T, 0); +#define LLIST_FREE(T) TP(llist_free__, T) +#define LLIST_CONS(T) TP(llist_cons__, T) + +#endif /* LINKED_LIST_H */ +#ifdef TYPE + +typedef struct LINK(TYPE) { + struct LINK(TYPE)* before; + struct LINK(TYPE)* after; + TYPE* value; +} LINK(TYPE); + +typedef struct { + LINK(TYPE)* head; + LINK(TYPE)* tail; + LINK(TYPE)* cur; + int length; +} LLIST(TYPE); + +int CONSTRUCTOR_DECL ( LLIST(TYPE) ); +int LLIST_FREE(TYPE) ( LLIST(TYPE)* ); + +int CONSTRUCTOR_DECL ( LINK(TYPE) ); + +int LLIST_CONS(TYPE) ( LLIST(TYPE)* lst, TYPE* val); + +int DEEP_COPY(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* src ); + +#endif /* TYPE */ |