diff options
| author | 2023-07-03 16:41:51 +0200 | |
|---|---|---|
| committer | 2023-07-03 16:41:51 +0200 | |
| commit | 5b3c7d45bbaa4bb0fee61b89f4ecc5df4c4ffcd8 (patch) | |
| tree | 436cecffbe17a2edaaa66ba83850658e92291217 /xs.h | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-5b3c7d45bbaa4bb0fee61b89f4ecc5df4c4ffcd8.tar.gz snac2-5b3c7d45bbaa4bb0fee61b89f4ecc5df4c4ffcd8.tar.xz snac2-5b3c7d45bbaa4bb0fee61b89f4ecc5df4c4ffcd8.zip | |
Backport from xs.
Diffstat (limited to 'xs.h')
| -rw-r--r-- | xs.h | 18 |
1 files changed, 18 insertions, 0 deletions
| @@ -122,6 +122,7 @@ xs_str *xs_hex_enc(const xs_val *data, int size); | |||
| 122 | xs_val *xs_hex_dec(const xs_str *hex, int *size); | 122 | xs_val *xs_hex_dec(const xs_str *hex, int *size); |
| 123 | int xs_is_hex(const char *str); | 123 | int xs_is_hex(const char *str); |
| 124 | 124 | ||
| 125 | unsigned 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[]; | |||
| 136 | extern xs_val xs_stock_true[]; | 137 | extern xs_val xs_stock_true[]; |
| 137 | extern xs_val xs_stock_false[]; | 138 | extern 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 | ||
| 1192 | unsigned 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 */ |