git://scm.lunaixsky.com
/
lunaix-os.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
feat: vfs - path walking and dnode caching.
[lunaix-os.git]
/
lunaix-os
/
libs
/
hash.c
1
#include <lib/hash.h>
2
3
/**
4
* @brief Simple string hash function
5
*
6
* ref: https://stackoverflow.com/a/7666577
7
*
8
* @param str
9
* @return unsigned int
10
*/
11
uint32_t
12
strhash_32(unsigned char* str, uint32_t truncate_to)
13
{
14
uint32_t hash = 5381;
15
int c;
16
17
while (c = *str++)
18
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
19
20
return hash >> (HASH_SIZE_BITS - truncate_to);
21
}