git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: stale dnode caching instance cause locked-up upon accessing (#52)
[lunaix-os.git]
/
lunaix-os
/
libs
/
hash.c
diff --git
a/lunaix-os/libs/hash.c
b/lunaix-os/libs/hash.c
index c1580edda5a51074ea9237abe709eeaddac55cb3..7182ab684523b1fa53180c336f9e0f0a17be23ba 100644
(file)
--- a/
lunaix-os/libs/hash.c
+++ b/
lunaix-os/libs/hash.c
@@
-1,24
+1,28
@@
-#include <lib/hash.h>
+#include <klibc/hash.h>
+#include <lunaix/compiler.h>
/**
/**
- * @brief Simple string hash function
+ * @brief Simple string hash function
(sdbm)
*
*
- * ref: https://stackoverflow.com/a/7666577
+ * ref: http://www.cse.yorku.ca/~oz/hash.html
+ *
+ * sdbm has lower standard deviation in bucket distribution
+ * than djb2 (previously used) for low bucket size (16, 32).
*
* @param str
* @return unsigned int
*/
*
* @param str
* @return unsigned int
*/
-u
int32_t
-strhash_32(
unsigned char* str, uint
32_t truncate_to)
+u
32_t _weak
+strhash_32(
const char* str, u
32_t truncate_to)
{
if (!str)
return 0;
{
if (!str)
return 0;
- u
int32_t hash = 5381
;
+ u
32_t hash = 0
;
int c;
while ((c = *str++))
int c;
while ((c = *str++))
- hash = (
(hash << 5) + hash) + c; /* hash * 33 + c */
+ hash = (
hash << 6) + (hash << 16) + c - hash;
return hash >> (HASH_SIZE_BITS - truncate_to);
}
\ No newline at end of file
return hash >> (HASH_SIZE_BITS - truncate_to);
}
\ No newline at end of file