Decoupling Architectural-specific Code (#35)
[lunaix-os.git] / lunaix-os / includes / klibc / hash.h
1 #ifndef __LUNAIX_HASH_H
2 #define __LUNAIX_HASH_H
3
4 #include <lunaix/types.h>
5
6 #define HASH_SIZE_BITS 32
7
8 u32_t
9 strhash_32(const char* str, u32_t truncate_to);
10
11 /**
12  * @brief Simple generic hash function
13  *
14  * ref:
15  * https://elixir.bootlin.com/linux/v5.18.12/source/include/linux/hash.h#L60
16  *
17  * @param val
18  * @return u32_t
19  */
20 inline u32_t
21 hash_32(const u32_t val, u32_t truncate_to)
22 {
23     return (val * 0x61C88647u) >> (HASH_SIZE_BITS - truncate_to);
24 }
25
26 #endif /* __LUNAIX_HASH_H */