addition: next and peek, need testing
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user