Browse Source

Backport from xs.

default 1 month ago
parent
commit
492b91e4e4
3 changed files with 25 additions and 5 deletions
  1. 18 3
      xs.h
  2. 6 1
      xs_match.h
  3. 1 1
      xs_version.h

+ 18 - 3
xs.h

@@ -12,6 +12,7 @@
 #include <stdarg.h>
 #include <signal.h>
 #include <errno.h>
+#include <stdint.h>
 
 typedef enum {
     XSTYPE_STRING = 0x02,       /* C string (\0 delimited) (NOT STORED) */
@@ -142,6 +143,7 @@ void xs_data_get(void *data, const xs_data *value);
 void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size);
 
 unsigned int xs_hash_func(const char *data, int size);
+uint64_t xs_hash64_func(const char *data, int size);
 
 #ifdef XS_ASSERT
 #include <assert.h>
@@ -632,7 +634,7 @@ xs_str *xs_crop_i(xs_str *str, int start, int end)
         end = sz + end;
 
     /* crop from the top */
-    if (end > 0 && end < sz)
+    if (end >= 0 && end < sz)
         str[end] = '\0';
 
     /* crop from the bottom */
@@ -1487,9 +1489,8 @@ unsigned int xs_hash_func(const char *data, int size)
 /* a general purpose hashing function */
 {
     unsigned int hash = 0x666;
-    int n;
 
-    for (n = 0; n < size; n++) {
+    for (int n = 0; n < size; n++) {
         hash ^= (unsigned char)data[n];
         hash *= 111111111;
     }
@@ -1498,6 +1499,20 @@ unsigned int xs_hash_func(const char *data, int size)
 }
 
 
+uint64_t xs_hash64_func(const char *data, int size)
+/* a general purpose hashing function (64 bit) */
+{
+    uint64_t hash = 0x100;
+
+    for (int n = 0; n < size; n++) {
+        hash ^= (unsigned char)data[n];
+        hash *= 1111111111111111111;
+    }
+
+    return hash;
+}
+
+
 #endif /* XS_IMPLEMENTATION */
 
 #endif /* _XS_H */

+ 6 - 1
xs_match.h

@@ -24,6 +24,7 @@ int xs_match(const char *str, const char *spec)
 retry:
 
     for (;;) {
+        const char *q = spec;
         char c = *str++;
         char p = *spec++;
 
@@ -63,8 +64,12 @@ retry:
                     spec = b_spec;
                     str  = ++b_str;
                 }
-                else
+                else {
+                    if (*q == '|')
+                        spec = q;
+
                     break;
+                }
             }
         }
     }

+ 1 - 1
xs_version.h

@@ -1 +1 @@
-/* b865e89769aedfdbc61251e94451e9d37579f52e 2025-01-12T16:17:47+01:00 */
+/* 2f43b93e9d2b63360c802e09f4c68adfef74c673 2025-01-28T07:40:50+01:00 */