ucx/cx/map.h

changeset 750
4d7a2238c5ac
parent 747
efbd59642577
child 775
e5909dff0dbf
--- a/ucx/cx/map.h	Sun May 21 11:52:06 2023 +0200
+++ b/ucx/cx/map.h	Sun May 21 16:34:58 2023 +0200
@@ -63,6 +63,24 @@
 };
 
 /**
+ * The type of iterator for a map.
+ */
+enum cx_map_iterator_type {
+    /**
+     * Iterates over key/value pairs.
+     */
+    CX_MAP_ITERATOR_PAIRS,
+    /**
+     * Iterates over keys only.
+     */
+    CX_MAP_ITERATOR_KEYS,
+    /**
+     * Iterates over values only.
+     */
+    CX_MAP_ITERATOR_VALUES
+};
+
+/**
  * The class definition for arbitrary maps.
  */
 struct cx_map_class_s {
@@ -108,40 +126,10 @@
     );
 
     /**
-     * Iterator over the key/value pairs.
-     */
-    __attribute__((__nonnull__, __warn_unused_result__))
-    CxIterator (*iterator)(CxMap const *map);
-
-    /**
-     * Iterator over the keys.
-     */
-    __attribute__((__nonnull__, __warn_unused_result__))
-    CxIterator (*iterator_keys)(CxMap const *map);
-
-    /**
-     * Iterator over the values.
+     * Creates an iterator for this map.
      */
     __attribute__((__nonnull__, __warn_unused_result__))
-    CxIterator (*iterator_values)(CxMap const *map);
-
-    /**
-     * Mutating iterator over the key/value pairs.
-     */
-    __attribute__((__nonnull__, __warn_unused_result__))
-    CxMutIterator (*mut_iterator)(CxMap *map);
-
-    /**
-     * Mutating iterator over the keys.
-     */
-    __attribute__((__nonnull__, __warn_unused_result__))
-    CxMutIterator (*mut_iterator_keys)(CxMap *map);
-
-    /**
-     * Mutating iterator over the values.
-     */
-    __attribute__((__nonnull__, __warn_unused_result__))
-    CxMutIterator (*mut_iterator_values)(CxMap *map);
+    CxIterator (*iterator)(CxMap const *map, enum cx_map_iterator_type type);
 };
 
 /**
@@ -158,6 +146,8 @@
     void *value;
 };
 
+extern CxMap *const cxEmptyMap;
+
 /**
  * Advises the map to store copies of the objects (default mode of operation).
  *
@@ -225,8 +215,8 @@
  * @return an iterator for the currently stored values
  */
 __attribute__((__nonnull__, __warn_unused_result__))
-static inline CxIterator cxMapIteratorValues(CxMap *map) {
-    return map->cl->iterator_values(map);
+static inline CxIterator cxMapIteratorValues(CxMap const *map) {
+    return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);
 }
 
 /**
@@ -241,8 +231,8 @@
  * @return an iterator for the currently stored keys
  */
 __attribute__((__nonnull__, __warn_unused_result__))
-static inline CxIterator cxMapIteratorKeys(CxMap *map) {
-    return map->cl->iterator_keys(map);
+static inline CxIterator cxMapIteratorKeys(CxMap const *map) {
+    return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);
 }
 
 /**
@@ -259,8 +249,8 @@
  * @see cxMapIteratorValues()
  */
 __attribute__((__nonnull__, __warn_unused_result__))
-static inline CxIterator cxMapIterator(CxMap *map) {
-    return map->cl->iterator(map);
+static inline CxIterator cxMapIterator(CxMap const *map) {
+    return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);
 }
 
 
@@ -274,9 +264,7 @@
  * @return an iterator for the currently stored values
  */
 __attribute__((__nonnull__, __warn_unused_result__))
-static inline CxMutIterator cxMapMutIteratorValues(CxMap *map) {
-    return map->cl->mut_iterator_values(map);
-}
+CxMutIterator cxMapMutIteratorValues(CxMap *map);
 
 /**
  * Creates a mutating iterator over the keys of a map.
@@ -290,9 +278,7 @@
  * @return an iterator for the currently stored keys
  */
 __attribute__((__nonnull__, __warn_unused_result__))
-static inline CxMutIterator cxMapMutIteratorKeys(CxMap *map) {
-    return map->cl->mut_iterator_keys(map);
-}
+CxMutIterator cxMapMutIteratorKeys(CxMap *map);
 
 /**
  * Creates a mutating iterator for a map.
@@ -308,9 +294,7 @@
  * @see cxMapMutIteratorValues()
  */
 __attribute__((__nonnull__, __warn_unused_result__))
-static inline CxMutIterator cxMapMutIterator(CxMap *map) {
-    return map->cl->mut_iterator(map);
-}
+CxMutIterator cxMapMutIterator(CxMap *map);
 
 #ifdef __cplusplus
 } // end the extern "C" block here, because we want to start overloading

mercurial