summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-07-03 16:41:51 +0200
committerGravatar default2023-07-03 16:41:51 +0200
commit5b3c7d45bbaa4bb0fee61b89f4ecc5df4c4ffcd8 (patch)
tree436cecffbe17a2edaaa66ba83850658e92291217
parentUpdated RELEASE_NOTES. (diff)
downloadsnac2-5b3c7d45bbaa4bb0fee61b89f4ecc5df4c4ffcd8.tar.gz
snac2-5b3c7d45bbaa4bb0fee61b89f4ecc5df4c4ffcd8.tar.xz
snac2-5b3c7d45bbaa4bb0fee61b89f4ecc5df4c4ffcd8.zip
Backport from xs.
-rw-r--r--xs.h18
-rw-r--r--xs_set.h16
-rw-r--r--xs_version.h2
3 files changed, 20 insertions, 16 deletions
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);
122xs_val *xs_hex_dec(const xs_str *hex, int *size); 122xs_val *xs_hex_dec(const xs_str *hex, int *size);
123int xs_is_hex(const char *str); 123int xs_is_hex(const char *str);
124 124
125unsigned int xs_hash_func(const char *data, int size);
125 126
126#ifdef XS_ASSERT 127#ifdef XS_ASSERT
127#include <assert.h> 128#include <assert.h>
@@ -136,6 +137,8 @@ extern xs_val xs_stock_null[];
136extern xs_val xs_stock_true[]; 137extern xs_val xs_stock_true[];
137extern xs_val xs_stock_false[]; 138extern xs_val xs_stock_false[];
138 139
140#define xs_return(v) xs_val *__r = v; v = NULL; return __r
141
139 142
140#ifdef XS_IMPLEMENTATION 143#ifdef XS_IMPLEMENTATION
141 144
@@ -1186,6 +1189,21 @@ int xs_is_hex(const char *str)
1186} 1189}
1187 1190
1188 1191
1192unsigned int xs_hash_func(const char *data, int size)
1193/* a general purpose hashing function */
1194{
1195 unsigned int hash = 0x666;
1196 int n;
1197
1198 for (n = 0; n < size; n++) {
1199 hash ^= data[n];
1200 hash *= 111111111;
1201 }
1202
1203 return hash ^ hash >> 16;
1204}
1205
1206
1189#endif /* XS_IMPLEMENTATION */ 1207#endif /* XS_IMPLEMENTATION */
1190 1208
1191#endif /* _XS_H */ 1209#endif /* _XS_H */
diff --git a/xs_set.h b/xs_set.h
index 8829f14..1857ae7 100644
--- a/xs_set.h
+++ b/xs_set.h
@@ -51,26 +51,12 @@ void xs_set_free(xs_set *s)
51} 51}
52 52
53 53
54static unsigned int _calc_hash(const char *data, int size)
55{
56 unsigned int hash = 0x666;
57 int n;
58
59 for (n = 0; n < size; n++) {
60 hash ^= data[n];
61 hash *= 111111111;
62 }
63
64 return hash ^ hash >> 16;
65}
66
67
68static int _store_hash(xs_set *s, const char *data, int value) 54static int _store_hash(xs_set *s, const char *data, int value)
69{ 55{
70 unsigned int hash, i; 56 unsigned int hash, i;
71 int sz = xs_size(data); 57 int sz = xs_size(data);
72 58
73 hash = _calc_hash(data, sz); 59 hash = xs_hash_func(data, sz);
74 60
75 while (s->hash[(i = hash % s->elems)]) { 61 while (s->hash[(i = hash % s->elems)]) {
76 /* get the pointer to the stored data */ 62 /* get the pointer to the stored data */
diff --git a/xs_version.h b/xs_version.h
index 6d8b8b8..a8007e7 100644
--- a/xs_version.h
+++ b/xs_version.h
@@ -1 +1 @@
/* 567d70ecbe16b2358873b8bc971a6e092c3c0074 */ /* dada4e932155b621ab6d66820f62ea9cf09cbb70 */