From 4b2389ad627e7093af33031c040920bcc23d7c38 Mon Sep 17 00:00:00 2001 From: laentropia Date: Sun, 19 Apr 2026 12:32:11 -0600 Subject: [PATCH] feature: Added structure for ArrayListSlices --- include/arraylist.h | 11 ++--------- src/arraylist.c | 8 ++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/arraylist.h b/include/arraylist.h index 3fbf677..e461e3a 100644 --- a/include/arraylist.h +++ b/include/arraylist.h @@ -7,15 +7,7 @@ typedef struct ArrayList ArrayList; -// FUCK, i forgot one of the main reasons i wanted to -// implement arrays myself was because i needed -// array slices or something like this and i completely -// forgot, fuck, guess i will implement it once i get -// the tests done. -typedef struct { - ArrayList *array; - size_t offset; -} ArrayListSlice; +typedef struct ArrayListSlice ArrayListSlice; typedef enum { ARRLIST_OK = 0, @@ -26,6 +18,7 @@ typedef enum { ARRLIST_NULL_ARG, ARRLIST_INVALID_ELEM_SIZE, ARRLIST_INVALID_CAPACITY, + ARRLIST_IS_BORROWED, } ArrayListErr; ArrayList *arraylist_init(size_t capacity, size_t elem_size); diff --git a/src/arraylist.c b/src/arraylist.c index f29e7b0..b7300ad 100644 --- a/src/arraylist.c +++ b/src/arraylist.c @@ -11,6 +11,14 @@ struct ArrayList{ size_t elem_size; }; +struct ArrayListSlice { + ArrayList *arr; + size_t start; + size_t end; + size_t current; + bool is_safe; +}; + // Grow and shrink factor is 2, 1.5 might give different results i guess // but i'm basing myself in that Rust implementation of array does use // 2 as the factor so i guess is good :)