Sat, 08 Nov 2025 23:06:11 +0100
update ucx
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
| 852 | 29 | * @file hash_key.h |
| 30 | * @brief Interface for map implementations. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #ifndef UCX_HASH_KEY_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #define UCX_HASH_KEY_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include "common.h" |
| 852 | 41 | #include "string.h" |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | #ifdef __cplusplus |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | extern "C" { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | #endif |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | /** Internal structure for a key within a hash map. */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | struct cx_hash_key_s { |
| 888 | 49 | /** |
| 50 | * The key data. | |
| 51 | * May be NULL when the hash is collision-free. | |
| 52 | */ | |
| 852 | 53 | const void *data; |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | * The key data length. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | size_t len; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | /** The hash value of the key data. */ |
| 888 | 59 | uint64_t hash; |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | }; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | * Type for a hash key. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | typedef struct cx_hash_key_s CxHashKey; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | /** |
| 852 | 68 | * Computes a murmur2 32-bit hash. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | * |
| 852 | 70 | * You need to initialize @c data and @c len in the key struct. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | * The hash is then directly written to that struct. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | * |
| 852 | 73 | * Usually you should not need this function. |
| 74 | * Use cx_hash_key(), instead. | |
| 75 | * | |
| 76 | * @note If @c data is @c NULL, the hash is defined as 1574210520. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | * @param key the key, the hash shall be computed for |
| 852 | 79 | * @see cx_hash_key() |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | */ |
| 852 | 81 | cx_attr_nonnull |
| 888 | 82 | CX_EXPORT void cx_hash_murmur(CxHashKey *key); |
| 83 | ||
| 84 | /** | |
| 85 | * Mixes up a 32-bit integer to be used as a hash. | |
| 86 | * | |
| 87 | * This function produces no collisions and has a good statistical distribution. | |
| 88 | * | |
| 89 | * @param x the integer | |
| 90 | * @return the hash | |
| 91 | */ | |
| 92 | CX_EXPORT uint32_t cx_hash_u32(uint32_t x); | |
| 93 | ||
| 94 | /** | |
| 95 | * Mixes up a 64-bit integer to be used as a hash. | |
| 96 | * | |
| 97 | * This function produces no collisions and has a good statistical distribution. | |
| 98 | * | |
| 99 | * @param x the integer | |
| 100 | * @return the hash | |
| 101 | */ | |
| 102 | CX_EXPORT uint64_t cx_hash_u64(uint64_t x); | |
| 103 | ||
| 104 | /** | |
| 105 | * Computes a hash key from a 32-bit integer. | |
| 106 | * | |
| 107 | * @param x the integer | |
| 108 | * @return the hash key | |
| 109 | */ | |
| 110 | cx_attr_nodiscard | |
| 111 | CX_EXPORT CxHashKey cx_hash_key_u32(uint32_t x); | |
| 112 | ||
| 113 | /** | |
| 114 | * Computes a hash key from a 64-bit integer. | |
| 115 | * | |
| 116 | * @param x the integer | |
| 117 | * @return the hash key | |
| 118 | */ | |
| 119 | cx_attr_nodiscard | |
| 120 | CX_EXPORT CxHashKey cx_hash_key_u64(uint64_t x); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | * Computes a hash key from a string. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | * The string needs to be zero-terminated. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | * @param str the string |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | * @return the hash key |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | */ |
| 888 | 130 | cx_attr_nodiscard cx_attr_cstr_arg(1) |
| 131 | CX_EXPORT CxHashKey cx_hash_key_str(const char *str); | |
| 132 | ||
| 133 | /** | |
| 134 | * Computes a hash key from a string. | |
| 135 | * | |
| 136 | * Use this function when the string is represented | |
| 137 | * as an unsigned char array. | |
| 138 | * | |
| 139 | * The string needs to be zero-terminated. | |
| 140 | * | |
| 141 | * @param str the string | |
| 142 | * @return the hash key | |
| 143 | */ | |
| 144 | cx_attr_nodiscard cx_attr_cstr_arg(1) | |
| 145 | CX_EXPORT CxHashKey cx_hash_key_ustr(const unsigned char *str); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | * Computes a hash key from a byte array. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | * @param bytes the array |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | * @param len the length |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | * @return the hash key |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | */ |
| 888 | 154 | cx_attr_nodiscard cx_attr_access_r(1, 2) |
| 155 | CX_EXPORT CxHashKey cx_hash_key_bytes(const unsigned char *bytes, size_t len); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | * Computes a hash key for an arbitrary object. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | * The computation uses the in-memory representation that might not be |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | * the same on different platforms. Therefore, this hash should not be |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | * used for data exchange with different machines. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | * @param obj a pointer to an arbitrary object |
| 888 | 165 | * @param len the length of the object in memory |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | * @return the hash key |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | */ |
| 852 | 168 | cx_attr_nodiscard |
| 169 | cx_attr_access_r(1, 2) | |
| 888 | 170 | CX_EXPORT CxHashKey cx_hash_key(const void *obj, size_t len); |
| 171 | ||
| 172 | /** | |
| 173 | * Computes a hash key from a UCX string. | |
| 174 | * | |
| 175 | * @param str the string | |
| 176 | * @return the hash key | |
| 177 | */ | |
| 178 | cx_attr_nodiscard | |
| 179 | CX_EXPORT CxHashKey cx_hash_key_cxstr(cxstring str); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | * Computes a hash key from a UCX string. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | * @param str the string |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | * @return the hash key |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | */ |
| 852 | 187 | cx_attr_nodiscard |
| 888 | 188 | CX_EXPORT CxHashKey cx_hash_key_mutstr(cxmutstr str); |
| 852 | 189 | |
| 190 | /** | |
| 888 | 191 | * The identity function for the CX_HASH_KEY() macro. |
| 192 | * You should never need to use this manually. | |
| 193 | * | |
| 194 | * @param key the key | |
| 195 | * @return a copy of the key | |
| 196 | */ | |
| 197 | cx_attr_nodiscard | |
| 198 | CX_INLINE CxHashKey cx_hash_key_identity(CxHashKey key) { | |
| 199 | return key; | |
| 200 | } | |
| 201 | ||
| 202 | #ifndef __cplusplus | |
| 203 | /** | |
| 204 | * Creates a hash key from any of the supported types with implicit length. | |
| 205 | * | |
| 206 | * Does nothing when passing a CxHashkey. | |
| 207 | * | |
| 208 | * Supported types are UCX strings, zero-terminated C strings, | |
| 209 | * and 32-bit or 64-bit unsigned integers. | |
| 852 | 210 | * |
| 888 | 211 | * @param key the key data |
| 212 | * @returns the @c CxHashKey | |
| 852 | 213 | */ |
| 888 | 214 | #define CX_HASH_KEY(key) _Generic((key), \ |
| 215 | CxHashKey: cx_hash_key_identity, \ | |
| 216 | cxstring: cx_hash_key_cxstr, \ | |
| 217 | cxmutstr: cx_hash_key_mutstr, \ | |
| 218 | char*: cx_hash_key_str, \ | |
| 219 | const char*: cx_hash_key_str, \ | |
| 220 | unsigned char*: cx_hash_key_ustr, \ | |
| 221 | const unsigned char*: cx_hash_key_ustr, \ | |
| 222 | uint32_t: cx_hash_key_u32, \ | |
| 223 | uint64_t: cx_hash_key_u64) \ | |
| 224 | (key) | |
| 225 | #endif // __cplusplus | |
| 226 | ||
| 227 | /** | |
| 228 | * Compare function for hash keys. | |
| 229 | * | |
| 230 | * The pointers are untyped to be compatible with the cx_compare_func signature. | |
| 231 | * | |
| 232 | * @param left (@c CxHashKey*) the first key | |
| 233 | * @param right (@c CxHashKey*) the second key | |
| 234 | * @return zero when the keys equal, non-zero when they differ | |
| 235 | */ | |
| 236 | cx_attr_nodiscard cx_attr_nonnull | |
| 237 | CX_EXPORT int cx_hash_key_cmp(const void *left, const void *right); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | #ifdef __cplusplus |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | } // extern "C" |
| 888 | 241 | |
| 242 | // ---------------------------------------------------------- | |
| 243 | // Overloads of CX_HASH_KEY (the C++ version of a _Generic) | |
| 244 | // ---------------------------------------------------------- | |
| 245 | ||
| 246 | CX_CPPDECL CxHashKey CX_HASH_KEY(CxHashKey key) { | |
| 247 | return key; | |
| 248 | } | |
| 249 | ||
| 250 | CX_CPPDECL CxHashKey CX_HASH_KEY(cxstring str) { | |
| 251 | return cx_hash_key_cxstr(str); | |
| 252 | } | |
| 253 | ||
| 254 | CX_CPPDECL CxHashKey CX_HASH_KEY(cxmutstr str) { | |
| 255 | return cx_hash_key_mutstr(str); | |
| 256 | } | |
| 257 | ||
| 258 | CX_CPPDECL CxHashKey CX_HASH_KEY(const char *str) { | |
| 259 | return cx_hash_key_str(str); | |
| 260 | } | |
| 261 | ||
| 262 | CX_CPPDECL CxHashKey CX_HASH_KEY(const unsigned char *str) { | |
| 263 | return cx_hash_key_ustr(str); | |
| 264 | } | |
| 265 | ||
| 266 | CX_CPPDECL CxHashKey CX_HASH_KEY(uint32_t key) { | |
| 267 | return cx_hash_key_u32(key); | |
| 268 | } | |
| 269 | ||
| 270 | CX_CPPDECL CxHashKey CX_HASH_KEY(uint64_t key) { | |
| 271 | return cx_hash_key_u64(key); | |
| 272 | } | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | #endif |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | #endif // UCX_HASH_KEY_H |