src/cx/hash_map.h

changeset 658
56c62780582e
parent 563
69a83fad8a35
child 669
dce9b8450656
--- a/src/cx/hash_map.h	Mon Feb 20 19:55:42 2023 +0100
+++ b/src/cx/hash_map.h	Thu Feb 23 18:58:15 2023 +0100
@@ -44,16 +44,7 @@
 #endif
 
 /** Internal structure for an element of a hash map. */
-struct cx_hash_map_element_s {
-    /** The value data. */
-    void *data;
-
-    /** A pointer to the next element in the current bucket. */
-    struct cx_hash_map_element_s *next;
-
-    /** The corresponding key. */
-    CxHashKey key;
-};
+struct cx_hash_map_element_s;
 
 /**
  * Internal structure for a hash map.
@@ -84,16 +75,39 @@
  * In other words, when the iterator is finished, \c index==size .
  *
  * @param allocator the allocator to use
+ * @param itemsize the size of one element
  * @param buckets the initial number of buckets in this hash map
  * @return a pointer to the new hash map
  */
 __attribute__((__nonnull__, __warn_unused_result__))
 CxMap *cxHashMapCreate(
         CxAllocator *allocator,
+        size_t itemsize,
         size_t buckets
 );
 
 /**
+ * Convenience function for creating a hash map that is storing pointers.
+ *
+ * If \p buckets is zero, an implementation defined default will be used.
+ *
+ * @param allocator the allocator to use
+ * @param buckets the initial number of buckets in this hash map
+ * @return a pointer to the new hash map
+ */
+__attribute__((__nonnull__, __warn_unused_result__))
+static inline CxMap *cxHashMapCreateForPointers(
+        CxAllocator *allocator,
+        size_t buckets
+) {
+    CxMap *map = cxHashMapCreate(allocator, sizeof(void *), buckets);
+    if (map != NULL) {
+        map->store_pointers = true;
+    }
+    return map;
+}
+
+/**
  * Increases the number of buckets, if necessary.
  *
  * The load threshold is \c 0.75*buckets. If the element count exceeds the load

mercurial