summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--xs.h21
-rw-r--r--xs_match.h7
-rw-r--r--xs_version.h2
3 files changed, 25 insertions, 5 deletions
diff --git a/xs.h b/xs.h
index 05d84f5..961425b 100644
--- a/xs.h
+++ b/xs.h
@@ -12,6 +12,7 @@
12#include <stdarg.h> 12#include <stdarg.h>
13#include <signal.h> 13#include <signal.h>
14#include <errno.h> 14#include <errno.h>
15#include <stdint.h>
15 16
16typedef enum { 17typedef enum {
17 XSTYPE_STRING = 0x02, /* C string (\0 delimited) (NOT STORED) */ 18 XSTYPE_STRING = 0x02, /* C string (\0 delimited) (NOT STORED) */
@@ -142,6 +143,7 @@ void xs_data_get(void *data, const xs_data *value);
142void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size); 143void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size);
143 144
144unsigned int xs_hash_func(const char *data, int size); 145unsigned int xs_hash_func(const char *data, int size);
146uint64_t xs_hash64_func(const char *data, int size);
145 147
146#ifdef XS_ASSERT 148#ifdef XS_ASSERT
147#include <assert.h> 149#include <assert.h>
@@ -632,7 +634,7 @@ xs_str *xs_crop_i(xs_str *str, int start, int end)
632 end = sz + end; 634 end = sz + end;
633 635
634 /* crop from the top */ 636 /* crop from the top */
635 if (end > 0 && end < sz) 637 if (end >= 0 && end < sz)
636 str[end] = '\0'; 638 str[end] = '\0';
637 639
638 /* crop from the bottom */ 640 /* crop from the bottom */
@@ -1487,9 +1489,8 @@ unsigned int xs_hash_func(const char *data, int size)
1487/* a general purpose hashing function */ 1489/* a general purpose hashing function */
1488{ 1490{
1489 unsigned int hash = 0x666; 1491 unsigned int hash = 0x666;
1490 int n;
1491 1492
1492 for (n = 0; n < size; n++) { 1493 for (int n = 0; n < size; n++) {
1493 hash ^= (unsigned char)data[n]; 1494 hash ^= (unsigned char)data[n];
1494 hash *= 111111111; 1495 hash *= 111111111;
1495 } 1496 }
@@ -1498,6 +1499,20 @@ unsigned int xs_hash_func(const char *data, int size)
1498} 1499}
1499 1500
1500 1501
1502uint64_t xs_hash64_func(const char *data, int size)
1503/* a general purpose hashing function (64 bit) */
1504{
1505 uint64_t hash = 0x100;
1506
1507 for (int n = 0; n < size; n++) {
1508 hash ^= (unsigned char)data[n];
1509 hash *= 1111111111111111111;
1510 }
1511
1512 return hash;
1513}
1514
1515
1501#endif /* XS_IMPLEMENTATION */ 1516#endif /* XS_IMPLEMENTATION */
1502 1517
1503#endif /* _XS_H */ 1518#endif /* _XS_H */
diff --git a/xs_match.h b/xs_match.h
index 0b89ac8..76c1bf3 100644
--- a/xs_match.h
+++ b/xs_match.h
@@ -24,6 +24,7 @@ int xs_match(const char *str, const char *spec)
24retry: 24retry:
25 25
26 for (;;) { 26 for (;;) {
27 const char *q = spec;
27 char c = *str++; 28 char c = *str++;
28 char p = *spec++; 29 char p = *spec++;
29 30
@@ -63,8 +64,12 @@ retry:
63 spec = b_spec; 64 spec = b_spec;
64 str = ++b_str; 65 str = ++b_str;
65 } 66 }
66 else 67 else {
68 if (*q == '|')
69 spec = q;
70
67 break; 71 break;
72 }
68 } 73 }
69 } 74 }
70 } 75 }
diff --git a/xs_version.h b/xs_version.h
index 12f713a..7314133 100644
--- a/xs_version.h
+++ b/xs_version.h
@@ -1 +1 @@
/* b865e89769aedfdbc61251e94451e9d37579f52e 2025-01-12T16:17:47+01:00 */ /* 2f43b93e9d2b63360c802e09f4c68adfef74c673 2025-01-28T07:40:50+01:00 */