commit 492b91e

default  ·  2025-01-28 06:42:08 +0000 UTC
parent 1766d6b
Backport from xs.
3 files changed,  +25, -5
M xs.h
M xs.h
+18, -3
 1@@ -12,6 +12,7 @@
 2 #include <stdarg.h>
 3 #include <signal.h>
 4 #include <errno.h>
 5+#include <stdint.h>
 6 
 7 typedef enum {
 8     XSTYPE_STRING = 0x02,       /* C string (\0 delimited) (NOT STORED) */
 9@@ -142,6 +143,7 @@ void xs_data_get(void *data, const xs_data *value);
10 void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size);
11 
12 unsigned int xs_hash_func(const char *data, int size);
13+uint64_t xs_hash64_func(const char *data, int size);
14 
15 #ifdef XS_ASSERT
16 #include <assert.h>
17@@ -632,7 +634,7 @@ xs_str *xs_crop_i(xs_str *str, int start, int end)
18         end = sz + end;
19 
20     /* crop from the top */
21-    if (end > 0 && end < sz)
22+    if (end >= 0 && end < sz)
23         str[end] = '\0';
24 
25     /* crop from the bottom */
26@@ -1487,9 +1489,8 @@ unsigned int xs_hash_func(const char *data, int size)
27 /* a general purpose hashing function */
28 {
29     unsigned int hash = 0x666;
30-    int n;
31 
32-    for (n = 0; n < size; n++) {
33+    for (int n = 0; n < size; n++) {
34         hash ^= (unsigned char)data[n];
35         hash *= 111111111;
36     }
37@@ -1498,6 +1499,20 @@ unsigned int xs_hash_func(const char *data, int size)
38 }
39 
40 
41+uint64_t xs_hash64_func(const char *data, int size)
42+/* a general purpose hashing function (64 bit) */
43+{
44+    uint64_t hash = 0x100;
45+
46+    for (int n = 0; n < size; n++) {
47+        hash ^= (unsigned char)data[n];
48+        hash *= 1111111111111111111;
49+    }
50+
51+    return hash;
52+}
53+
54+
55 #endif /* XS_IMPLEMENTATION */
56 
57 #endif /* _XS_H */
+6, -1
 1@@ -24,6 +24,7 @@ int xs_match(const char *str, const char *spec)
 2 retry:
 3 
 4     for (;;) {
 5+        const char *q = spec;
 6         char c = *str++;
 7         char p = *spec++;
 8 
 9@@ -63,8 +64,12 @@ retry:
10                     spec = b_spec;
11                     str  = ++b_str;
12                 }
13-                else
14+                else {
15+                    if (*q == '|')
16+                        spec = q;
17+
18                     break;
19+                }
20             }
21         }
22     }
+1, -1
1@@ -1 +1 @@
2-/* b865e89769aedfdbc61251e94451e9d37579f52e 2025-01-12T16:17:47+01:00 */
3+/* 2f43b93e9d2b63360c802e09f4c68adfef74c673 2025-01-28T07:40:50+01:00 */