snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit 492b91e4e47c43d15bb828ecbe1e4195c47c31f8
parent 1766d6bf92eb433841c03ccb096c636a4c5dc968
Author: default <nobody@localhost>
Date:   Tue, 28 Jan 2025 07:42:08 +0100

Backport from xs.

Diffstat:
Mxs.h | 21++++++++++++++++++---
Mxs_match.h | 7++++++-
Mxs_version.h | 2+-
3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/xs.h b/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 */ diff --git a/xs_match.h b/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; + } } } } diff --git 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 */