aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorame <[email protected]>2024-01-11 11:45:25 -0600
committerame <[email protected]>2024-01-11 11:45:25 -0600
commit8582794ad694c7ca3e53f875a3ce41f0231a5dd4 (patch)
tree0242d5b5afee856607263b808aba82437e657cde
parent78d83c1c4ae765636584616b99ccf146636669cf (diff)
fixed djb2
-rw-r--r--src/hash/djb2.c10
-rw-r--r--tests/hash.lua2
2 files changed, 6 insertions, 6 deletions
diff --git a/src/hash/djb2.c b/src/hash/djb2.c
index 8949ca8..7ec39de 100644
--- a/src/hash/djb2.c
+++ b/src/hash/djb2.c
@@ -3,11 +3,11 @@
#include <stdio.h>
#include <stdint.h>
-uint64_t djb2(uint8_t* in, size_t len){
- uint64_t hash = 5381;
+uint32_t djb2(uint8_t* in, size_t len){
+ uint32_t hash = 5381;
for(int i = 0; i != len; i++){
- hash = ((hash << 5) + hash) + (uint64_t)*in;
+ hash = ((hash << 5) + hash) + (uint32_t)*in;
in++;
}
@@ -20,8 +20,8 @@ int l_djb2(lua_State* L){
char digest[64];
- uint64_t u = djb2(a, len);
- sprintf(digest,"%08lx",u);
+ uint32_t u = djb2(a, len);
+ sprintf(digest,"%08x",u);
lua_pushstring(L, digest);
return 1;
}
diff --git a/tests/hash.lua b/tests/hash.lua
index e6099d5..76cb4a5 100644
--- a/tests/hash.lua
+++ b/tests/hash.lua
@@ -33,7 +33,7 @@ test("buzhash16","meow","0255")
test("cityhash32","meow","c41a03e9")
test("cityhash64","meow","e99b592ae1ff868b")
test("cityhash128","meow","d73f2b9c5501a6524097c5d815f2152")
-test("djb2","meow","17c9a913d")
+test("djb2","meow","7c9a913d")
test("farmhash32","meow","c41a03e9");
test("farmhash64","meow","e99b592ae1ff868b")
--maybe test fasthash, metrohash, sha512_t and murmur blehh