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

@@ -286,4 +286,36 @@ ArrayListErr arraylist_remove_at(ArrayList *arr, size_t index, void *out) {
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;
}