Sun, 11 Jan 2026 10:42:29 +0100
fix properties loading when the config dir is overriden by ui_setappdir
| 174 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * | |
| 4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * | |
| 9 | * 1. Redistributions of source code must retain the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer. | |
| 11 | * | |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 | * notice, this list of conditions and the following disclaimer in the | |
| 14 | * documentation and/or other materials provided with the distribution. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | * POSSIBILITY OF SUCH DAMAGE. | |
| 27 | */ | |
| 28 | ||
| 29 | #include "cx/hash_key.h" | |
| 845 | 30 | #include "cx/compare.h" |
| 174 | 31 | #include <string.h> |
| 32 | ||
| 33 | void cx_hash_murmur(CxHashKey *key) { | |
| 324 | 34 | const unsigned char *data = key->data; |
| 174 | 35 | if (data == NULL) { |
| 36 | // extension: special value for NULL | |
| 37 | key->hash = 1574210520u; | |
| 38 | return; | |
| 39 | } | |
| 40 | size_t len = key->len; | |
| 41 | ||
| 42 | unsigned m = 0x5bd1e995; | |
| 43 | unsigned r = 24; | |
| 440 | 44 | unsigned h = 25 ^ (unsigned) len; |
| 174 | 45 | unsigned i = 0; |
| 46 | while (len >= 4) { | |
| 47 | unsigned k = data[i + 0] & 0xFF; | |
| 48 | k |= (data[i + 1] & 0xFF) << 8; | |
| 49 | k |= (data[i + 2] & 0xFF) << 16; | |
| 50 | k |= (data[i + 3] & 0xFF) << 24; | |
| 51 | ||
| 52 | k *= m; | |
| 53 | k ^= k >> r; | |
| 54 | k *= m; | |
| 55 | ||
| 56 | h *= m; | |
| 57 | h ^= k; | |
| 58 | ||
| 59 | i += 4; | |
| 60 | len -= 4; | |
| 61 | } | |
| 62 | ||
| 63 | switch (len) { | |
| 64 | case 3: | |
| 65 | h ^= (data[i + 2] & 0xFF) << 16; | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
943
diff
changeset
|
66 | CX_FALLTHROUGH; |
| 174 | 67 | case 2: |
| 68 | h ^= (data[i + 1] & 0xFF) << 8; | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
943
diff
changeset
|
69 | CX_FALLTHROUGH; |
| 174 | 70 | case 1: |
| 71 | h ^= (data[i + 0] & 0xFF); | |
| 72 | h *= m; | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
943
diff
changeset
|
73 | CX_FALLTHROUGH; |
| 174 | 74 | default: // do nothing |
| 75 | ; | |
| 76 | } | |
| 77 | ||
| 78 | h ^= h >> 13; | |
| 79 | h *= m; | |
| 80 | h ^= h >> 15; | |
| 81 | ||
| 82 | key->hash = h; | |
| 83 | } | |
| 84 | ||
| 85 | CxHashKey cx_hash_key( | |
| 324 | 86 | const void *obj, |
| 174 | 87 | size_t len |
| 88 | ) { | |
| 89 | CxHashKey key; | |
| 90 | key.data = obj; | |
| 91 | key.len = len; | |
| 92 | cx_hash_murmur(&key); | |
| 93 | return key; | |
| 94 | } | |
| 845 | 95 | |
|
943
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
96 | int cx_hash_key_cmp(const void *l, const void *r) { |
|
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
97 | const CxHashKey *left = l; |
|
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
98 | const CxHashKey *right = r; |
| 845 | 99 | int d; |
| 100 | d = cx_vcmp_uint64(left->hash, right->hash); | |
| 101 | if (d != 0) return d; | |
| 102 | d = cx_vcmp_size(left->len, right->len); | |
| 103 | if (d != 0) return d; | |
| 104 | if (left->len == 0) return 0; | |
| 105 | return memcmp(left->data, right->data, left->len); | |
| 106 | } | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
943
diff
changeset
|
107 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
943
diff
changeset
|
108 | cxstring cx_hash_key_as_string(const CxHashKey *key) { |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
943
diff
changeset
|
109 | return cx_strn(key->data, key->len); |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
943
diff
changeset
|
110 | } |