simplify iterator structures

Thu, 23 May 2024 19:29:14 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 23 May 2024 19:29:14 +0200
changeset 853
d4baf4dd55c3
parent 852
16e2a3391e88
child 854
fe0d69d72bcd

simplify iterator structures

docs/src/features.md file | annotate | diff | comparison | revisions
src/array_list.c file | annotate | diff | comparison | revisions
src/cx/iterator.h file | annotate | diff | comparison | revisions
src/cx/list.h file | annotate | diff | comparison | revisions
src/cx/map.h file | annotate | diff | comparison | revisions
src/cx/tree.h file | annotate | diff | comparison | revisions
src/hash_map.c file | annotate | diff | comparison | revisions
src/iterator.c file | annotate | diff | comparison | revisions
src/linked_list.c file | annotate | diff | comparison | revisions
src/list.c file | annotate | diff | comparison | revisions
src/map.c file | annotate | diff | comparison | revisions
src/tree.c file | annotate | diff | comparison | revisions
tests/test_hash_map.c file | annotate | diff | comparison | revisions
tests/test_iterator.c file | annotate | diff | comparison | revisions
tests/test_list.c file | annotate | diff | comparison | revisions
tests/test_tree.c file | annotate | diff | comparison | revisions
     1.1 --- a/docs/src/features.md	Thu May 23 18:21:36 2024 +0200
     1.2 +++ b/docs/src/features.md	Thu May 23 19:29:14 2024 +0200
     1.3 @@ -186,15 +186,17 @@
     1.4  Sometimes you only need the `index` (for example when iterating over simple lists), and other times you will need the
     1.5  `slot` and `kv_data` fields (for example when iterating over maps).
     1.6  
     1.7 +If the predefined fields are insufficient for your use case, you can alternatively create your own iterator structure
     1.8 +and place the `CX_ITERATOR_BASE` macro inside.
     1.9 +
    1.10  Usually an iterator is not mutating the collection it is iterating over.
    1.11  In some programming languages it is even disallowed to change the collection while iterating with foreach.
    1.12  But sometimes it is desirable to remove an element from the collection while iterating over it.
    1.13 -This is, what the `CxMutIterator` is for.
    1.14 +For this purpose, most collections allow the creation of a _mutating_ iterator.
    1.15  The only differences are, that the `mutating` flag is `true` and the `src_handle` is not const.
    1.16  On mutating iterators it is allowed to call the `cxFlagForRemoval()` function, which instructs the iterator to remove
    1.17  the current element from the collection on the next call to `cxIteratorNext()` and clear the flag afterward.
    1.18 -If you are implementing your own iterator, it is up to you to implement this behavior in your `next` method, or
    1.19 -make the implementation of the `flag_removal` method always return `false`.
    1.20 +If you are implementing your own iterator, it is up to you to implement this behavior.
    1.21  
    1.22  ## Collection
    1.23  
     2.1 --- a/src/array_list.c	Thu May 23 18:21:36 2024 +0200
     2.2 +++ b/src/array_list.c	Thu May 23 19:29:14 2024 +0200
     2.3 @@ -273,11 +273,11 @@
     2.4  }
     2.5  
     2.6  static int cx_arl_insert_iter(
     2.7 -        struct cx_mut_iterator_s *iter,
     2.8 +        struct cx_iterator_s *iter,
     2.9          void const *elem,
    2.10          int prepend
    2.11  ) {
    2.12 -    struct cx_list_s *list = iter->src_handle;
    2.13 +    struct cx_list_s *list = iter->src_handle.m;
    2.14      if (iter->index < list->size) {
    2.15          int result = cx_arl_insert_element(
    2.16                  list,
    2.17 @@ -453,7 +453,7 @@
    2.18  
    2.19  static bool cx_arl_iter_valid(void const *it) {
    2.20      struct cx_iterator_s const *iter = it;
    2.21 -    struct cx_list_s const *list = iter->src_handle;
    2.22 +    struct cx_list_s const *list = iter->src_handle.c;
    2.23      return iter->index < list->size;
    2.24  }
    2.25  
    2.26 @@ -463,27 +463,24 @@
    2.27  }
    2.28  
    2.29  static void cx_arl_iter_next(void *it) {
    2.30 -    struct cx_iterator_base_s *itbase = it;
    2.31 -    if (itbase->remove) {
    2.32 -        struct cx_mut_iterator_s *iter = it;
    2.33 -        itbase->remove = false;
    2.34 -        cx_arl_remove(iter->src_handle, iter->index);
    2.35 +    struct cx_iterator_s *iter = it;
    2.36 +    if (iter->remove) {
    2.37 +        iter->remove = false;
    2.38 +        cx_arl_remove(iter->src_handle.m, iter->index);
    2.39      } else {
    2.40 -        struct cx_iterator_s *iter = it;
    2.41          iter->index++;
    2.42          iter->elem_handle =
    2.43                  ((char *) iter->elem_handle)
    2.44 -                + ((struct cx_list_s const *) iter->src_handle)->item_size;
    2.45 +                + ((struct cx_list_s const *) iter->src_handle.c)->item_size;
    2.46      }
    2.47  }
    2.48  
    2.49  static void cx_arl_iter_prev(void *it) {
    2.50 -    struct cx_iterator_base_s *itbase = it;
    2.51 -    struct cx_mut_iterator_s *iter = it;
    2.52 -    cx_array_list *const list = iter->src_handle;
    2.53 -    if (itbase->remove) {
    2.54 -        itbase->remove = false;
    2.55 -        cx_arl_remove(iter->src_handle, iter->index);
    2.56 +    struct cx_iterator_s *iter = it;
    2.57 +    cx_array_list const* list = iter->src_handle.c;
    2.58 +    if (iter->remove) {
    2.59 +        iter->remove = false;
    2.60 +        cx_arl_remove(iter->src_handle.m, iter->index);
    2.61      }
    2.62      iter->index--;
    2.63      if (iter->index < list->base.size) {
    2.64 @@ -501,15 +498,15 @@
    2.65      struct cx_iterator_s iter;
    2.66  
    2.67      iter.index = index;
    2.68 -    iter.src_handle = list;
    2.69 +    iter.src_handle.c = list;
    2.70      iter.elem_handle = cx_arl_at(list, index);
    2.71      iter.elem_size = list->item_size;
    2.72      iter.elem_count = list->size;
    2.73 -    iter.base.valid = cx_arl_iter_valid;
    2.74 -    iter.base.current = cx_arl_iter_current;
    2.75 -    iter.base.next = backwards ? cx_arl_iter_prev : cx_arl_iter_next;
    2.76 -    iter.base.remove = false;
    2.77 -    iter.base.mutating = false;
    2.78 +    iter.valid = cx_arl_iter_valid;
    2.79 +    iter.current = cx_arl_iter_current;
    2.80 +    iter.next = backwards ? cx_arl_iter_prev : cx_arl_iter_next;
    2.81 +    iter.remove = false;
    2.82 +    iter.mutating = false;
    2.83  
    2.84      return iter;
    2.85  }
     3.1 --- a/src/cx/iterator.h	Thu May 23 18:21:36 2024 +0200
     3.2 +++ b/src/cx/iterator.h	Thu May 23 19:29:14 2024 +0200
     3.3 @@ -38,68 +38,64 @@
     3.4  
     3.5  #include "common.h"
     3.6  
     3.7 +#define CX_ITERATOR_BASE \
     3.8 +    /** \
     3.9 +     * True iff the iterator points to valid data. \
    3.10 +     */ \
    3.11 +    __attribute__ ((__nonnull__)) \
    3.12 +    bool (*valid)(void const *); \
    3.13 +    /** \
    3.14 +     * Returns a pointer to the current element. \
    3.15 +     * \
    3.16 +     * When valid returns false, the behavior of this function is undefined. \
    3.17 +     */ \
    3.18 +    __attribute__ ((__nonnull__)) \
    3.19 +    void *(*current)(void const *); \
    3.20 +    /** \
    3.21 +     * Original implementation in case the function needs to be wrapped. \
    3.22 +     */ \
    3.23 +    __attribute__ ((__nonnull__)) \
    3.24 +    void *(*current_impl)(void const *); \
    3.25 +    /** \
    3.26 +     * Advances the iterator. \
    3.27 +     * \
    3.28 +     * When valid returns false, the behavior of this function is undefined. \
    3.29 +     */ \
    3.30 +    __attribute__ ((__nonnull__)) \
    3.31 +    void (*next)(void *); \
    3.32 +    /** \
    3.33 +     * Indicates whether this iterator may remove elements. \
    3.34 +     */ \
    3.35 +    bool mutating; \
    3.36 +    /** \
    3.37 +     * Internal flag for removing the current element when advancing. \
    3.38 +     */ \
    3.39 +    bool remove;
    3.40 +
    3.41  /**
    3.42 - * The base of mutating and non-mutating iterators.
    3.43 + * Internal iterator struct - use CxIterator.
    3.44   */
    3.45 -struct cx_iterator_base_s {
    3.46 -    /**
    3.47 -     * True iff the iterator points to valid data.
    3.48 -     */
    3.49 -    __attribute__ ((__nonnull__))
    3.50 -    bool (*valid)(void const *);
    3.51 +struct cx_iterator_s {
    3.52 +    CX_ITERATOR_BASE
    3.53  
    3.54      /**
    3.55 -     * Returns a pointer to the current element.
    3.56 -     *
    3.57 -     * When valid returns false, the behavior of this function is undefined.
    3.58 -     */
    3.59 -    __attribute__ ((__nonnull__))
    3.60 -    void *(*current)(void const *);
    3.61 -
    3.62 -    /**
    3.63 -     * Original implementation in case the function needs to be wrapped.
    3.64 -     */
    3.65 -    __attribute__ ((__nonnull__))
    3.66 -    void *(*current_impl)(void const *);
    3.67 -
    3.68 -    /**
    3.69 -     * Advances the iterator.
    3.70 -     *
    3.71 -     * When valid returns false, the behavior of this function is undefined.
    3.72 -     */
    3.73 -    __attribute__ ((__nonnull__))
    3.74 -    void (*next)(void *);
    3.75 -
    3.76 -    /**
    3.77 -     * Indicates whether this iterator may remove elements.
    3.78 -     */
    3.79 -    bool mutating;
    3.80 -
    3.81 -    /**
    3.82 -     * Internal flag for removing the current element when advancing.
    3.83 -     */
    3.84 -    bool remove;
    3.85 -};
    3.86 -
    3.87 -/**
    3.88 - * Internal iterator struct - use CxMutIterator.
    3.89 - */
    3.90 -struct cx_mut_iterator_s {
    3.91 -
    3.92 -    /**
    3.93 -     * The base properties of this iterator.
    3.94 -     */
    3.95 -    struct cx_iterator_base_s base;
    3.96 -
    3.97 -    /**
    3.98 -     * Handle for the current element, if required.
    3.99 +     * Handle for the current element.
   3.100       */
   3.101      void *elem_handle;
   3.102  
   3.103      /**
   3.104       * Handle for the source collection, if any.
   3.105       */
   3.106 -    void *src_handle;
   3.107 +    union {
   3.108 +        /**
   3.109 +         * Access for mutating iterators.
   3.110 +         */
   3.111 +        void *m;
   3.112 +        /**
   3.113 +         * Access for normal iterators.
   3.114 +         */
   3.115 +        void const *c;
   3.116 +    } src_handle;
   3.117  
   3.118      /**
   3.119       * Field for storing a key-value pair.
   3.120 @@ -141,91 +137,15 @@
   3.121  };
   3.122  
   3.123  /**
   3.124 - * Mutating iterator value type.
   3.125 + * Iterator type.
   3.126   *
   3.127 - * An iterator points to a certain element in an (possibly unbounded) chain of elements.
   3.128 - * Iterators that are based on collections (which have a defined "first" element), are supposed
   3.129 - * to be "position-aware", which means that they keep track of the current index within the collection.
   3.130 - *
   3.131 - * @note Objects that are pointed to by an iterator are mutable through that iterator. However, if the
   3.132 - * iterator is based on a collection and the underlying collection is mutated by other means than this iterator
   3.133 - * (e.g. elements added or removed), the iterator becomes invalid (regardless of what cxIteratorValid() returns)
   3.134 - * and MUST be re-obtained from the collection.
   3.135 - *
   3.136 - * @see CxIterator
   3.137 - */
   3.138 -typedef struct cx_mut_iterator_s CxMutIterator;
   3.139 -
   3.140 -/**
   3.141 - * Internal iterator struct - use CxIterator.
   3.142 - */
   3.143 -struct cx_iterator_s {
   3.144 -
   3.145 -    /**
   3.146 -     * The base properties of this iterator.
   3.147 -     */
   3.148 -    struct cx_iterator_base_s base;
   3.149 -
   3.150 -    /**
   3.151 -     * Handle for the current element, if required.
   3.152 -     */
   3.153 -    void *elem_handle;
   3.154 -
   3.155 -    /**
   3.156 -     * Handle for the source collection, if any.
   3.157 -     */
   3.158 -    void const *src_handle;
   3.159 -
   3.160 -    /**
   3.161 -     * Field for storing a key-value pair.
   3.162 -     * May be used by iterators that iterate over k/v-collections.
   3.163 -     */
   3.164 -    struct {
   3.165 -        /**
   3.166 -         * A pointer to the key.
   3.167 -         */
   3.168 -        void const *key;
   3.169 -        /**
   3.170 -         * A pointer to the value.
   3.171 -         */
   3.172 -        void *value;
   3.173 -    } kv_data;
   3.174 -
   3.175 -    /**
   3.176 -     * Field for storing a slot number.
   3.177 -     * May be used by iterators that iterate over multi-bucket collections.
   3.178 -     */
   3.179 -    size_t slot;
   3.180 -
   3.181 -    /**
   3.182 -     * If the iterator is position-aware, contains the index of the element in the underlying collection.
   3.183 -     * Otherwise, this field is usually uninitialized.
   3.184 -     */
   3.185 -    size_t index;
   3.186 -
   3.187 -    /**
   3.188 -     * The size of an individual element.
   3.189 -     */
   3.190 -    size_t elem_size;
   3.191 -
   3.192 -    /**
   3.193 -     * May contain the total number of elements, if known.
   3.194 -     * Shall be set to \c SIZE_MAX when the total number is unknown during iteration.
   3.195 -     */
   3.196 -    size_t elem_count;
   3.197 -};
   3.198 -
   3.199 -/**
   3.200 - * Iterator value type.
   3.201   * An iterator points to a certain element in a (possibly unbounded) chain of elements.
   3.202   * Iterators that are based on collections (which have a defined "first" element), are supposed
   3.203   * to be "position-aware", which means that they keep track of the current index within the collection.
   3.204   *
   3.205   * @note Objects that are pointed to by an iterator are always mutable through that iterator. However,
   3.206 - * this iterator cannot mutate the collection itself (add or remove elements) and any mutation of the
   3.207 - * collection by other means makes this iterator invalid (regardless of what cxIteratorValid() returns).
   3.208 - *
   3.209 - * @see CxMutIterator
   3.210 + * any concurrent mutation of the collection other than by this iterator makes this iterator invalid
   3.211 + * and it must not be used anymore.
   3.212   */
   3.213  typedef struct cx_iterator_s CxIterator;
   3.214  
   3.215 @@ -237,7 +157,7 @@
   3.216   * @param iter the iterator
   3.217   * @return true iff the iterator points to valid data
   3.218   */
   3.219 -#define cxIteratorValid(iter) (iter).base.valid(&(iter))
   3.220 +#define cxIteratorValid(iter) (iter).valid(&(iter))
   3.221  
   3.222  /**
   3.223   * Returns a pointer to the current element.
   3.224 @@ -247,21 +167,21 @@
   3.225   * @param iter the iterator
   3.226   * @return a pointer to the current element
   3.227   */
   3.228 -#define cxIteratorCurrent(iter) (iter).base.current(&iter)
   3.229 +#define cxIteratorCurrent(iter) (iter).current(&iter)
   3.230  
   3.231  /**
   3.232   * Advances the iterator to the next element.
   3.233   *
   3.234   * @param iter the iterator
   3.235   */
   3.236 -#define cxIteratorNext(iter) (iter).base.next(&iter)
   3.237 +#define cxIteratorNext(iter) (iter).next(&iter)
   3.238  
   3.239  /**
   3.240   * Flags the current element for removal, if this iterator is mutating.
   3.241   *
   3.242   * @param iter the iterator
   3.243   */
   3.244 -#define cxIteratorFlagRemoval(iter) (iter).base.remove |= (iter).base.mutating
   3.245 +#define cxIteratorFlagRemoval(iter) (iter).remove |= (iter).mutating
   3.246  
   3.247  /**
   3.248   * Loops over an iterator.
   3.249 @@ -316,7 +236,7 @@
   3.250   * @return an iterator for the specified array
   3.251   */
   3.252  __attribute__((__warn_unused_result__))
   3.253 -CxMutIterator cxMutIterator(
   3.254 +CxIterator cxMutIterator(
   3.255          void *array,
   3.256          size_t elem_size,
   3.257          size_t elem_count,
     4.1 --- a/src/cx/list.h	Thu May 23 18:21:36 2024 +0200
     4.2 +++ b/src/cx/list.h	Thu May 23 19:29:14 2024 +0200
     4.3 @@ -100,7 +100,7 @@
     4.4       * Member function for inserting an element relative to an iterator position.
     4.5       */
     4.6      int (*insert_iter)(
     4.7 -            struct cx_mut_iterator_s *iter,
     4.8 +            struct cx_iterator_s *iter,
     4.9              void const *elem,
    4.10              int prepend
    4.11      );
    4.12 @@ -336,10 +336,10 @@
    4.13   */
    4.14  __attribute__((__nonnull__))
    4.15  static inline int cxListInsertAfter(
    4.16 -        CxMutIterator *iter,
    4.17 +        CxIterator *iter,
    4.18          void const *elem
    4.19  ) {
    4.20 -    return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0);
    4.21 +    return ((struct cx_list_s *) iter->src_handle.m)->cl->insert_iter(iter, elem, 0);
    4.22  }
    4.23  
    4.24  /**
    4.25 @@ -359,10 +359,10 @@
    4.26   */
    4.27  __attribute__((__nonnull__))
    4.28  static inline int cxListInsertBefore(
    4.29 -        CxMutIterator *iter,
    4.30 +        CxIterator *iter,
    4.31          void const *elem
    4.32  ) {
    4.33 -    return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1);
    4.34 +    return ((struct cx_list_s *) iter->src_handle.m)->cl->insert_iter(iter, elem, 1);
    4.35  }
    4.36  
    4.37  /**
    4.38 @@ -481,7 +481,7 @@
    4.39   * @return a new iterator
    4.40   */
    4.41  __attribute__((__nonnull__, __warn_unused_result__))
    4.42 -CxMutIterator cxListMutIteratorAt(
    4.43 +CxIterator cxListMutIteratorAt(
    4.44          CxList *list,
    4.45          size_t index
    4.46  );
    4.47 @@ -499,7 +499,7 @@
    4.48   * @return a new iterator
    4.49   */
    4.50  __attribute__((__nonnull__, __warn_unused_result__))
    4.51 -CxMutIterator cxListMutBackwardsIteratorAt(
    4.52 +CxIterator cxListMutBackwardsIteratorAt(
    4.53          CxList *list,
    4.54          size_t index
    4.55  );
    4.56 @@ -530,7 +530,7 @@
    4.57   * @return a new iterator
    4.58   */
    4.59  __attribute__((__nonnull__, __warn_unused_result__))
    4.60 -static inline CxMutIterator cxListMutIterator(CxList *list) {
    4.61 +static inline CxIterator cxListMutIterator(CxList *list) {
    4.62      return cxListMutIteratorAt(list, 0);
    4.63  }
    4.64  
    4.65 @@ -561,7 +561,7 @@
    4.66   * @return a new iterator
    4.67   */
    4.68  __attribute__((__nonnull__, __warn_unused_result__))
    4.69 -static inline CxMutIterator cxListMutBackwardsIterator(CxList *list) {
    4.70 +static inline CxIterator cxListMutBackwardsIterator(CxList *list) {
    4.71      return cxListMutBackwardsIteratorAt(list, list->size - 1);
    4.72  }
    4.73  
     5.1 --- a/src/cx/map.h	Thu May 23 18:21:36 2024 +0200
     5.2 +++ b/src/cx/map.h	Thu May 23 19:29:14 2024 +0200
     5.3 @@ -268,7 +268,7 @@
     5.4   * @return an iterator for the currently stored values
     5.5   */
     5.6  __attribute__((__nonnull__, __warn_unused_result__))
     5.7 -CxMutIterator cxMapMutIteratorValues(CxMap *map);
     5.8 +CxIterator cxMapMutIteratorValues(CxMap *map);
     5.9  
    5.10  /**
    5.11   * Creates a mutating iterator over the keys of a map.
    5.12 @@ -282,7 +282,7 @@
    5.13   * @return an iterator for the currently stored keys
    5.14   */
    5.15  __attribute__((__nonnull__, __warn_unused_result__))
    5.16 -CxMutIterator cxMapMutIteratorKeys(CxMap *map);
    5.17 +CxIterator cxMapMutIteratorKeys(CxMap *map);
    5.18  
    5.19  /**
    5.20   * Creates a mutating iterator for a map.
    5.21 @@ -298,7 +298,7 @@
    5.22   * @see cxMapMutIteratorValues()
    5.23   */
    5.24  __attribute__((__nonnull__, __warn_unused_result__))
    5.25 -CxMutIterator cxMapMutIterator(CxMap *map);
    5.26 +CxIterator cxMapMutIterator(CxMap *map);
    5.27  
    5.28  #ifdef __cplusplus
    5.29  } // end the extern "C" block here, because we want to start overloading
     6.1 --- a/src/cx/tree.h	Thu May 23 18:21:36 2024 +0200
     6.2 +++ b/src/cx/tree.h	Thu May 23 19:29:14 2024 +0200
     6.3 @@ -58,10 +58,7 @@
     6.4   * @see CxIterator
     6.5   */
     6.6  typedef struct cx_tree_iterator_s {
     6.7 -    /**
     6.8 -     * The base properties of this iterator.
     6.9 -     */
    6.10 -    struct cx_iterator_base_s base;
    6.11 +    CX_ITERATOR_BASE
    6.12      /**
    6.13       * Indicates whether the subtree below the current node shall be skipped.
    6.14       */
    6.15 @@ -97,7 +94,7 @@
    6.16       * Stores a copy of the next pointer of the visited node.
    6.17       * Allows freeing a node on exit without corrupting the iteration.
    6.18       */
    6.19 -    void *next;
    6.20 +    void *node_next;
    6.21      /**
    6.22       * Internal stack.
    6.23       * Will be automatically freed once the iterator becomes invalid.
    6.24 @@ -157,10 +154,7 @@
    6.25   * @see CxIterator
    6.26   */
    6.27  typedef struct cx_tree_visitor_s {
    6.28 -    /**
    6.29 -     * The base properties of this iterator.
    6.30 -     */
    6.31 -    struct cx_iterator_base_s base;
    6.32 +    CX_ITERATOR_BASE
    6.33      /**
    6.34       * Indicates whether the subtree below the current node shall be skipped.
    6.35       */
     7.1 --- a/src/hash_map.c	Thu May 23 18:21:36 2024 +0200
     7.2 +++ b/src/hash_map.c	Thu May 23 19:29:14 2024 +0200
     7.3 @@ -252,7 +252,7 @@
     7.4  
     7.5  static void *cx_hash_map_iter_current_value(void const *it) {
     7.6      struct cx_iterator_s const *iter = it;
     7.7 -    struct cx_hash_map_s const *map = iter->src_handle;
     7.8 +    struct cx_hash_map_s const *map = iter->src_handle.c;
     7.9      struct cx_hash_map_element_s *elm = iter->elem_handle;
    7.10      if (map->base.store_pointer) {
    7.11          return *(void **) elm->data;
    7.12 @@ -269,15 +269,13 @@
    7.13  static void cx_hash_map_iter_next(void *it) {
    7.14      struct cx_iterator_s *iter = it;
    7.15      struct cx_hash_map_element_s *elm = iter->elem_handle;
    7.16 +    struct cx_hash_map_s *map = iter->src_handle.m;
    7.17  
    7.18      // remove current element, if asked
    7.19 -    if (iter->base.remove) {
    7.20 -        // obtain mutable pointer to the map
    7.21 -        struct cx_mut_iterator_s *miter = it;
    7.22 -        struct cx_hash_map_s *map = miter->src_handle;
    7.23 +    if (iter->remove) {
    7.24  
    7.25          // clear the flag
    7.26 -        iter->base.remove = false;
    7.27 +        iter->remove = false;
    7.28  
    7.29          // determine the next element
    7.30          struct cx_hash_map_element_s *next = elm->next;
    7.31 @@ -306,7 +304,6 @@
    7.32      }
    7.33  
    7.34      // search the next bucket, if required
    7.35 -    struct cx_hash_map_s const *map = iter->src_handle;
    7.36      while (elm == NULL && ++iter->slot < map->bucket_count) {
    7.37          elm = map->buckets[iter->slot];
    7.38      }
    7.39 @@ -332,30 +329,30 @@
    7.40  ) {
    7.41      CxIterator iter;
    7.42  
    7.43 -    iter.src_handle = map;
    7.44 +    iter.src_handle.c = map;
    7.45      iter.elem_count = map->size;
    7.46  
    7.47      switch (type) {
    7.48          case CX_MAP_ITERATOR_PAIRS:
    7.49              iter.elem_size = sizeof(CxMapEntry);
    7.50 -            iter.base.current = cx_hash_map_iter_current_entry;
    7.51 +            iter.current = cx_hash_map_iter_current_entry;
    7.52              break;
    7.53          case CX_MAP_ITERATOR_KEYS:
    7.54              iter.elem_size = sizeof(CxHashKey);
    7.55 -            iter.base.current = cx_hash_map_iter_current_key;
    7.56 +            iter.current = cx_hash_map_iter_current_key;
    7.57              break;
    7.58          case CX_MAP_ITERATOR_VALUES:
    7.59              iter.elem_size = map->item_size;
    7.60 -            iter.base.current = cx_hash_map_iter_current_value;
    7.61 +            iter.current = cx_hash_map_iter_current_value;
    7.62              break;
    7.63          default:
    7.64              assert(false);
    7.65      }
    7.66  
    7.67 -    iter.base.valid = cx_hash_map_iter_valid;
    7.68 -    iter.base.next = cx_hash_map_iter_next;
    7.69 -    iter.base.remove = false;
    7.70 -    iter.base.mutating = false;
    7.71 +    iter.valid = cx_hash_map_iter_valid;
    7.72 +    iter.next = cx_hash_map_iter_next;
    7.73 +    iter.remove = false;
    7.74 +    iter.mutating = false;
    7.75  
    7.76      iter.slot = 0;
    7.77      iter.index = 0;
     8.1 --- a/src/iterator.c	Thu May 23 18:21:36 2024 +0200
     8.2 +++ b/src/iterator.c	Thu May 23 19:29:14 2024 +0200
     8.3 @@ -41,30 +41,27 @@
     8.4  }
     8.5  
     8.6  static void cx_iter_next_fast(void *it) {
     8.7 -    struct cx_iterator_base_s *itbase = it;
     8.8 -    if (itbase->remove) {
     8.9 -        struct cx_mut_iterator_s *iter = it;
    8.10 -        itbase->remove = false;
    8.11 +    struct cx_iterator_s *iter = it;
    8.12 +    if (iter->remove) {
    8.13 +        iter->remove = false;
    8.14          iter->elem_count--;
    8.15          // only move the last element when we are not currently aiming
    8.16          // at the last element already
    8.17          if (iter->index < iter->elem_count) {
    8.18 -            void *last = ((char *) iter->src_handle)
    8.19 +            void *last = ((char *) iter->src_handle.m)
    8.20                           + iter->elem_count * iter->elem_size;
    8.21              memcpy(iter->elem_handle, last, iter->elem_size);
    8.22          }
    8.23      } else {
    8.24 -        struct cx_iterator_s *iter = it;
    8.25          iter->index++;
    8.26          iter->elem_handle = ((char *) iter->elem_handle) + iter->elem_size;
    8.27      }
    8.28  }
    8.29  
    8.30  static void cx_iter_next_slow(void *it) {
    8.31 -    struct cx_iterator_base_s *itbase = it;
    8.32 -    if (itbase->remove) {
    8.33 -        struct cx_mut_iterator_s *iter = it;
    8.34 -        itbase->remove = false;
    8.35 +    struct cx_iterator_s *iter = it;
    8.36 +    if (iter->remove) {
    8.37 +        iter->remove = false;
    8.38          iter->elem_count--;
    8.39  
    8.40          // number of elements to move
    8.41 @@ -77,30 +74,29 @@
    8.42              );
    8.43          }
    8.44      } else {
    8.45 -        struct cx_iterator_s *iter = it;
    8.46          iter->index++;
    8.47          iter->elem_handle = ((char *) iter->elem_handle) + iter->elem_size;
    8.48      }
    8.49  }
    8.50  
    8.51 -CxMutIterator cxMutIterator(
    8.52 +CxIterator cxMutIterator(
    8.53          void *array,
    8.54          size_t elem_size,
    8.55          size_t elem_count,
    8.56          bool remove_keeps_order
    8.57  ) {
    8.58 -    CxMutIterator iter;
    8.59 +    CxIterator iter;
    8.60  
    8.61      iter.index = 0;
    8.62 -    iter.src_handle = array;
    8.63 +    iter.src_handle.m = array;
    8.64      iter.elem_handle = array;
    8.65      iter.elem_size = elem_size;
    8.66      iter.elem_count = array == NULL ? 0 : elem_count;
    8.67 -    iter.base.valid = cx_iter_valid;
    8.68 -    iter.base.current = cx_iter_current;
    8.69 -    iter.base.next = remove_keeps_order ? cx_iter_next_slow : cx_iter_next_fast;
    8.70 -    iter.base.remove = false;
    8.71 -    iter.base.mutating = true;
    8.72 +    iter.valid = cx_iter_valid;
    8.73 +    iter.current = cx_iter_current;
    8.74 +    iter.next = remove_keeps_order ? cx_iter_next_slow : cx_iter_next_fast;
    8.75 +    iter.remove = false;
    8.76 +    iter.mutating = true;
    8.77  
    8.78      return iter;
    8.79  }
    8.80 @@ -110,11 +106,7 @@
    8.81          size_t elem_size,
    8.82          size_t elem_count
    8.83  ) {
    8.84 -    CxMutIterator iter = cxMutIterator((void*)array, elem_size, elem_count, false);
    8.85 -    iter.base.mutating = false;
    8.86 -
    8.87 -    // we know the iterators share the same memory layout
    8.88 -    CxIterator ret;
    8.89 -    memcpy(&ret, &iter, sizeof(CxIterator));
    8.90 -    return ret;
    8.91 +    CxIterator iter = cxMutIterator((void*)array, elem_size, elem_count, false);
    8.92 +    iter.mutating = false;
    8.93 +    return iter;
    8.94  }
     9.1 --- a/src/linked_list.c	Thu May 23 18:21:36 2024 +0200
     9.2 +++ b/src/linked_list.c	Thu May 23 19:29:14 2024 +0200
     9.3 @@ -816,12 +816,11 @@
     9.4  }
     9.5  
     9.6  static void cx_ll_iter_next(void *it) {
     9.7 -    struct cx_iterator_base_s *itbase = it;
     9.8 -    if (itbase->remove) {
     9.9 -        itbase->remove = false;
    9.10 -        struct cx_mut_iterator_s *iter = it;
    9.11 -        struct cx_list_s *list = iter->src_handle;
    9.12 -        cx_linked_list *ll = iter->src_handle;
    9.13 +    struct cx_iterator_s *iter = it;
    9.14 +    if (iter->remove) {
    9.15 +        iter->remove = false;
    9.16 +        struct cx_list_s *list = iter->src_handle.m;
    9.17 +        cx_linked_list *ll = iter->src_handle.m;
    9.18          cx_linked_list_node *node = iter->elem_handle;
    9.19          iter->elem_handle = node->next;
    9.20          cx_invoke_destructor(list, node->payload);
    9.21 @@ -830,7 +829,6 @@
    9.22          list->size--;
    9.23          cxFree(list->allocator, node);
    9.24      } else {
    9.25 -        struct cx_iterator_s *iter = it;
    9.26          iter->index++;
    9.27          cx_linked_list_node *node = iter->elem_handle;
    9.28          iter->elem_handle = node->next;
    9.29 @@ -838,12 +836,11 @@
    9.30  }
    9.31  
    9.32  static void cx_ll_iter_prev(void *it) {
    9.33 -    struct cx_iterator_base_s *itbase = it;
    9.34 -    if (itbase->remove) {
    9.35 -        itbase->remove = false;
    9.36 -        struct cx_mut_iterator_s *iter = it;
    9.37 -        struct cx_list_s *list = iter->src_handle;
    9.38 -        cx_linked_list *ll = iter->src_handle;
    9.39 +    struct cx_iterator_s *iter = it;
    9.40 +    if (iter->remove) {
    9.41 +        iter->remove = false;
    9.42 +        struct cx_list_s *list = iter->src_handle.m;
    9.43 +        cx_linked_list *ll = iter->src_handle.m;
    9.44          cx_linked_list_node *node = iter->elem_handle;
    9.45          iter->elem_handle = node->prev;
    9.46          iter->index--;
    9.47 @@ -853,7 +850,6 @@
    9.48          list->size--;
    9.49          cxFree(list->allocator, node);
    9.50      } else {
    9.51 -        struct cx_iterator_s *iter = it;
    9.52          iter->index--;
    9.53          cx_linked_list_node *node = iter->elem_handle;
    9.54          iter->elem_handle = node->prev;
    9.55 @@ -873,24 +869,24 @@
    9.56  ) {
    9.57      CxIterator iter;
    9.58      iter.index = index;
    9.59 -    iter.src_handle = list;
    9.60 +    iter.src_handle.c = list;
    9.61      iter.elem_handle = cx_ll_node_at((cx_linked_list const *) list, index);
    9.62      iter.elem_size = list->item_size;
    9.63      iter.elem_count = list->size;
    9.64 -    iter.base.valid = cx_ll_iter_valid;
    9.65 -    iter.base.current = cx_ll_iter_current;
    9.66 -    iter.base.next = backwards ? cx_ll_iter_prev : cx_ll_iter_next;
    9.67 -    iter.base.mutating = false;
    9.68 -    iter.base.remove = false;
    9.69 +    iter.valid = cx_ll_iter_valid;
    9.70 +    iter.current = cx_ll_iter_current;
    9.71 +    iter.next = backwards ? cx_ll_iter_prev : cx_ll_iter_next;
    9.72 +    iter.mutating = false;
    9.73 +    iter.remove = false;
    9.74      return iter;
    9.75  }
    9.76  
    9.77  static int cx_ll_insert_iter(
    9.78 -        CxMutIterator *iter,
    9.79 +        CxIterator *iter,
    9.80          void const *elem,
    9.81          int prepend
    9.82  ) {
    9.83 -    struct cx_list_s *list = iter->src_handle;
    9.84 +    struct cx_list_s *list = iter->src_handle.m;
    9.85      cx_linked_list_node *node = iter->elem_handle;
    9.86      if (node != NULL) {
    9.87          assert(prepend >= 0 && prepend <= 1);
    10.1 --- a/src/list.c	Thu May 23 18:21:36 2024 +0200
    10.2 +++ b/src/list.c	Thu May 23 19:29:14 2024 +0200
    10.3 @@ -80,11 +80,11 @@
    10.4  }
    10.5  
    10.6  static int cx_pl_insert_iter(
    10.7 -        struct cx_mut_iterator_s *iter,
    10.8 +        struct cx_iterator_s *iter,
    10.9          void const *elem,
   10.10          int prepend
   10.11  ) {
   10.12 -    struct cx_list_s *list = iter->src_handle;
   10.13 +    struct cx_list_s *list = iter->src_handle.m;
   10.14      return list->climpl->insert_iter(iter, &elem, prepend);
   10.15  }
   10.16  
   10.17 @@ -148,7 +148,7 @@
   10.18  
   10.19  static void *cx_pl_iter_current(void const *it) {
   10.20      struct cx_iterator_s const *iter = it;
   10.21 -    void **ptr = iter->base.current_impl(it);
   10.22 +    void **ptr = iter->current_impl(it);
   10.23      return ptr == NULL ? NULL : *ptr;
   10.24  }
   10.25  
   10.26 @@ -158,8 +158,8 @@
   10.27          bool backwards
   10.28  ) {
   10.29      struct cx_iterator_s iter = list->climpl->iterator(list, index, backwards);
   10.30 -    iter.base.current_impl = iter.base.current;
   10.31 -    iter.base.current = cx_pl_iter_current;
   10.32 +    iter.current_impl = iter.current;
   10.33 +    iter.current = cx_pl_iter_current;
   10.34      return iter;
   10.35  }
   10.36  
   10.37 @@ -235,9 +235,9 @@
   10.38          __attribute__((__unused__)) bool backwards
   10.39  ) {
   10.40      CxIterator iter = {0};
   10.41 -    iter.src_handle = list;
   10.42 +    iter.src_handle.c = list;
   10.43      iter.index = index;
   10.44 -    iter.base.valid = cx_emptyl_iter_valid;
   10.45 +    iter.valid = cx_emptyl_iter_valid;
   10.46      return iter;
   10.47  }
   10.48  
   10.49 @@ -317,28 +317,20 @@
   10.50      }
   10.51  }
   10.52  
   10.53 -CxMutIterator cxListMutIteratorAt(
   10.54 +CxIterator cxListMutIteratorAt(
   10.55          CxList *list,
   10.56          size_t index
   10.57  ) {
   10.58      CxIterator it = list->cl->iterator(list, index, false);
   10.59 -    it.base.mutating = true;
   10.60 -
   10.61 -    // we know the iterators share the same memory layout
   10.62 -    CxMutIterator iter;
   10.63 -    memcpy(&iter, &it, sizeof(CxMutIterator));
   10.64 -    return iter;
   10.65 +    it.mutating = true;
   10.66 +    return it;
   10.67  }
   10.68  
   10.69 -CxMutIterator cxListMutBackwardsIteratorAt(
   10.70 +CxIterator cxListMutBackwardsIteratorAt(
   10.71          CxList *list,
   10.72          size_t index
   10.73  ) {
   10.74      CxIterator it = list->cl->iterator(list, index, true);
   10.75 -    it.base.mutating = true;
   10.76 -
   10.77 -    // we know the iterators share the same memory layout
   10.78 -    CxMutIterator iter;
   10.79 -    memcpy(&iter, &it, sizeof(CxMutIterator));
   10.80 -    return iter;
   10.81 +    it.mutating = true;
   10.82 +    return it;
   10.83  }
    11.1 --- a/src/map.c	Thu May 23 18:21:36 2024 +0200
    11.2 +++ b/src/map.c	Thu May 23 19:29:14 2024 +0200
    11.3 @@ -51,8 +51,8 @@
    11.4          __attribute__((__unused__)) enum cx_map_iterator_type type
    11.5  ) {
    11.6      CxIterator iter = {0};
    11.7 -    iter.src_handle = map;
    11.8 -    iter.base.valid = cx_empty_map_iter_valid;
    11.9 +    iter.src_handle.c = map;
   11.10 +    iter.valid = cx_empty_map_iter_valid;
   11.11      return iter;
   11.12  }
   11.13  
   11.14 @@ -81,32 +81,20 @@
   11.15  
   11.16  // </editor-fold>
   11.17  
   11.18 -CxMutIterator cxMapMutIteratorValues(CxMap *map) {
   11.19 +CxIterator cxMapMutIteratorValues(CxMap *map) {
   11.20      CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);
   11.21 -    it.base.mutating = true;
   11.22 -
   11.23 -    // we know the iterators share the same memory layout
   11.24 -    CxMutIterator iter;
   11.25 -    memcpy(&iter, &it, sizeof(CxMutIterator));
   11.26 -    return iter;
   11.27 +    it.mutating = true;
   11.28 +    return it;
   11.29  }
   11.30  
   11.31 -CxMutIterator cxMapMutIteratorKeys(CxMap *map) {
   11.32 +CxIterator cxMapMutIteratorKeys(CxMap *map) {
   11.33      CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);
   11.34 -    it.base.mutating = true;
   11.35 -
   11.36 -    // we know the iterators share the same memory layout
   11.37 -    CxMutIterator iter;
   11.38 -    memcpy(&iter, &it, sizeof(CxMutIterator));
   11.39 -    return iter;
   11.40 +    it.mutating = true;
   11.41 +    return it;
   11.42  }
   11.43  
   11.44 -CxMutIterator cxMapMutIterator(CxMap *map) {
   11.45 +CxIterator cxMapMutIterator(CxMap *map) {
   11.46      CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);
   11.47 -    it.base.mutating = true;
   11.48 -
   11.49 -    // we know the iterators share the same memory layout
   11.50 -    CxMutIterator iter;
   11.51 -    memcpy(&iter, &it, sizeof(CxMutIterator));
   11.52 -    return iter;
   11.53 +    it.mutating = true;
   11.54 +    return it;
   11.55  }
    12.1 --- a/src/tree.c	Thu May 23 18:21:36 2024 +0200
    12.2 +++ b/src/tree.c	Thu May 23 19:29:14 2024 +0200
    12.3 @@ -205,10 +205,10 @@
    12.4          cx_tree_iter_search_next:
    12.5          // check if there is a sibling
    12.6          if (iter->exiting) {
    12.7 -            next = iter->next;
    12.8 +            next = iter->node_next;
    12.9          } else {
   12.10              next = tree_next(iter->node);
   12.11 -            iter->next = next;
   12.12 +            iter->node_next = next;
   12.13          }
   12.14          if (next == NULL) {
   12.15              // no sibling, we are done with this node and exit
   12.16 @@ -220,7 +220,7 @@
   12.17                  if (iter->depth == 1) {
   12.18                      // there is no parent - we have iterated the entire tree
   12.19                      // invalidate the iterator and free the node stack
   12.20 -                    iter->node = iter->next = NULL;
   12.21 +                    iter->node = iter->node_next = NULL;
   12.22                      iter->stack_capacity = iter->depth = 0;
   12.23                      free(iter->stack);
   12.24                      iter->stack = NULL;
   12.25 @@ -272,7 +272,7 @@
   12.26  
   12.27      // visit the root node
   12.28      iter.node = root;
   12.29 -    iter.next = NULL;
   12.30 +    iter.node_next = NULL;
   12.31      iter.counter = 1;
   12.32      iter.depth = 1;
   12.33      iter.stack[0] = root;
   12.34 @@ -280,12 +280,12 @@
   12.35      iter.skip = false;
   12.36  
   12.37      // assign base iterator functions
   12.38 -    iter.base.mutating = false;
   12.39 -    iter.base.remove = false;
   12.40 -    iter.base.current_impl = NULL;
   12.41 -    iter.base.valid = cx_tree_iter_valid;
   12.42 -    iter.base.next = cx_tree_iter_next;
   12.43 -    iter.base.current = cx_tree_iter_current;
   12.44 +    iter.mutating = false;
   12.45 +    iter.remove = false;
   12.46 +    iter.current_impl = NULL;
   12.47 +    iter.valid = cx_tree_iter_valid;
   12.48 +    iter.next = cx_tree_iter_next;
   12.49 +    iter.current = cx_tree_iter_current;
   12.50  
   12.51      return iter;
   12.52  }
   12.53 @@ -389,12 +389,12 @@
   12.54      iter.queue_last = NULL;
   12.55  
   12.56      // assign base iterator functions
   12.57 -    iter.base.mutating = false;
   12.58 -    iter.base.remove = false;
   12.59 -    iter.base.current_impl = NULL;
   12.60 -    iter.base.valid = cx_tree_visitor_valid;
   12.61 -    iter.base.next = cx_tree_visitor_next;
   12.62 -    iter.base.current = cx_tree_visitor_current;
   12.63 +    iter.mutating = false;
   12.64 +    iter.remove = false;
   12.65 +    iter.current_impl = NULL;
   12.66 +    iter.valid = cx_tree_visitor_valid;
   12.67 +    iter.next = cx_tree_visitor_next;
   12.68 +    iter.current = cx_tree_visitor_current;
   12.69  
   12.70      return iter;
   12.71  }
    13.1 --- a/tests/test_hash_map.c	Thu May 23 18:21:36 2024 +0200
    13.2 +++ b/tests/test_hash_map.c	Thu May 23 19:29:14 2024 +0200
    13.3 @@ -240,7 +240,7 @@
    13.4          cxMapPut(map, "key 5", (void *) "val 5");
    13.5          cxMapPut(map, "key 6", (void *) "val 6");
    13.6  
    13.7 -        CxMutIterator iter = cxMapMutIterator(map);
    13.8 +        CxIterator iter = cxMapMutIterator(map);
    13.9          cx_foreach(CxMapEntry*, entry, iter) {
   13.10              if (((char const *)entry->key->data)[4] % 2 == 1) cxIteratorFlagRemoval(iter);
   13.11          }
   13.12 @@ -313,13 +313,13 @@
   13.13      cxMapPut(map, k5, (void *) v5);
   13.14  
   13.15      {
   13.16 -        CxMutIterator iter = cxMapMutIteratorKeys(map);
   13.17 +        CxIterator iter = cxMapMutIteratorKeys(map);
   13.18          cx_foreach(CxHashKey*, key, iter) {
   13.19              if (((char*)key->data)[4] == '1') cxIteratorFlagRemoval(iter);
   13.20          }
   13.21      }
   13.22      {
   13.23 -        CxMutIterator iter = cxMapMutIteratorValues(map);
   13.24 +        CxIterator iter = cxMapMutIteratorValues(map);
   13.25          cx_foreach(char*, v, iter) {
   13.26              if (v[4] == '5') cxIteratorFlagRemoval(iter);
   13.27          }
   13.28 @@ -380,9 +380,9 @@
   13.29      CxIterator it1 = cxMapIterator(map);
   13.30      CxIterator it2 = cxMapIteratorValues(map);
   13.31      CxIterator it3 = cxMapIteratorKeys(map);
   13.32 -    CxMutIterator it4 = cxMapMutIterator(map);
   13.33 -    CxMutIterator it5 = cxMapMutIteratorValues(map);
   13.34 -    CxMutIterator it6 = cxMapMutIteratorKeys(map);
   13.35 +    CxIterator it4 = cxMapMutIterator(map);
   13.36 +    CxIterator it5 = cxMapMutIteratorValues(map);
   13.37 +    CxIterator it6 = cxMapMutIteratorKeys(map);
   13.38  
   13.39      CX_TEST_DO {
   13.40          CX_TEST_ASSERT(!cxIteratorValid(it1));
    14.1 --- a/tests/test_iterator.c	Thu May 23 18:21:36 2024 +0200
    14.2 +++ b/tests/test_iterator.c	Thu May 23 19:29:14 2024 +0200
    14.3 @@ -40,7 +40,7 @@
    14.4          CX_TEST_ASSERT(iter.index == 0);
    14.5          CX_TEST_ASSERT(iter.elem_size == sizeof(unsigned));
    14.6          CX_TEST_ASSERT(iter.elem_count == size);
    14.7 -        CX_TEST_ASSERT(iter.src_handle == array);
    14.8 +        CX_TEST_ASSERT(iter.src_handle.c == array);
    14.9          CX_TEST_ASSERT(iter.elem_handle == &array[0]);
   14.10          CX_TEST_ASSERT(cxIteratorValid(iter));
   14.11      }
   14.12 @@ -52,7 +52,7 @@
   14.13          CX_TEST_ASSERT(iter.index == 0);
   14.14          CX_TEST_ASSERT(iter.elem_size == sizeof(unsigned));
   14.15          CX_TEST_ASSERT(iter.elem_count == 0);
   14.16 -        CX_TEST_ASSERT(iter.src_handle == NULL);
   14.17 +        CX_TEST_ASSERT(iter.src_handle.c == NULL);
   14.18          CX_TEST_ASSERT(iter.elem_handle == NULL);
   14.19          CX_TEST_ASSERT(!cxIteratorValid(iter));
   14.20      }
   14.21 @@ -71,7 +71,7 @@
   14.22              CX_TEST_ASSERT(*e == expected);
   14.23              CX_TEST_ASSERT(iter.elem_size == sizeof(unsigned));
   14.24              CX_TEST_ASSERT(iter.elem_count == size);
   14.25 -            CX_TEST_ASSERT(iter.src_handle == array);
   14.26 +            CX_TEST_ASSERT(iter.src_handle.c == array);
   14.27              CX_TEST_ASSERT(iter.elem_handle == &array[expected]);
   14.28              expected++;
   14.29          }
   14.30 @@ -96,7 +96,7 @@
   14.31              0, 2, 4, 6, 8, 10, 12, 14, 16, 18
   14.32      };
   14.33  
   14.34 -    CxMutIterator iter = cxMutIterator(array, sizeof(unsigned), size, true);
   14.35 +    CxIterator iter = cxMutIterator(array, sizeof(unsigned), size, true);
   14.36      CX_TEST_DO {
   14.37          unsigned expected = 0;
   14.38          cx_foreach(unsigned *, e, iter) {
   14.39 @@ -104,7 +104,7 @@
   14.40              CX_TEST_ASSERT(iter.index == indices[expected]);
   14.41              CX_TEST_ASSERT(iter.elem_size == sizeof(unsigned));
   14.42              CX_TEST_ASSERT(iter.elem_count == elem_counts[expected]);
   14.43 -            CX_TEST_ASSERT(iter.src_handle == array);
   14.44 +            CX_TEST_ASSERT(iter.src_handle.m == array);
   14.45              CX_TEST_ASSERT(iter.elem_handle == &array[indices[expected]]);
   14.46              expected++;
   14.47              if (expected % 2 == 0) {
   14.48 @@ -141,7 +141,7 @@
   14.49              15, 6, 14, 7, 13, 8, 12, 9, 11, 10
   14.50      };
   14.51  
   14.52 -    CxMutIterator iter = cxMutIterator(array, sizeof(unsigned), size, false);
   14.53 +    CxIterator iter = cxMutIterator(array, sizeof(unsigned), size, false);
   14.54      CX_TEST_DO {
   14.55          unsigned expected = 0;
   14.56          cx_foreach(unsigned *, e, iter) {
   14.57 @@ -149,7 +149,7 @@
   14.58              CX_TEST_ASSERT(iter.index == indices[expected]);
   14.59              CX_TEST_ASSERT(iter.elem_size == sizeof(unsigned));
   14.60              CX_TEST_ASSERT(iter.elem_count == elem_counts[expected]);
   14.61 -            CX_TEST_ASSERT(iter.src_handle == array);
   14.62 +            CX_TEST_ASSERT(iter.src_handle.m == array);
   14.63              CX_TEST_ASSERT(iter.elem_handle == &array[indices[expected]]);
   14.64              expected++;
   14.65              if (expected % 2 == 0) {
    15.1 --- a/tests/test_list.c	Thu May 23 18:21:36 2024 +0200
    15.2 +++ b/tests/test_list.c	Thu May 23 19:29:14 2024 +0200
    15.3 @@ -632,8 +632,8 @@
    15.4  
    15.5      CxIterator it1 = cxListIterator(list);
    15.6      CxIterator it2 = cxListBackwardsIterator(list);
    15.7 -    CxMutIterator it3 = cxListMutIterator(list);
    15.8 -    CxMutIterator it4 = cxListMutBackwardsIterator(list);
    15.9 +    CxIterator it3 = cxListMutIterator(list);
   15.10 +    CxIterator it4 = cxListMutBackwardsIterator(list);
   15.11  
   15.12      CX_TEST_DO {
   15.13          CX_TEST_ASSERT(!cxIteratorValid(it1));
   15.14 @@ -1224,7 +1224,7 @@
   15.15      }
   15.16      CX_TEST_ASSERT(i == 0);
   15.17      i = len / 2;
   15.18 -    CxMutIterator mut_iter = cxListMutIteratorAt(list, i);
   15.19 +    CxIterator mut_iter = cxListMutIteratorAt(list, i);
   15.20      CX_TEST_ASSERT(mut_iter.elem_size == list->item_size);
   15.21      CX_TEST_ASSERT(mut_iter.elem_count == list->size);
   15.22      size_t j = 0;
   15.23 @@ -1258,7 +1258,7 @@
   15.24      cx_for_n(i, 5) cxListAdd(list, &fivenums[i]);
   15.25      int newdata[] = array_init(10, 20, 30, 40, 50);
   15.26  
   15.27 -    CxMutIterator iter = cxListMutIteratorAt(list, 2);
   15.28 +    CxIterator iter = cxListMutIteratorAt(list, 2);
   15.29      CX_TEST_ASSERT(cxIteratorValid(iter));
   15.30      CX_TEST_ASSERT(iter.index == 2);
   15.31      CX_TEST_ASSERT(*(int *) cxIteratorCurrent(iter) == 2);
   15.32 @@ -1365,7 +1365,7 @@
   15.33      CX_TEST_ASSERT(testdata[48] == destr_last_value + off);
   15.34      CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
   15.35  
   15.36 -    CxMutIterator iter = cxListMutIteratorAt(list, 7);
   15.37 +    CxIterator iter = cxListMutIteratorAt(list, 7);
   15.38      cxIteratorNext(iter);
   15.39      CX_TEST_ASSERT(2 == destr_test_ctr);
   15.40      CX_TEST_ASSERT(testdata[48] == destr_last_value + off);
    16.1 --- a/tests/test_tree.c	Thu May 23 18:21:36 2024 +0200
    16.2 +++ b/tests/test_tree.c	Thu May 23 19:29:14 2024 +0200
    16.3 @@ -260,8 +260,8 @@
    16.4          CX_TEST_ASSERT(!iter.exiting);
    16.5          CX_TEST_ASSERT(iter.counter == 1);
    16.6          CX_TEST_ASSERT(iter.node == &root);
    16.7 -        CX_TEST_ASSERT(!iter.base.mutating);
    16.8 -        CX_TEST_ASSERT(!iter.base.remove);
    16.9 +        CX_TEST_ASSERT(!iter.mutating);
   16.10 +        CX_TEST_ASSERT(!iter.remove);
   16.11          CX_TEST_ASSERT(iter.stack != NULL);
   16.12          CX_TEST_ASSERT(iter.stack_capacity > 0);
   16.13          CX_TEST_ASSERT(iter.stack_size == 1);
   16.14 @@ -517,8 +517,8 @@
   16.15          CxTreeVisitor iter = cx_tree_visitor(&root, tree_child_list);
   16.16          CX_TEST_ASSERT(iter.counter == 1);
   16.17          CX_TEST_ASSERT(iter.node == &root);
   16.18 -        CX_TEST_ASSERT(!iter.base.mutating);
   16.19 -        CX_TEST_ASSERT(!iter.base.remove);
   16.20 +        CX_TEST_ASSERT(!iter.mutating);
   16.21 +        CX_TEST_ASSERT(!iter.remove);
   16.22          CX_TEST_ASSERT(iter.queue_next != NULL);
   16.23          CX_TEST_ASSERT(iter.queue_last != NULL);
   16.24          CX_TEST_ASSERT(iter.depth == 1);

mercurial