implement array list ctor and dtor

Sun, 13 Nov 2022 13:21:48 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 13 Nov 2022 13:21:48 +0100
changeset 607
2d99e978dc34
parent 606
314e9288af2f
child 608
2e93521145ac

implement array list ctor and dtor

also lays out the "glue level" functions

src/array_list.c file | annotate | diff | comparison | revisions
--- a/src/array_list.c	Sat Nov 12 15:56:58 2022 +0100
+++ b/src/array_list.c	Sun Nov 13 13:21:48 2022 +0100
@@ -28,11 +28,124 @@
 
 #include "cx/array_list.h"
 
+/* LOW LEVEL ARRAY LIST FUNCTIONS */
+
+
+
+/* HIGH LEVEL ARRAY LIST FUNCTIONS */
+
+typedef struct {
+    struct cx_list_s base;
+    void *data;
+} cx_array_list;
+
+static void cx_arl_destructor(struct cx_list_s *list) {
+    cx_array_list *arl = (cx_array_list*) list;
+    cxFree(list->allocator, arl->data);
+}
+
+static int cx_arl_add(
+        struct cx_list_s *list,
+        void const *elem
+) {
+    return 1;
+}
+
+static int cx_arl_insert(
+        struct cx_list_s *list,
+        size_t index,
+        void const *elem
+) {
+    return 1;
+}
+
+static int cx_arl_insert_iter(
+        struct cx_iterator_s *iter,
+        void const *elem,
+        int prepend
+) {
+    return 1;
+}
+
+static int cx_arl_remove(
+        struct cx_list_s *list,
+        size_t index
+) {
+    return 1;
+}
+
+static void * cx_arl_at(
+        struct cx_list_s const *list,
+        size_t index
+) {
+    return NULL;
+}
+
+static size_t cx_arl_find(
+        struct cx_list_s const *list,
+        void const *elem
+) {
+    return 0;
+}
+
+static void cx_arl_sort(struct cx_list_s *list) {
+
+}
+
+static int cx_arl_compare(
+        struct cx_list_s const *list,
+        struct cx_list_s const *other
+) {
+
+}
+
+static void cx_arl_reverse(struct cx_list_s *list) {
+
+}
+
+static struct cx_iterator_s cx_arl_iterator(
+        struct cx_list_s *list,
+        size_t index
+) {
+    struct cx_iterator_s iter;
+
+    return iter;
+}
+
+static cx_list_class cx_array_list_class = {
+        cx_arl_destructor,
+        cx_arl_add,
+        cx_arl_insert,
+        cx_arl_insert_iter,
+        cx_arl_remove,
+        cx_arl_at,
+        cx_arl_find,
+        cx_arl_sort,
+        cx_arl_compare,
+        cx_arl_reverse,
+        cx_arl_iterator,
+};
+
 CxList *cxArrayListCreate(
         CxAllocator const *allocator,
         CxListComparator comparator,
         size_t item_size,
         size_t initial_capacity
 ) {
-    return NULL;
+    cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list));
+    if (list == NULL) return NULL;
+
+    list->data = cxCalloc(allocator, initial_capacity, item_size);
+    if (list->data == NULL) {
+        cxFree(allocator, list);
+        return NULL;
+    }
+
+    list->base.cl = &cx_array_list_class;
+    list->base.allocator = allocator;
+    list->base.cmpfunc = comparator;
+    list->base.itemsize = item_size;
+    list->base.capacity = initial_capacity;
+
+    return (CxList *) list;
 }

mercurial