Improve cake allocator's memory utilisation (#43)
[lunaix-os.git] / lunaix-os / libs / hash.c
index 293ec67bc3bddb6d7a450e09e32009c5f827f4e3..b4e5c6f58910f57545aaaf0d36f4cd07722e7c4e 100644 (file)
@@ -1,4 +1,5 @@
-#include <lib/hash.h>
+#include <klibc/hash.h>
+#include <lunaix/compiler.h>
 
 /**
  * @brief Simple string hash function
@@ -8,13 +9,16 @@
  * @param str
  * @return unsigned int
  */
-uint32_t
-strhash_32(unsigned char* str, uint32_t truncate_to)
+u32_t weak
+strhash_32(const char* str, u32_t truncate_to)
 {
-    uint32_t hash = 5381;
+    if (!str)
+        return 0;
+
+    u32_t hash = 5381;
     int c;
 
-    while (c = *str++)
+    while ((c = *str++))
         hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
 
     return hash >> (HASH_SIZE_BITS - truncate_to);