42 #ifdef __cplusplus |
42 #ifdef __cplusplus |
43 extern "C" { |
43 extern "C" { |
44 #endif |
44 #endif |
45 |
45 |
46 /** Internal structure for an element of a hash map. */ |
46 /** Internal structure for an element of a hash map. */ |
47 struct cx_hash_map_element_s { |
47 struct cx_hash_map_element_s; |
48 /** The value data. */ |
|
49 void *data; |
|
50 |
|
51 /** A pointer to the next element in the current bucket. */ |
|
52 struct cx_hash_map_element_s *next; |
|
53 |
|
54 /** The corresponding key. */ |
|
55 CxHashKey key; |
|
56 }; |
|
57 |
48 |
58 /** |
49 /** |
59 * Internal structure for a hash map. |
50 * Internal structure for a hash map. |
60 */ |
51 */ |
61 struct cx_hash_map_s { |
52 struct cx_hash_map_s { |
77 /** |
68 /** |
78 * Creates a new hash map with the specified number of buckets. |
69 * Creates a new hash map with the specified number of buckets. |
79 * |
70 * |
80 * 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. |
81 * |
72 * |
|
73 * If \p item_size is CX_STORE_POINTERS, the created map will be created as if |
|
74 * cxMapStorePointers() was called immediately after creation. |
|
75 * |
82 * @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. |
83 * 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. |
84 * In other words, when the iterator is finished, \c index==size . |
78 * In other words, when the iterator is finished, \c index==size . |
85 * |
79 * |
86 * @param allocator the allocator to use |
80 * @param allocator the allocator to use |
|
81 * @param itemsize the size of one element |
87 * @param buckets the initial number of buckets in this hash map |
82 * @param buckets the initial number of buckets in this hash map |
88 * @return a pointer to the new hash map |
83 * @return a pointer to the new hash map |
89 */ |
84 */ |
90 __attribute__((__nonnull__, __warn_unused_result__)) |
85 __attribute__((__nonnull__, __warn_unused_result__)) |
91 CxMap *cxHashMapCreate( |
86 CxMap *cxHashMapCreate( |
92 CxAllocator *allocator, |
87 CxAllocator const *allocator, |
|
88 size_t itemsize, |
93 size_t buckets |
89 size_t buckets |
94 ); |
90 ); |
|
91 |
|
92 /** |
|
93 * Creates a new hash map with a default number of buckets. |
|
94 * |
|
95 * If \p item_size is CX_STORE_POINTERS, the created map will be created as if |
|
96 * cxMapStorePointers() was called immediately after creation. |
|
97 * |
|
98 * @note Iterators provided by this hash map implementation provide the remove operation. |
|
99 * The index value of an iterator is the incremented when the iterator advanced without removal. |
|
100 * In other words, when the iterator is finished, \c index==size . |
|
101 * |
|
102 * @param itemsize the size of one element |
|
103 * @return a pointer to the new hash map |
|
104 */ |
|
105 #define cxHashMapCreateSimple(itemsize) \ |
|
106 cxHashMapCreate(cxDefaultAllocator, itemsize, 0) |
95 |
107 |
96 /** |
108 /** |
97 * Increases the number of buckets, if necessary. |
109 * Increases the number of buckets, if necessary. |
98 * |
110 * |
99 * The load threshold is \c 0.75*buckets. If the element count exceeds the load |
111 * The load threshold is \c 0.75*buckets. If the element count exceeds the load |