git://scm.lunaixsky.com
/
lunaix-os.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
6-acpi_and_apic.md (#27)
[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
u32_t
12
strhash_32(const char* str, u32_t truncate_to)
13
{
14
if (!str)
15
return 0;
16
17
u32_t hash = 5381;
18
int c;
19
20
while ((c = *str++))
21
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
22
23
return hash >> (HASH_SIZE_BITS - truncate_to);
24
}