ucx/cx/hash_key.h

Wed, 31 Dec 2025 16:41:16 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 31 Dec 2025 16:41:16 +0100
branch
dav-2
changeset 894
e86049631677
parent 889
42cdbf9bbd49
permissions
-rw-r--r--

update ucx to version 4.0

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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
29 * @file hash_key.h
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
30 * @brief Interface for map implementations.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
31 * @author Mike Becker
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
32 * @author Olaf Wintermann
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
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 /** 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
44 struct cx_hash_key_s {
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
45 /**
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
46 * The key data.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
47 * May be NULL when the hash is collision-free.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
48 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
49 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
50 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 * 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
52 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 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
54 /** The hash value of the key data. */
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
55 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
56 };
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 * 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
60 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 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
62
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 /**
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
64 * 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
65 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
66 * 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
67 * 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
68 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
69 * Usually you should not need this function.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
70 * Use cx_hash_key(), instead.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
71 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
72 * @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
73 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 * @param key the key, the hash shall be computed for
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
75 * @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
76 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
77 CX_EXTERN CX_NONNULL
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
78 void cx_hash_murmur(CxHashKey *key);
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
79
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
80 /**
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
81 * Mixes up a 32-bit integer to be used as a hash.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
82 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
83 * This function produces no collisions and has a good statistical distribution.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
84 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
85 * @param x the integer
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
86 * @return the hash
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
87 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
88 CX_INLINE
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
89 uint32_t cx_hash_u32(uint32_t x) {
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
90 x = ((x >> 16) ^ x) * 0x45d9f3bu;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
91 x = ((x >> 16) ^ x) * 0x45d9f3bu;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
92 x = (x >> 16) ^ x;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
93 return x;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
94 }
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
95
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
96 /**
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
97 * Mixes up a 64-bit integer to be used as a hash.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
98 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
99 * This function produces no collisions and has a good statistical distribution.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
100 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
101 * @param x the integer
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
102 * @return the hash
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
103 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
104 CX_INLINE
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
105 uint64_t cx_hash_u64(uint64_t x){
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
106 x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
107 x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb);
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
108 x = x ^ (x >> 31);
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
109 return x;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
110 }
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
111
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
112 /**
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
113 * Computes a hash key for an arbitrary object.
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
114 *
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
115 * The computation uses the in-memory representation that might not be
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
116 * the same on different platforms. Therefore, this hash should not be
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
117 * used for data exchange with different machines.
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
118 *
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
119 * @param obj a pointer to an arbitrary object
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
120 * @param len the length of the object in memory
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
121 * @return the hash key
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
122 */
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
123 CX_EXTERN CX_NODISCARD CX_ACCESS_R(1, 2)
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
124 CxHashKey cx_hash_key(const void *obj, size_t len);
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
125
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
126 /**
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
127 * Computes a hash key from a 32-bit integer.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
128 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
129 * @param x the integer
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
130 * @return the hash key
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
131 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
132 CX_NODISCARD CX_INLINE
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
133 CxHashKey cx_hash_key_u32(uint32_t x) {
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
134 CxHashKey key;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
135 key.data = NULL;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
136 key.len = 0;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
137 key.hash = cx_hash_u32(x);
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
138 return key;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
139 }
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
140
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
141 /**
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
142 * Computes a hash key from a 64-bit integer.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
143 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
144 * @param x the integer
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
145 * @return the hash key
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
146 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
147 CX_NODISCARD CX_INLINE
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
148 CxHashKey cx_hash_key_u64(uint64_t x) {
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
149 CxHashKey key;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
150 key.data = NULL;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
151 key.len = 0;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
152 key.hash = cx_hash_u64(x);
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
153 return key;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
154 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155
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 * 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
158 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 * 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
160 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 * @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
162 * @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
163 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
164 CX_NODISCARD CX_CSTR_ARG(1) CX_INLINE
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
165 CxHashKey cx_hash_key_str(const char *str) {
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
166 return cx_hash_key((const void*)str, str == NULL ? 0 : strlen(str));
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
167 }
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
168
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
169 /**
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
170 * Computes a hash key from a string.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
171 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
172 * Use this function when the string is represented
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
173 * as an unsigned char array.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
174 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
175 * The string needs to be zero-terminated.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
176 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
177 * @param str the string
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
178 * @return the hash key
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
179 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
180 CX_NODISCARD CX_CSTR_ARG(1) CX_INLINE
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
181 CxHashKey cx_hash_key_ustr(const unsigned char *str) {
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
182 return cx_hash_key((const void*)str, str == NULL ? 0 : strlen((const char*)str));
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
183 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 * 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
187 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 * @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
189 * @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
190 * @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
191 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
192 CX_NODISCARD CX_ACCESS_R(1, 2) CX_INLINE
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
193 CxHashKey cx_hash_key_bytes(const unsigned char *bytes, size_t len) {
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
194 return cx_hash_key((const void*)bytes, len);
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
195 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 /**
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
198 * Computes a hash key from a UCX string.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 *
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
200 * @param str the string
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 * @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
202 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
203 CX_NODISCARD CX_INLINE
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
204 CxHashKey cx_hash_key_cxstr(cxstring str) {
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
205 return cx_hash_key((void*)str.ptr, str.length);
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
206 }
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
207
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
208 /**
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
209 * Computes a hash key from a UCX string.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
210 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
211 * @param str the string
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
212 * @return the hash key
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
213 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
214 CX_NODISCARD CX_INLINE
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
215 CxHashKey cx_hash_key_mutstr(cxmutstr str) {
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
216 return cx_hash_key((void*)str.ptr, str.length);
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
217 }
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
218
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
219 /**
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
220 * The identity function for the CX_HASH_KEY() macro.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
221 * You should never need to use this manually.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
222 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
223 * @param key the key
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
224 * @return a copy of the key (not the data)
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
225 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
226 CX_NODISCARD CX_INLINE
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
227 CxHashKey cx_hash_key_identity(CxHashKey key) {
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
228 return key;
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
229 }
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
230
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
231 /**
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
232 * The dereference function for the CX_HASH_KEY() macro.
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
233 * You should never need to use this manually.
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
234 *
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
235 * @param key a pointer to a key
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
236 * @return a copy of the key (not the data)
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
237 */
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
238 CX_NODISCARD CX_INLINE
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
239 CxHashKey cx_hash_key_deref(const CxHashKey *key) {
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
240 return *key;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
241 }
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
242
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
243 #ifndef __cplusplus
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
244 /**
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
245 * Creates a hash key from any of the supported types with implicit length.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
246 *
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
247 * Does nothing when passing a CxHashKey and dereferences CxHashKey pointers.
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
248 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
249 * Supported types are UCX strings, zero-terminated C strings,
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
250 * and 32-bit or 64-bit unsigned integers.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
251 *
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
252 * @param key the key data
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
253 * @returns the @c CxHashKey
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
254 */
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
255 #define CX_HASH_KEY(key) _Generic((key), \
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
256 CxHashKey*: cx_hash_key_deref, \
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
257 const CxHashKey*: cx_hash_key_deref, \
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
258 CxHashKey: cx_hash_key_identity, \
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
259 cxstring: cx_hash_key_cxstr, \
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
260 cxmutstr: cx_hash_key_mutstr, \
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
261 char*: cx_hash_key_str, \
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
262 const char*: cx_hash_key_str, \
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
263 unsigned char*: cx_hash_key_ustr, \
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
264 const unsigned char*: cx_hash_key_ustr, \
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
265 uint32_t: cx_hash_key_u32, \
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
266 uint64_t: cx_hash_key_u64) \
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
267 (key)
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
268 #endif // __cplusplus
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
269
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
270 /**
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
271 * Compare function for hash keys.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
272 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
273 * The pointers are untyped to be compatible with the cx_compare_func signature.
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
274 *
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
275 * @param left (@c CxHashKey*) the first key
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
276 * @param right (@c CxHashKey*) the second key
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
277 * @return zero when the keys equal, non-zero when they differ
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
278 */
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
279 CX_EXTERN CX_NODISCARD CX_NONNULL
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
280 int cx_hash_key_cmp(const void *left, const void *right);
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
281
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
282 /**
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
283 * Interprets the key data as a string and returns it.
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
284 *
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
285 * @param key the key
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
286 * @return the key data as a string
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
287 */
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
288 CX_EXTERN
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
289 cxstring cx_hash_key_as_string(const CxHashKey *key);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 #ifdef __cplusplus
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
292 // ----------------------------------------------------------
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
293 // Overloads of CX_HASH_KEY (the C++ version of a _Generic)
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
294 // ----------------------------------------------------------
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
295
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
296 CX_CPPDECL CxHashKey CX_HASH_KEY(CxHashKey key) {
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
297 return key;
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
298 }
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
299
894
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
300 CX_CPPDECL CxHashKey CX_HASH_KEY(const CxHashKey *key) {
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
301 return *key;
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
302 }
e86049631677 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 889
diff changeset
303
889
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
304 CX_CPPDECL CxHashKey CX_HASH_KEY(cxstring str) {
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
305 return cx_hash_key_cxstr(str);
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
306 }
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
307
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
308 CX_CPPDECL CxHashKey CX_HASH_KEY(cxmutstr str) {
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
309 return cx_hash_key_mutstr(str);
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
310 }
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
311
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
312 CX_CPPDECL CxHashKey CX_HASH_KEY(const char *str) {
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
313 return cx_hash_key_str(str);
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
314 }
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
315
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
316 CX_CPPDECL CxHashKey CX_HASH_KEY(const unsigned char *str) {
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
317 return cx_hash_key_ustr(str);
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
318 }
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
319
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
320 CX_CPPDECL CxHashKey CX_HASH_KEY(uint32_t key) {
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
321 return cx_hash_key_u32(key);
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
322 }
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
323
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
324 CX_CPPDECL CxHashKey CX_HASH_KEY(uint64_t key) {
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
325 return cx_hash_key_u64(key);
42cdbf9bbd49 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
326 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 #endif
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 #endif // UCX_HASH_KEY_H

mercurial