addition: Added basic header and structure
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#ifndef ARRAYLIST_H
|
||||
#define ARRAYLIST_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
void *data;
|
||||
size_t capacity;
|
||||
size_t len;
|
||||
size_t elem_size;
|
||||
} ArrayList;
|
||||
|
||||
typedef struct {
|
||||
ArrayList array;
|
||||
size_t offset;
|
||||
} ArrayListSlice;
|
||||
|
||||
typedef enum {
|
||||
ARRLIST_OK = 0,
|
||||
ARRLIST_OUT_OF_BOUNDS,
|
||||
ARRLIST_BAD_ALLOC,
|
||||
ARRLIST_EMPTY,
|
||||
ARRLIST_NULL_ARG,
|
||||
ARRLIST_INVALID_CAPACITY,
|
||||
ARRLIST_INVALID_ELEM_SIZE,
|
||||
} ArrayListErr;
|
||||
|
||||
typedef struct {
|
||||
bool is_valid;
|
||||
union {
|
||||
ArrayListErr err;
|
||||
ArrayList array;
|
||||
};
|
||||
} ArrayListResult;
|
||||
|
||||
ArrayListResult arraylist_init(size_t capacity, size_t elem_size);
|
||||
ArrayListErr arraylist_destroy(ArrayList *arr);
|
||||
ArrayListErr arraylist_clear(ArrayList *arr);
|
||||
|
||||
size_t arraylist_size(ArrayList *arr);
|
||||
size_t arraylist_capacity(ArrayList *arr);
|
||||
bool arraylist_is_empty(ArrayList *arr);
|
||||
|
||||
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);
|
||||
|
||||
ArrayListErr arraylist_get(ArrayList *arr, size_t index, void *out);
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user