--- a/ucx/cx/iterator.h Mon Jan 06 22:22:55 2025 +0100 +++ b/ucx/cx/iterator.h Tue Feb 25 21:11:00 2025 +0100 @@ -47,9 +47,8 @@ */ struct cx_iterator_base_s { /** - * True iff the iterator points to valid data. + * True if the iterator points to valid data. */ - cx_attr_nonnull bool (*valid)(const void *); /** @@ -57,15 +56,11 @@ * * When valid returns false, the behavior of this function is undefined. */ - cx_attr_nonnull - cx_attr_nodiscard void *(*current)(const void *); /** * Original implementation in case the function needs to be wrapped. */ - cx_attr_nonnull - cx_attr_nodiscard void *(*current_impl)(const void *); /** @@ -73,7 +68,6 @@ * * When valid returns false, the behavior of this function is undefined. */ - cx_attr_nonnull void (*next)(void *); /** * Indicates whether this iterator may remove elements. @@ -86,6 +80,12 @@ }; /** + * Convenience type definition for the base structure of an iterator. + * @see #CX_ITERATOR_BASE + */ +typedef struct cx_iterator_base_s CxIteratorBase; + +/** * Declares base attributes for an iterator. * Must be the first member of an iterator structure. */ @@ -120,27 +120,6 @@ } src_handle; /** - * Field for storing a key-value pair. - * May be used by iterators that iterate over k/v-collections. - */ - struct { - /** - * A pointer to the key. - */ - const void *key; - /** - * A pointer to the value. - */ - void *value; - } kv_data; - - /** - * Field for storing a slot number. - * May be used by iterators that iterate over multi-bucket collections. - */ - size_t slot; - - /** * If the iterator is position-aware, contains the index of the element in the underlying collection. * Otherwise, this field is usually uninitialized. */ @@ -174,8 +153,6 @@ /** * Checks if the iterator points to valid data. * - * This is especially false for past-the-end iterators. - * * @param iter the iterator * @retval true if the iterator points to valid data * @retval false if the iterator already moved past the end @@ -215,7 +192,7 @@ * This is useful for APIs that expect some iterator as an argument. * * @param iter the iterator - * @return (@c CxIterator*) a pointer to the iterator + * @return (@c struct @c cx_iterator_base_s*) a pointer to the iterator */ #define cxIteratorRef(iter) &((iter).base) @@ -248,6 +225,7 @@ * @see cxIteratorPtr() */ cx_attr_nodiscard +cx_attr_export CxIterator cxIterator( const void *array, size_t elem_size, @@ -278,6 +256,7 @@ * @return an iterator for the specified array */ cx_attr_nodiscard +cx_attr_export CxIterator cxMutIterator( void *array, size_t elem_size, @@ -299,6 +278,7 @@ * @see cxIterator() */ cx_attr_nodiscard +cx_attr_export CxIterator cxIteratorPtr( const void *array, size_t elem_count @@ -319,6 +299,7 @@ * @see cxIteratorPtr() */ cx_attr_nodiscard +cx_attr_export CxIterator cxMutIteratorPtr( void *array, size_t elem_count,