summaryrefslogtreecommitdiff
path: root/include/conts/conts.h
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-10-27 21:57:02 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2024-10-27 21:57:02 +0200
commit1f57645d9550e486a5bc209a0652bfad7fb8872a (patch)
tree2ff0fca8539c0fe147b463dca9e4d0e308336b95 /include/conts/conts.h
parent5940254d9363ed8de9ba79a65cb074ec5aa4e69f (diff)
downloadconts-1f57645d9550e486a5bc209a0652bfad7fb8872a.tar.gz
conts-1f57645d9550e486a5bc209a0652bfad7fb8872a.zip
add map
Diffstat (limited to 'include/conts/conts.h')
-rw-r--r--include/conts/conts.h26
1 files changed, 6 insertions, 20 deletions
diff --git a/include/conts/conts.h b/include/conts/conts.h
index d965aeb..862bd31 100644
--- a/include/conts/conts.h
+++ b/include/conts/conts.h
@@ -4,25 +4,11 @@
#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;
-}
+#define CONTAINER_OF(ptr, type, member) \
+ (type *)((char *)(ptr) - offsetof(type, member))
+#define foreach(name, i, s)\
+ for (auto i = CONTS_JOIN(name, begin)(s);\
+ !CONTS_JOIN(name, end)(s, i);\
+ i = CONTS_JOIN(name, next)(i))
#endif /* CONTS_H */