1.1 --- a/src/cx/map.h Wed Nov 23 22:40:55 2022 +0100 1.2 +++ b/src/cx/map.h Sat Nov 26 16:58:41 2022 +0100 1.3 @@ -114,19 +114,37 @@ 1.4 * Iterator over the key/value pairs. 1.5 */ 1.6 __attribute__((__nonnull__, __warn_unused_result__)) 1.7 - CxIterator (*iterator)(CxMap *map); 1.8 + CxIterator (*iterator)(CxMap const *map); 1.9 1.10 /** 1.11 * Iterator over the keys. 1.12 */ 1.13 __attribute__((__nonnull__, __warn_unused_result__)) 1.14 - CxIterator (*iterator_keys)(CxMap *map); 1.15 + CxIterator (*iterator_keys)(CxMap const *map); 1.16 1.17 /** 1.18 * Iterator over the values. 1.19 */ 1.20 __attribute__((__nonnull__, __warn_unused_result__)) 1.21 - CxIterator (*iterator_values)(CxMap *map); 1.22 + CxIterator (*iterator_values)(CxMap const *map); 1.23 + 1.24 + /** 1.25 + * Mutating iterator over the key/value pairs. 1.26 + */ 1.27 + __attribute__((__nonnull__, __warn_unused_result__)) 1.28 + CxMutIterator (*mut_iterator)(CxMap *map); 1.29 + 1.30 + /** 1.31 + * Mutating iterator over the keys. 1.32 + */ 1.33 + __attribute__((__nonnull__, __warn_unused_result__)) 1.34 + CxMutIterator (*mut_iterator_keys)(CxMap *map); 1.35 + 1.36 + /** 1.37 + * Mutating iterator over the values. 1.38 + */ 1.39 + __attribute__((__nonnull__, __warn_unused_result__)) 1.40 + CxMutIterator (*mut_iterator_values)(CxMap *map); 1.41 }; 1.42 1.43 /** 1.44 @@ -263,6 +281,55 @@ 1.45 return map->cl->iterator(map); 1.46 } 1.47 1.48 + 1.49 +/** 1.50 + * Creates a mutating iterator over the values of a map. 1.51 + * 1.52 + * \note An iterator iterates over all elements successively. Therefore the order 1.53 + * highly depends on the map implementation and may change arbitrarily when the contents change. 1.54 + * 1.55 + * @param map the map to create the iterator for 1.56 + * @return an iterator for the currently stored values 1.57 + */ 1.58 +__attribute__((__nonnull__, __warn_unused_result__)) 1.59 +static inline CxMutIterator cxMapMutIteratorValues(CxMap *map) { 1.60 + return map->cl->mut_iterator_values(map); 1.61 +} 1.62 + 1.63 +/** 1.64 + * Creates a mutating iterator over the keys of a map. 1.65 + * 1.66 + * The elements of the iterator are keys of type CxHashKey. 1.67 + * 1.68 + * \note An iterator iterates over all elements successively. Therefore the order 1.69 + * highly depends on the map implementation and may change arbitrarily when the contents change. 1.70 + * 1.71 + * @param map the map to create the iterator for 1.72 + * @return an iterator for the currently stored keys 1.73 + */ 1.74 +__attribute__((__nonnull__, __warn_unused_result__)) 1.75 +static inline CxMutIterator cxMapMutIteratorKeys(CxMap *map) { 1.76 + return map->cl->mut_iterator_keys(map); 1.77 +} 1.78 + 1.79 +/** 1.80 + * Creates a mutating iterator for a map. 1.81 + * 1.82 + * The elements of the iterator are key/value pairs of type CxMapEntry. 1.83 + * 1.84 + * \note An iterator iterates over all elements successively. Therefore the order 1.85 + * highly depends on the map implementation and may change arbitrarily when the contents change. 1.86 + * 1.87 + * @param map the map to create the iterator for 1.88 + * @return an iterator for the currently stored entries 1.89 + * @see cxMapMutIteratorKeys() 1.90 + * @see cxMapMutIteratorValues() 1.91 + */ 1.92 +__attribute__((__nonnull__, __warn_unused_result__)) 1.93 +static inline CxMutIterator cxMapMutIterator(CxMap *map) { 1.94 + return map->cl->mut_iterator(map); 1.95 +} 1.96 + 1.97 #ifdef __cplusplus 1.98 } 1.99 #endif