aboutsummaryrefslogtreecommitdiff
path: root/xs.h
diff options
context:
space:
mode:
authordefault <nobody@localhost>2025-01-28 07:42:08 +0100
committerdefault <nobody@localhost>2025-01-28 07:42:08 +0100
commit492b91e4e47c43d15bb828ecbe1e4195c47c31f8 (patch)
tree2a0784dde0119899a8cda2ee8e4d87cd66bd7815 /xs.h
parent1766d6bf92eb433841c03ccb096c636a4c5dc968 (diff)
Backport from xs.
Diffstat (limited to 'xs.h')
-rw-r--r--xs.h21
1 files changed, 18 insertions, 3 deletions
diff --git a/xs.h b/xs.h
index 05d84f5..961425b 100644
--- 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 */