feat: vfs - path walking and dnode caching.
[lunaix-os.git] / lunaix-os / includes / lib / hash.h
1 #ifndef __LUNAIX_HASH_H
2 #define __LUNAIX_HASH_H
3
4 #include <stdint.h>
5
6 #define HASH_SIZE_BITS 32
7
8 uint32_t
9 strhash_32(unsigned char* str, uint32_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 uint32_t
19  */
20 inline uint32_t
21 hash_32(uint32_t val, uint32_t truncate_to)
22 {
23     return (val * 0x61C88647u) >> (HASH_SIZE_BITS - truncate_to);
24 }
25
26 #endif /* __LUNAIX_HASH_H */