src/cx/hash_map.h

changeset 550
89b2a83728b1
parent 549
d7f0b5a9a985
child 559
8603709932b9
equal deleted inserted replaced
549:d7f0b5a9a985 550:89b2a83728b1
44 #endif 44 #endif
45 45
46 /** Internal structure for a key within a hash map. */ 46 /** Internal structure for a key within a hash map. */
47 struct cx_hash_map_key_s { 47 struct cx_hash_map_key_s {
48 /** The key data. */ 48 /** The key data. */
49 CxDataPtr data; 49 unsigned char *data;
50 /**
51 * The key data length.
52 */
53 size_t len;
50 /** The hash value of the key data. */ 54 /** The hash value of the key data. */
51 unsigned hash; 55 unsigned hash;
52 }; 56 };
53 57
54 /** Internal structure for an element of a hash map. */ 58 /** Internal structure for an element of a hash map. */
61 65
62 /** The corresponding key. */ 66 /** The corresponding key. */
63 struct cx_hash_map_key_s key; 67 struct cx_hash_map_key_s key;
64 }; 68 };
65 69
70 /**
71 * Internal structure for a hash map.
72 */
73 struct cx_hash_map_s {
74 /**
75 * Base structure for maps.
76 */
77 struct cx_map_s base;
78 /**
79 * The buckets of this map, each containing a linked list of elements.
80 */
81 struct cx_hash_map_element_s **buckets;
82 /**
83 * The number of buckets.
84 */
85 size_t bucket_count;
86 };
87
66 88
67 /** 89 /**
68 * Creates a new hash map with the specified size using a UcxAllocator. 90 * Creates a new hash map with the specified number of buckets.
91 *
92 * If \p buckets is zero, an implementation defined default will be used.
93 *
94 * @note Iterators provided by this hash map implementation do provide the remove operation, because
95 * a remove never causes an immediate rehashing. The iterators are also position-aware in the sense
96 * that the index is initialized with zero and incremented when the iterator advances.
69 * 97 *
70 * @param allocator the allocator to use 98 * @param allocator the allocator to use
71 * @param buckets the initial number of buckets in this hash map 99 * @param buckets the initial number of buckets in this hash map
72 * @return a pointer to the new hash map 100 * @return a pointer to the new hash map
73 */ 101 */
102 __attribute__((__nonnull__, __warn_unused_result__))
74 CxMap *cxHashMapCreate( 103 CxMap *cxHashMapCreate(
75 CxAllocator *allocator, 104 CxAllocator *allocator,
76 size_t buckets 105 size_t buckets
77 ); 106 );
78 107

mercurial