addition: next and peek, need testing

This commit is contained in:
2026-04-23 08:47:45 -06:00
parent 94dc859a8f
commit e8aaa006de
2 changed files with 52 additions and 6 deletions

View File

@@ -506,3 +506,50 @@ ArrayListErr arrayslice_destroy(ArraySlice **slice) {
return ARRLIST_OK;
}
bool arrayslice_is_valid(const ArraySlice *slice) {
if (slice == NULL) {
return false;
}
return slice->current != slice->end;
}
size_t arrayslice_size(const ArraySlice *slice) {
if (slice == NULL) {
return 0;
}
return slice->end - slice->start;
}
ArrayListErr arrayslice_peek(const ArraySlice *slice, void *out) {
if (slice == NULL || out == NULL) {
return ARRLIST_NULL_ARG;
}
if (slice->current == slice->end) {
return ARRLIST_INVALID_SLICE;
}
arraylist_get(slice->arr, slice->current, out);
return ARRLIST_OK;
}
ArrayListErr arrayslice_next(ArraySlice *slice, void *out) {
// HERE, it makes sense that you want to advance to the next
// without actually getting the value so it's good
if (slice == NULL) {
return ARRLIST_NULL_ARG;
}
if (slice->current == slice->end) {
return ARRLIST_INVALID_SLICE;
}
arraylist_get(slice->arr, slice->current, out);
slice->current++;
return ARRLIST_OK;
}