2026-04-13 17:55:45 -06:00
|
|
|
#ifndef ARRAYLIST_H
|
|
|
|
|
#define ARRAYLIST_H
|
|
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
2026-04-14 20:30:02 -06:00
|
|
|
typedef struct ArrayList ArrayList;
|
2026-04-13 17:55:45 -06:00
|
|
|
|
2026-04-18 19:22:17 -06:00
|
|
|
// 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.
|
2026-04-13 17:55:45 -06:00
|
|
|
typedef struct {
|
2026-04-14 20:30:02 -06:00
|
|
|
ArrayList *array;
|
2026-04-13 17:55:45 -06:00
|
|
|
size_t offset;
|
|
|
|
|
} ArrayListSlice;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
ARRLIST_OK = 0,
|
|
|
|
|
ARRLIST_OUT_OF_BOUNDS,
|
|
|
|
|
ARRLIST_BAD_ALLOC,
|
2026-04-15 17:17:54 -06:00
|
|
|
ARRLIST_ALLOC_OVERFLOW,
|
2026-04-13 17:55:45 -06:00
|
|
|
ARRLIST_EMPTY,
|
|
|
|
|
ARRLIST_NULL_ARG,
|
|
|
|
|
ARRLIST_INVALID_ELEM_SIZE,
|
2026-04-15 10:01:27 -06:00
|
|
|
ARRLIST_INVALID_CAPACITY,
|
2026-04-13 17:55:45 -06:00
|
|
|
} ArrayListErr;
|
|
|
|
|
|
2026-04-14 20:30:02 -06:00
|
|
|
ArrayList *arraylist_init(size_t capacity, size_t elem_size);
|
2026-04-15 17:17:54 -06:00
|
|
|
ArrayListErr arraylist_destroy(ArrayList **arr);
|
2026-04-13 17:55:45 -06:00
|
|
|
ArrayListErr arraylist_clear(ArrayList *arr);
|
|
|
|
|
|
2026-04-14 20:30:02 -06:00
|
|
|
size_t arraylist_size(const ArrayList *arr);
|
|
|
|
|
size_t arraylist_capacity(const ArrayList *arr);
|
|
|
|
|
bool arraylist_is_empty(const ArrayList *arr);
|
2026-04-13 17:55:45 -06:00
|
|
|
|
|
|
|
|
ArrayListErr arraylist_push_back(ArrayList *arr, void *data);
|
|
|
|
|
ArrayListErr arraylist_insert(ArrayList*arr, size_t index, void *data);
|
|
|
|
|
ArrayListErr arraylist_push_front(ArrayList* arr, void *data);
|
|
|
|
|
|
|
|
|
|
// Here out can be null for not having anything writen
|
|
|
|
|
ArrayListErr arraylist_pop_back(ArrayList *arr, void *out);
|
|
|
|
|
ArrayListErr arraylist_remove_at(ArrayList *arr, size_t index, void *out);
|
|
|
|
|
ArrayListErr arraylist_pop_front(ArrayList *arr, void *out);
|
|
|
|
|
|
2026-04-14 20:30:02 -06:00
|
|
|
ArrayListErr arraylist_get(const ArrayList *arr, size_t index, void *out);
|
2026-04-13 17:55:45 -06:00
|
|
|
ArrayListErr arraylist_set(ArrayList *arr, size_t index, void *data);
|
|
|
|
|
|
|
|
|
|
ArrayListErr arraylist_resize(ArrayList *arr, size_t new_capacity);
|
|
|
|
|
ArrayListErr arraylist_reserve(ArrayList *arr, size_t size_to_reserve);
|
|
|
|
|
|
|
|
|
|
#endif
|