diff options
Diffstat (limited to 'src/common.cc')
| -rw-r--r-- | src/common.cc | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/common.cc b/src/common.cc index 141b079..df8b9aa 100644 --- a/src/common.cc +++ b/src/common.cc @@ -5,6 +5,7 @@ #include <cstdint> #include <cstdio> #include <cstdlib> +#include <cstring> /* typedefs for common types */ @@ -55,8 +56,9 @@ struct Slice { T* ptr; usize length; - Slice() : ptr(nullptr), length(0) {} + Slice() : Slice(nullptr, 0) {} Slice(T* ptr, usize length) : ptr(ptr), length(length) {} + Slice(const char* str) : ptr((u8*)str), length(strlen(str)) {} T* operator[](usize index) { assert(index < this->length); @@ -86,14 +88,10 @@ struct Link { Link* next; Link* prev; + Link() : Link(nullptr, nullptr) {} Link(Link* next, Link* prev) : next(next), prev(prev) {} }; -struct List { - Link head; - Link tail; -}; - static inline void link_after(Link* prev, Link* nlink) { assert(prev != nullptr); assert(nlink != nullptr); @@ -108,4 +106,19 @@ static inline void link_after(Link* prev, Link* nlink) { next->prev = nlink; } +static inline void link_remove(Link* item) { + assert(item != nullptr); + + Link* prev = item->prev; + Link* next = item->next; + + if(prev != nullptr) + prev->next = next; + + if(next != nullptr) + next->prev = prev; + + item->prev = item->next = nullptr; +} + #endif |
