src/cx/hash_map.h

changeset 669
dce9b8450656
parent 658
56c62780582e
child 677
b09aae58bba4
equal deleted inserted replaced
668:d7129285ac32 669:dce9b8450656
68 /** 68 /**
69 * Creates a new hash map with the specified number of buckets. 69 * Creates a new hash map with the specified number of buckets.
70 * 70 *
71 * If \p buckets is zero, an implementation defined default will be used. 71 * If \p buckets is zero, an implementation defined default will be used.
72 * 72 *
73 * If \p itemsize is CX_STORE_POINTERS, the created map will be created as if
74 * cxMapStorePointers() was called immediately after creation.
75 *
73 * @note Iterators provided by this hash map implementation provide the remove operation. 76 * @note Iterators provided by this hash map implementation provide the remove operation.
74 * The index value of an iterator is the incremented when the iterator advanced without removal. 77 * The index value of an iterator is the incremented when the iterator advanced without removal.
75 * In other words, when the iterator is finished, \c index==size . 78 * In other words, when the iterator is finished, \c index==size .
76 * 79 *
77 * @param allocator the allocator to use 80 * @param allocator the allocator to use
83 CxMap *cxHashMapCreate( 86 CxMap *cxHashMapCreate(
84 CxAllocator *allocator, 87 CxAllocator *allocator,
85 size_t itemsize, 88 size_t itemsize,
86 size_t buckets 89 size_t buckets
87 ); 90 );
88
89 /**
90 * Convenience function for creating a hash map that is storing pointers.
91 *
92 * If \p buckets is zero, an implementation defined default will be used.
93 *
94 * @param allocator the allocator to use
95 * @param buckets the initial number of buckets in this hash map
96 * @return a pointer to the new hash map
97 */
98 __attribute__((__nonnull__, __warn_unused_result__))
99 static inline CxMap *cxHashMapCreateForPointers(
100 CxAllocator *allocator,
101 size_t buckets
102 ) {
103 CxMap *map = cxHashMapCreate(allocator, sizeof(void *), buckets);
104 if (map != NULL) {
105 map->store_pointers = true;
106 }
107 return map;
108 }
109 91
110 /** 92 /**
111 * Increases the number of buckets, if necessary. 93 * Increases the number of buckets, if necessary.
112 * 94 *
113 * The load threshold is \c 0.75*buckets. If the element count exceeds the load 95 * The load threshold is \c 0.75*buckets. If the element count exceeds the load

mercurial