This is a tiny library containing a dynamic array implementation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
barray/include/barray.h

35 lines
1.1 KiB

#ifndef _BARRAY_H
#define _BARRAY_H
#include <stddef.h>
#include <stdint.h>
typedef struct {
void* ptr;
size_t len;
size_t cap;
size_t elem_size;
} BArray;
typedef enum {
BARRAY_NO_ERR,
BARRAY_ERR_ALLOC_ERR,
BARRAY_ERR_OUT_OF_BOUNDS,
BARRAY_ERR_SIZE_OVERFLOW,
BARRAY_ERR_NULL,
BARRAY_ERR_ELEM_SIZE_ZERO
} BArray_ErrCode;
BArray barray_create(size_t elem_size, size_t initial_cap, BArray_ErrCode* errc);
void barray_grow(BArray* array, BArray_ErrCode* errc);
void barray_grow_to(BArray* array, size_t new_cap, BArray_ErrCode* errc);
void barray_shrink_to_fit(BArray* array, BArray_ErrCode* errc);
void barray_force_shrink(BArray* array, size_t new_cap, BArray_ErrCode* errc);
void* barray_get(BArray* array, size_t ix, BArray_ErrCode* errc);
void barray_set(BArray* array, size_t ix, void* value, BArray_ErrCode* errc);
void barray_put(BArray* array, size_t ix, void* value, BArray_ErrCode* errc);
void barray_append(BArray* array, void* value, BArray_ErrCode* errc);
void barray_remove(BArray* array, size_t ix, BArray_ErrCode* errc);
void barray_clear(BArray* array, BArray_ErrCode* errc);
#endif /* _BARRAY_H */