src/array_list.c

changeset 616
af7d8a29fbc5
parent 615
b52b66dcd44b
child 619
5e58187ac707
     1.1 --- a/src/array_list.c	Thu Nov 17 18:55:14 2022 +0100
     1.2 +++ b/src/array_list.c	Fri Nov 18 22:32:17 2022 +0100
     1.3 @@ -263,12 +263,39 @@
     1.4  
     1.5  }
     1.6  
     1.7 +static bool cx_arl_iter_valid(struct cx_iterator_s const *iter) {
     1.8 +    struct cx_list_s const *list = iter->src_handle;
     1.9 +    return iter->index < list->size;
    1.10 +}
    1.11 +
    1.12 +static void *cx_arl_iter_current(struct cx_iterator_s const *iter) {
    1.13 +    return iter->elem_handle;
    1.14 +}
    1.15 +
    1.16 +static void cx_arl_iter_next(struct cx_iterator_s *iter) {
    1.17 +    if (iter->remove) {
    1.18 +        iter->remove = false;
    1.19 +        cx_arl_remove(iter->src_handle, iter->index);
    1.20 +    } else {
    1.21 +        iter->index++;
    1.22 +        iter->elem_handle = cx_arl_at(iter->src_handle, iter->index);
    1.23 +    }
    1.24 +}
    1.25 +
    1.26  static struct cx_iterator_s cx_arl_iterator(
    1.27          struct cx_list_s *list,
    1.28          size_t index
    1.29  ) {
    1.30      struct cx_iterator_s iter;
    1.31  
    1.32 +    iter.index = index;
    1.33 +    iter.src_handle = list;
    1.34 +    iter.elem_handle = cx_arl_at(list, index);
    1.35 +    iter.valid = cx_arl_iter_valid;
    1.36 +    iter.current = cx_arl_iter_current;
    1.37 +    iter.next = cx_arl_iter_next;
    1.38 +    iter.remove = false;
    1.39 +
    1.40      return iter;
    1.41  }
    1.42  

mercurial