44 extern "C" { |
44 extern "C" { |
45 #endif |
45 #endif |
46 |
46 |
47 /** Internal structure for a key within a hash map. */ |
47 /** Internal structure for a key within a hash map. */ |
48 struct cx_hash_key_s { |
48 struct cx_hash_key_s { |
49 /** The key data. */ |
49 /** |
|
50 * The key data. |
|
51 * May be NULL when the hash is collision-free. |
|
52 */ |
50 const void *data; |
53 const void *data; |
51 /** |
54 /** |
52 * The key data length. |
55 * The key data length. |
53 */ |
56 */ |
54 size_t len; |
57 size_t len; |
55 /** The hash value of the key data. */ |
58 /** The hash value of the key data. */ |
56 unsigned hash; |
59 uint64_t hash; |
57 }; |
60 }; |
58 |
61 |
59 /** |
62 /** |
60 * Type for a hash key. |
63 * Type for a hash key. |
61 */ |
64 */ |
76 * @see cx_hash_key() |
79 * @see cx_hash_key() |
77 */ |
80 */ |
78 cx_attr_nonnull |
81 cx_attr_nonnull |
79 cx_attr_export |
82 cx_attr_export |
80 void cx_hash_murmur(CxHashKey *key); |
83 void cx_hash_murmur(CxHashKey *key); |
|
84 |
|
85 /** |
|
86 * Mixes up a 32-bit integer to be used as a hash. |
|
87 * |
|
88 * This function produces no collisions and has a good statistical distribution. |
|
89 * |
|
90 * @param x the integer |
|
91 * @return the hash |
|
92 */ |
|
93 cx_attr_export |
|
94 uint32_t cx_hash_u32(uint32_t x); |
|
95 |
|
96 /** |
|
97 * Mixes up a 64-bit integer to be used as a hash. |
|
98 * |
|
99 * This function produces no collisions and has a good statistical distribution. |
|
100 * |
|
101 * @param x the integer |
|
102 * @return the hash |
|
103 */ |
|
104 cx_attr_export |
|
105 uint64_t cx_hash_u64(uint64_t x); |
|
106 |
|
107 /** |
|
108 * Computes a hash key from a 32-bit integer. |
|
109 * |
|
110 * @param x the integer |
|
111 * @return the hash key |
|
112 */ |
|
113 cx_attr_nodiscard |
|
114 cx_attr_export |
|
115 CxHashKey cx_hash_key_u32(uint32_t x); |
|
116 |
|
117 /** |
|
118 * Computes a hash key from a 64-bit integer. |
|
119 * |
|
120 * @param x the integer |
|
121 * @return the hash key |
|
122 */ |
|
123 cx_attr_nodiscard |
|
124 cx_attr_export |
|
125 CxHashKey cx_hash_key_u64(uint64_t x); |
81 |
126 |
82 /** |
127 /** |
83 * Computes a hash key from a string. |
128 * Computes a hash key from a string. |
84 * |
129 * |
85 * The string needs to be zero-terminated. |
130 * The string needs to be zero-terminated. |
143 * @param str (@c cxstring or @c cxmutstr) the string |
188 * @param str (@c cxstring or @c cxmutstr) the string |
144 * @return (@c CxHashKey) the hash key |
189 * @return (@c CxHashKey) the hash key |
145 */ |
190 */ |
146 #define cx_hash_key_cxstr(str) cx_hash_key_cxstr(cx_strcast(str)) |
191 #define cx_hash_key_cxstr(str) cx_hash_key_cxstr(cx_strcast(str)) |
147 |
192 |
|
193 /** |
|
194 * Compare function for hash keys. |
|
195 * |
|
196 * @param left the first key |
|
197 * @param right the second key |
|
198 * @return zero when the keys equal, non-zero when they differ |
|
199 */ |
|
200 cx_attr_nodiscard |
|
201 cx_attr_nonnull |
|
202 cx_attr_export |
|
203 int cx_hash_key_cmp(const CxHashKey *left, const CxHashKey *right); |
|
204 |
148 #ifdef __cplusplus |
205 #ifdef __cplusplus |
149 } // extern "C" |
206 } // extern "C" |
150 #endif |
207 #endif |
151 |
208 |
152 #endif // UCX_HASH_KEY_H |
209 #endif // UCX_HASH_KEY_H |