ucx/hash_key.c

Sat, 08 Nov 2025 23:06:11 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 08 Nov 2025 23:06:11 +0100
changeset 888
af685cc9d623
parent 852
83fdf679df99
permissions
-rw-r--r--

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
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "cx/hash_key.h"
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
30 #include "cx/compare.h"
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 void cx_hash_murmur(CxHashKey *key) {
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
34 const unsigned char *data = key->data;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 if (data == NULL) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 // extension: special value for NULL
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 key->hash = 1574210520u;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 return;
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 size_t len = key->len;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 unsigned m = 0x5bd1e995;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 unsigned r = 24;
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
44 unsigned h = 25 ^ (unsigned) len;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 unsigned i = 0;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 while (len >= 4) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 unsigned k = data[i + 0] & 0xFF;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 k |= (data[i + 1] & 0xFF) << 8;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 k |= (data[i + 2] & 0xFF) << 16;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 k |= (data[i + 3] & 0xFF) << 24;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 k *= m;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 k ^= k >> r;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 k *= m;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 h *= m;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 h ^= k;
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 i += 4;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 len -= 4;
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 switch (len) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 case 3:
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 h ^= (data[i + 2] & 0xFF) << 16;
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
66 cx_attr_fallthrough;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 case 2:
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 h ^= (data[i + 1] & 0xFF) << 8;
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
69 cx_attr_fallthrough;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 case 1:
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 h ^= (data[i + 0] & 0xFF);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 h *= m;
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
73 cx_attr_fallthrough;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 default: // do nothing
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 ;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 }
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 h ^= h >> 13;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 h *= m;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 h ^= h >> 15;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 key->hash = h;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 }
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
85
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
86 uint32_t cx_hash_u32(uint32_t x) {
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
87 x = ((x >> 16) ^ x) * 0x45d9f3bu;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
88 x = ((x >> 16) ^ x) * 0x45d9f3bu;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
89 x = (x >> 16) ^ x;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
90 return x;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
91 }
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
92
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
93 uint64_t cx_hash_u64(uint64_t x) {
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
94 x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
95 x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
96 x = x ^ (x >> 31);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
97 return x;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
98 }
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
99
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
100 CxHashKey cx_hash_key_str(const 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
101 CxHashKey key;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 key.data = str;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 key.len = str == NULL ? 0 : strlen(str);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 cx_hash_murmur(&key);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 return key;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 }
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
108 CxHashKey cx_hash_key_ustr(unsigned const char *str) {
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
109 CxHashKey key;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
110 key.data = str;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
111 key.len = str == NULL ? 0 : strlen((const char*)str);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
112 cx_hash_murmur(&key);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
113 return key;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
114 }
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
115
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
116 CxHashKey cx_hash_key_cxstr(cxstring str) {
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
117 return cx_hash_key(str.ptr, str.length);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
118 }
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
119
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
120 CxHashKey cx_hash_key_mutstr(cxmutstr str) {
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
121 return cx_hash_key(str.ptr, str.length);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
122 }
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
123
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 CxHashKey cx_hash_key_bytes(
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
125 const unsigned char *bytes,
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 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
127 ) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 CxHashKey key;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 key.data = bytes;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 key.len = len;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 cx_hash_murmur(&key);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 return key;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 }
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 CxHashKey cx_hash_key(
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
136 const void *obj,
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 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
138 ) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 CxHashKey key;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 key.data = obj;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 key.len = len;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 cx_hash_murmur(&key);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 return key;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 }
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
145
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
146 CxHashKey cx_hash_key_u32(uint32_t x) {
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
147 CxHashKey key;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
148 key.data = NULL;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
149 key.len = 0;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
150 key.hash = cx_hash_u32(x);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
151 return key;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
152 }
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
153
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
154 CxHashKey cx_hash_key_u64(uint64_t x) {
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
155 CxHashKey key;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
156 key.data = NULL;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
157 key.len = 0;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
158 key.hash = cx_hash_u64(x);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
159 return key;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
160 }
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
161
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
162 int cx_hash_key_cmp(const void *l, const void *r) {
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
163 const CxHashKey *left = l;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
164 const CxHashKey *right = r;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
165 int d;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
166 d = cx_vcmp_uint64(left->hash, right->hash);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
167 if (d != 0) return d;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
168 d = cx_vcmp_size(left->len, right->len);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
169 if (d != 0) return d;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
170 if (left->len == 0) return 0;
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
171 return memcmp(left->data, right->data, left->len);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
172 }

mercurial