addition: set and get, not tested

This commit is contained in:
2026-04-15 07:38:04 -06:00
parent 520dd9d52e
commit 0fc64c2d8d
2 changed files with 32 additions and 1 deletions

View File

@@ -18,7 +18,6 @@ typedef enum {
ARRLIST_BAD_ALLOC, ARRLIST_BAD_ALLOC,
ARRLIST_EMPTY, ARRLIST_EMPTY,
ARRLIST_NULL_ARG, ARRLIST_NULL_ARG,
ARRLIST_INVALID_CAPACITY,
ARRLIST_INVALID_ELEM_SIZE, ARRLIST_INVALID_ELEM_SIZE,
} ArrayListErr; } ArrayListErr;

View File

@@ -286,4 +286,36 @@ ArrayListErr arraylist_remove_at(ArrayList *arr, size_t index, void *out) {
return ARRLIST_OK; return ARRLIST_OK;
} }
ArrayListErr arraylist_get(const ArrayList *arr, size_t index, void *out) {
if (arr == NULL || out == NULL) {
return ARRLIST_NULL_ARG;
}
if (index >= arr->capacity) {
return ARRLIST_OUT_OF_BOUNDS;
}
memcpy(
out,
arr->buffer + (index * arr->elem_size),
arr->elem_size);
return ARRLIST_OK;
}
ArrayListErr arraylist_set(ArrayList *arr, size_t index, void *data) {
if (arr == NULL || data == NULL) {
return ARRLIST_NULL_ARG;
}
if (index >= arr->capacity) {
return ARRLIST_OUT_OF_BOUNDS;
}
memcpy(
arr->buffer + (index * arr->elem_size),
data,
arr->elem_size);
return ARRLIST_OK;
}