addition: set and get, not tested
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user