aboutsummaryrefslogtreecommitdiff
path: root/xs.h
diff options
context:
space:
mode:
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 */