From 5b3c7d45bbaa4bb0fee61b89f4ecc5df4c4ffcd8 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 3 Jul 2023 16:41:51 +0200 Subject: Backport from xs. --- xs.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'xs.h') diff --git a/xs.h b/xs.h index 6344816..f892472 100644 --- a/xs.h +++ b/xs.h @@ -122,6 +122,7 @@ xs_str *xs_hex_enc(const xs_val *data, int size); xs_val *xs_hex_dec(const xs_str *hex, int *size); int xs_is_hex(const char *str); +unsigned int xs_hash_func(const char *data, int size); #ifdef XS_ASSERT #include @@ -136,6 +137,8 @@ extern xs_val xs_stock_null[]; extern xs_val xs_stock_true[]; extern xs_val xs_stock_false[]; +#define xs_return(v) xs_val *__r = v; v = NULL; return __r + #ifdef XS_IMPLEMENTATION @@ -1186,6 +1189,21 @@ int xs_is_hex(const char *str) } +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++) { + hash ^= data[n]; + hash *= 111111111; + } + + return hash ^ hash >> 16; +} + + #endif /* XS_IMPLEMENTATION */ #endif /* _XS_H */ -- cgit v1.2.3