Wed, 24 Dec 2025 12:13:59 +0100
enable inline optimizations when creating hash keys from literals
| 563 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * | |
| 4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * | |
| 9 | * 1. Redistributions of source code must retain the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer. | |
| 11 | * | |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 | * notice, this list of conditions and the following disclaimer in the | |
| 14 | * documentation and/or other materials provided with the distribution. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | * POSSIBILITY OF SUCH DAMAGE. | |
| 27 | */ | |
| 28 | /** | |
|
1094
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
29 | * @file hash_key.h |
|
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
30 | * @brief Interface for map implementations. |
|
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
31 | * @author Mike Becker |
|
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
32 | * @author Olaf Wintermann |
|
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
33 | * @copyright 2-Clause BSD License |
| 563 | 34 | */ |
| 35 | ||
| 36 | ||
| 37 | #ifndef UCX_HASH_KEY_H | |
| 38 | #define UCX_HASH_KEY_H | |
| 39 | ||
|
681
502105523db7
fix common.h include problems - fixes #255
Mike Becker <universe@uap-core.de>
parents:
663
diff
changeset
|
40 | #include "common.h" |
|
1049
415bf2ce6bab
fix cx_hash_key_cxstr() being a macro
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
41 | #include "string.h" |
| 563 | 42 | |
| 43 | #ifdef __cplusplus | |
| 44 | extern "C" { | |
| 45 | #endif | |
| 46 | ||
| 47 | /** Internal structure for a key within a hash map. */ | |
| 48 | struct cx_hash_key_s { | |
|
1400
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
49 | /** |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
50 | * The key data. |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
51 | * May be NULL when the hash is collision-free. |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
52 | */ |
|
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
53 | const void *data; |
| 563 | 54 | /** |
| 55 | * The key data length. | |
| 56 | */ | |
| 57 | size_t len; | |
| 58 | /** The hash value of the key data. */ | |
|
1400
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
59 | uint64_t hash; |
| 563 | 60 | }; |
| 61 | ||
| 62 | /** | |
| 63 | * Type for a hash key. | |
| 64 | */ | |
| 65 | typedef struct cx_hash_key_s CxHashKey; | |
| 66 | ||
| 67 | /** | |
|
1094
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
68 | * Computes a murmur2 32-bit hash. |
| 563 | 69 | * |
|
1094
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
70 | * You need to initialize @c data and @c len in the key struct. |
| 563 | 71 | * The hash is then directly written to that struct. |
| 72 | * | |
|
1094
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
73 | * Usually you should not need this function. |
|
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
74 | * Use cx_hash_key(), instead. |
|
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
75 | * |
|
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
76 | * @note If @c data is @c NULL, the hash is defined as 1574210520. |
| 604 | 77 | * |
| 563 | 78 | * @param key the key, the hash shall be computed for |
|
1094
aea6f31a82d7
refine docs for hash_key.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1050
diff
changeset
|
79 | * @see cx_hash_key() |
| 563 | 80 | */ |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
81 | cx_attr_nonnull |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
82 | CX_EXPORT void cx_hash_murmur(CxHashKey *key); |
| 563 | 83 | |
| 84 | /** | |
|
1400
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
85 | * Mixes up a 32-bit integer to be used as a hash. |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
86 | * |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
87 | * This function produces no collisions and has a good statistical distribution. |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
88 | * |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
89 | * @param x the integer |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
90 | * @return the hash |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
91 | */ |
|
1665
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
92 | CX_INLINE uint32_t cx_hash_u32(uint32_t x) { |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
93 | x = ((x >> 16) ^ x) * 0x45d9f3bu; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
94 | x = ((x >> 16) ^ x) * 0x45d9f3bu; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
95 | x = (x >> 16) ^ x; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
96 | return x; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
97 | } |
|
1400
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
98 | |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
99 | /** |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
100 | * Mixes up a 64-bit integer to be used as a hash. |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
101 | * |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
102 | * This function produces no collisions and has a good statistical distribution. |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
103 | * |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
104 | * @param x the integer |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
105 | * @return the hash |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
106 | */ |
|
1665
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
107 | CX_INLINE uint64_t cx_hash_u64(uint64_t x){ |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
108 | x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9); |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
109 | x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb); |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
110 | x = x ^ (x >> 31); |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
111 | return x; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
112 | } |
| 563 | 113 | |
| 114 | /** | |
| 115 | * Computes a hash key for an arbitrary object. | |
| 116 | * | |
| 117 | * The computation uses the in-memory representation that might not be | |
| 118 | * the same on different platforms. Therefore, this hash should not be | |
| 119 | * used for data exchange with different machines. | |
| 120 | * | |
| 121 | * @param obj a pointer to an arbitrary object | |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1403
diff
changeset
|
122 | * @param len the length of the object in memory |
| 563 | 123 | * @return the hash key |
| 124 | */ | |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
125 | cx_attr_nodiscard |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
126 | cx_attr_access_r(1, 2) |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
127 | CX_EXPORT CxHashKey cx_hash_key(const void *obj, size_t len); |
| 563 | 128 | |
|
663
d50b5dc1e058
add cx_hash_key_cxstr() macro
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
129 | /** |
|
1665
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
130 | * Computes a hash key from a 32-bit integer. |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
131 | * |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
132 | * @param x the integer |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
133 | * @return the hash key |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
134 | */ |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
135 | cx_attr_nodiscard |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
136 | CX_INLINE CxHashKey cx_hash_key_u32(uint32_t x) { |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
137 | CxHashKey key; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
138 | key.data = NULL; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
139 | key.len = 0; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
140 | key.hash = cx_hash_u32(x); |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
141 | return key; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
142 | } |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
143 | |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
144 | /** |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
145 | * Computes a hash key from a 64-bit integer. |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
146 | * |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
147 | * @param x the integer |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
148 | * @return the hash key |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
149 | */ |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
150 | cx_attr_nodiscard |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
151 | CX_INLINE CxHashKey cx_hash_key_u64(uint64_t x) { |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
152 | CxHashKey key; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
153 | key.data = NULL; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
154 | key.len = 0; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
155 | key.hash = cx_hash_u64(x); |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
156 | return key; |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
157 | } |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
158 | |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
159 | /** |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
160 | * Computes a hash key from a string. |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
161 | * |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
162 | * The string needs to be zero-terminated. |
|
663
d50b5dc1e058
add cx_hash_key_cxstr() macro
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
163 | * |
|
d50b5dc1e058
add cx_hash_key_cxstr() macro
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
164 | * @param str the string |
|
d50b5dc1e058
add cx_hash_key_cxstr() macro
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
165 | * @return the hash key |
|
d50b5dc1e058
add cx_hash_key_cxstr() macro
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
166 | */ |
|
1665
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
167 | cx_attr_nodiscard cx_attr_cstr_arg(1) |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
168 | CX_INLINE CxHashKey cx_hash_key_str(const char *str) { |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
169 | return cx_hash_key((const void*)str, str == NULL ? 0 : strlen(str)); |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
170 | } |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
171 | |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
172 | /** |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
173 | * Computes a hash key from a string. |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
174 | * |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
175 | * Use this function when the string is represented |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
176 | * as an unsigned char array. |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
177 | * |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
178 | * The string needs to be zero-terminated. |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
179 | * |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
180 | * @param str the string |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
181 | * @return the hash key |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
182 | */ |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
183 | cx_attr_nodiscard cx_attr_cstr_arg(1) |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
184 | CX_INLINE CxHashKey cx_hash_key_ustr(const unsigned char *str) { |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
185 | return cx_hash_key((const void*)str, str == NULL ? 0 : strlen((const char*)str)); |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
186 | } |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
187 | |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
188 | /** |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
189 | * Computes a hash key from a byte array. |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
190 | * |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
191 | * @param bytes the array |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
192 | * @param len the length |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
193 | * @return the hash key |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
194 | */ |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
195 | cx_attr_nodiscard cx_attr_access_r(1, 2) |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
196 | CX_INLINE CxHashKey cx_hash_key_bytes(const unsigned char *bytes, size_t len) { |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
197 | return cx_hash_key((const void*)bytes, len); |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
198 | } |
|
1049
415bf2ce6bab
fix cx_hash_key_cxstr() being a macro
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
199 | |
|
415bf2ce6bab
fix cx_hash_key_cxstr() being a macro
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
200 | /** |
|
1050
3df63e95921a
make cx_strcast() also support cxstring
Mike Becker <universe@uap-core.de>
parents:
1049
diff
changeset
|
201 | * Computes a hash key from a UCX string. |
|
3df63e95921a
make cx_strcast() also support cxstring
Mike Becker <universe@uap-core.de>
parents:
1049
diff
changeset
|
202 | * |
|
1402
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
203 | * @param str the string |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
204 | * @return the hash key |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
205 | */ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
206 | cx_attr_nodiscard |
|
1665
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
207 | CX_INLINE CxHashKey cx_hash_key_cxstr(cxstring str) { |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
208 | return cx_hash_key((void*)str.ptr, str.length); |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
209 | } |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
210 | |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
211 | /** |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
212 | * Computes a hash key from a UCX string. |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
213 | * |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
214 | * @param str the string |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
215 | * @return the hash key |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
216 | */ |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
217 | cx_attr_nodiscard |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
218 | CX_INLINE CxHashKey cx_hash_key_mutstr(cxmutstr str) { |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
219 | return cx_hash_key((void*)str.ptr, str.length); |
|
b79405fbf91d
enable inline optimizations when creating hash keys from literals
Mike Becker <universe@uap-core.de>
parents:
1664
diff
changeset
|
220 | } |
|
1402
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
221 | |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
222 | /** |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
223 | * The identity function for the CX_HASH_KEY() macro. |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
224 | * You should never need to use this manually. |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
225 | * |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
226 | * @param key the key |
|
1664
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
227 | * @return a copy of the key (not the data) |
|
1402
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
228 | */ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
229 | cx_attr_nodiscard |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
230 | CX_INLINE CxHashKey cx_hash_key_identity(CxHashKey key) { |
|
1402
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
231 | return key; |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
232 | } |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
233 | |
|
1664
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
234 | /** |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
235 | * The dereference function for the CX_HASH_KEY() macro. |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
236 | * You should never need to use this manually. |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
237 | * |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
238 | * @param key a pointer to a key |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
239 | * @return a copy of the key (not the data) |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
240 | */ |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
241 | cx_attr_nodiscard |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
242 | CX_INLINE CxHashKey cx_hash_key_deref(const CxHashKey *key) { |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
243 | return *key; |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
244 | } |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
245 | |
|
1403
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
246 | #ifndef __cplusplus |
|
1402
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
247 | /** |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
248 | * Creates a hash key from any of the supported types with implicit length. |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
249 | * |
|
1664
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
250 | * Does nothing when passing a CxHashKey and dereferences CxHashKey pointers. |
|
1402
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
251 | * |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
252 | * Supported types are UCX strings, zero-terminated C strings, |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
253 | * and 32-bit or 64-bit unsigned integers. |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
254 | * |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
255 | * @param key the key data |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
256 | * @returns the @c CxHashKey |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
257 | */ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
258 | #define CX_HASH_KEY(key) _Generic((key), \ |
|
1664
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
259 | CxHashKey*: cx_hash_key_deref, \ |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
260 | const CxHashKey*: cx_hash_key_deref, \ |
|
1402
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
261 | CxHashKey: cx_hash_key_identity, \ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
262 | cxstring: cx_hash_key_cxstr, \ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
263 | cxmutstr: cx_hash_key_mutstr, \ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
264 | char*: cx_hash_key_str, \ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
265 | const char*: cx_hash_key_str, \ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
266 | unsigned char*: cx_hash_key_ustr, \ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
267 | const unsigned char*: cx_hash_key_ustr, \ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
268 | uint32_t: cx_hash_key_u32, \ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
269 | uint64_t: cx_hash_key_u64) \ |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
270 | (key) |
|
1403
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
271 | #endif // __cplusplus |
|
1402
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
272 | |
|
6fa42f7e2624
add generic CX_HASH_KEY() macro
Mike Becker <universe@uap-core.de>
parents:
1400
diff
changeset
|
273 | /** |
|
1400
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
274 | * Compare function for hash keys. |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
275 | * |
|
1448
0f0fe7311b76
add tests for cxMapDifference() and cxMapListDifference()
Mike Becker <universe@uap-core.de>
parents:
1426
diff
changeset
|
276 | * The pointers are untyped to be compatible with the cx_compare_func signature. |
|
0f0fe7311b76
add tests for cxMapDifference() and cxMapListDifference()
Mike Becker <universe@uap-core.de>
parents:
1426
diff
changeset
|
277 | * |
|
0f0fe7311b76
add tests for cxMapDifference() and cxMapListDifference()
Mike Becker <universe@uap-core.de>
parents:
1426
diff
changeset
|
278 | * @param left (@c CxHashKey*) the first key |
|
0f0fe7311b76
add tests for cxMapDifference() and cxMapListDifference()
Mike Becker <universe@uap-core.de>
parents:
1426
diff
changeset
|
279 | * @param right (@c CxHashKey*) the second key |
|
1400
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
280 | * @return zero when the keys equal, non-zero when they differ |
|
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
281 | */ |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
282 | cx_attr_nodiscard cx_attr_nonnull |
|
1448
0f0fe7311b76
add tests for cxMapDifference() and cxMapListDifference()
Mike Becker <universe@uap-core.de>
parents:
1426
diff
changeset
|
283 | CX_EXPORT int cx_hash_key_cmp(const void *left, const void *right); |
|
1400
7bc88ae62755
add support for integer keys - resolves #720
Mike Becker <universe@uap-core.de>
parents:
1180
diff
changeset
|
284 | |
|
1653
6a842bd49fea
adds cx_hash_key_as_string()
Mike Becker <universe@uap-core.de>
parents:
1448
diff
changeset
|
285 | /** |
|
6a842bd49fea
adds cx_hash_key_as_string()
Mike Becker <universe@uap-core.de>
parents:
1448
diff
changeset
|
286 | * Interprets the key data as a string and returns it. |
|
6a842bd49fea
adds cx_hash_key_as_string()
Mike Becker <universe@uap-core.de>
parents:
1448
diff
changeset
|
287 | * |
|
6a842bd49fea
adds cx_hash_key_as_string()
Mike Becker <universe@uap-core.de>
parents:
1448
diff
changeset
|
288 | * @param key the key |
|
6a842bd49fea
adds cx_hash_key_as_string()
Mike Becker <universe@uap-core.de>
parents:
1448
diff
changeset
|
289 | * @return the key data as a string |
|
6a842bd49fea
adds cx_hash_key_as_string()
Mike Becker <universe@uap-core.de>
parents:
1448
diff
changeset
|
290 | */ |
|
6a842bd49fea
adds cx_hash_key_as_string()
Mike Becker <universe@uap-core.de>
parents:
1448
diff
changeset
|
291 | CX_EXPORT cxstring cx_hash_key_as_string(const CxHashKey *key); |
|
6a842bd49fea
adds cx_hash_key_as_string()
Mike Becker <universe@uap-core.de>
parents:
1448
diff
changeset
|
292 | |
|
1050
3df63e95921a
make cx_strcast() also support cxstring
Mike Becker <universe@uap-core.de>
parents:
1049
diff
changeset
|
293 | #ifdef __cplusplus |
|
3df63e95921a
make cx_strcast() also support cxstring
Mike Becker <universe@uap-core.de>
parents:
1049
diff
changeset
|
294 | } // extern "C" |
|
1403
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
295 | |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
296 | // ---------------------------------------------------------- |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
297 | // Overloads of CX_HASH_KEY (the C++ version of a _Generic) |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
298 | // ---------------------------------------------------------- |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
299 | |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
300 | CX_CPPDECL CxHashKey CX_HASH_KEY(CxHashKey key) { |
|
1403
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
301 | return key; |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
302 | } |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
303 | |
|
1664
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
304 | CX_CPPDECL CxHashKey CX_HASH_KEY(const CxHashKey *key) { |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
305 | return *key; |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
306 | } |
|
e5a8c41ecb58
adds support for CxHashKey pointers in CX_HASH_KEY() and all map functions
Mike Becker <universe@uap-core.de>
parents:
1653
diff
changeset
|
307 | |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
308 | CX_CPPDECL CxHashKey CX_HASH_KEY(cxstring str) { |
|
1403
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
309 | return cx_hash_key_cxstr(str); |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
310 | } |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
311 | |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
312 | CX_CPPDECL CxHashKey CX_HASH_KEY(cxmutstr str) { |
|
1403
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
313 | return cx_hash_key_mutstr(str); |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
314 | } |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
315 | |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
316 | CX_CPPDECL CxHashKey CX_HASH_KEY(const char *str) { |
|
1403
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
317 | return cx_hash_key_str(str); |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
318 | } |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
319 | |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
320 | CX_CPPDECL CxHashKey CX_HASH_KEY(const unsigned char *str) { |
|
1403
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
321 | return cx_hash_key_ustr(str); |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
322 | } |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
323 | |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
324 | CX_CPPDECL CxHashKey CX_HASH_KEY(uint32_t key) { |
|
1403
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
325 | return cx_hash_key_u32(key); |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
326 | } |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
327 | |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
328 | CX_CPPDECL CxHashKey CX_HASH_KEY(uint64_t key) { |
|
1403
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
329 | return cx_hash_key_u64(key); |
|
09eca27b27e9
add C++ implementation of CX_HASH_KEY()
Mike Becker <universe@uap-core.de>
parents:
1402
diff
changeset
|
330 | } |
| 563 | 331 | #endif |
| 332 | ||
|
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
604
diff
changeset
|
333 | #endif // UCX_HASH_KEY_H |