summaryrefslogtreecommitdiff
path: root/include/conts/conts.h
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-10-27 16:17:32 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2024-10-27 16:35:04 +0200
commit5940254d9363ed8de9ba79a65cb074ec5aa4e69f (patch)
treeb217218914aff187ea3ee056a0ab46d1963cc9b2 /include/conts/conts.h
downloadconts-5940254d9363ed8de9ba79a65cb074ec5aa4e69f.tar.gz
conts-5940254d9363ed8de9ba79a65cb074ec5aa4e69f.zip
initial containers
Diffstat (limited to 'include/conts/conts.h')
-rw-r--r--include/conts/conts.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/conts/conts.h b/include/conts/conts.h
new file mode 100644
index 0000000..d965aeb
--- /dev/null
+++ b/include/conts/conts.h
@@ -0,0 +1,28 @@
+#ifndef CONTS_H
+#define CONTS_H
+
+#define CONTS_JOIN2(a, b) a##_##b
+#define CONTS_JOIN(a, b) CONTS_JOIN2(a, b)
+
+static inline unsigned long conts_strhash(const char *str)
+{
+ /* http://www.cse.yorku.ca/%7Eoz/hash.html, djb2 */
+ unsigned long hash = 5381;
+ int c;
+
+ while (c = *str++)
+ hash = ((hash << 5) + hash) + c;
+
+ return hash;
+}
+
+static inline unsigned long conts_inthash(unsigned long x)
+{
+ /* https://xorshift.di.unimi.it/splitmix64.c */
+ x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ULL;
+ x = (x ^ (x >> 27)) * 0x94d049bb133111ebULL;
+ x = (x ^ (x >> 31));
+ return x;
+}
+
+#endif /* CONTS_H */