commit 8c978e47e5ef7073b5ae4f297d875e681284c4df
parent d463e46038065c6f5b7fbf9e2cb067970dc02042
Author: Robert Russell <robertrussell.72001@gmail.com>
Date: Sun, 1 Oct 2023 15:15:36 -0700
Add a few list methods
Diffstat:
1 file changed, 26 insertions(+), 0 deletions(-)
diff --git a/inc/list/impl/decls.h b/inc/list/impl/decls.h
@@ -23,6 +23,27 @@ LIST_METHOD(cap)(LIST_T **l) {
return *l ? LIST_HDR(*l)->cap : 0;
}
+static inline UNUSED LIST_T *
+LIST_METHOD(ptr)(LIST_T **l, usize i) {
+ LIST_ASSERT(i < LIST_METHOD(len)(l),
+ STRINGIFY(LIST_METHOD(ptr))" called with i >= len");
+ return &(*l)[i];
+}
+
+static inline UNUSED LIST_T
+LIST_METHOD(get)(LIST_T **l, usize i) {
+ LIST_ASSERT(i < LIST_METHOD(len)(l),
+ STRINGIFY(LIST_METHOD(get))" called with i >= len");
+ return (*l)[i];
+}
+
+static inline UNUSED void
+LIST_METHOD(set)(LIST_T **l, usize i, LIST_T e) {
+ LIST_ASSERT(i < LIST_METHOD(len)(l),
+ STRINGIFY(LIST_METHOD(set))" called with i >= len");
+ (*l)[i] = e;
+}
+
static inline UNUSED int
LIST_METHOD(ins)(LIST_T **l, usize i, LIST_T e) {
return LIST_METHOD(insarr)(l, i, &e, 1);
@@ -68,3 +89,8 @@ LIST_METHOD(trunc)(LIST_T **l, usize n) {
STRINGIFY(LIST_METHOD(trunc))" called with n > len");
if (*l) LIST_HDR(*l)->len = n;
}
+
+static inline UNUSED void
+LIST_METHOD(clr)(LIST_T **l) {
+ LIST_METHOD(trunc)(l, 0);
+}