aboutsummaryrefslogtreecommitdiff
path: root/core/hash
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-12-29 12:24:47 +0000
committergingerBill <bill@gingerbill.org>2021-12-29 12:24:47 +0000
commitc987b8429219d9d823a658fd25a6661fe949bebd (patch)
treedbbb2ad43749eac757c324feb73ae278cc3d07a7 /core/hash
parenta9b17b5a37b611dae51da6153de8239dfa08f202 (diff)
Move bash.djbx33a to hash.odin
Diffstat (limited to 'core/hash')
-rw-r--r--core/hash/djbx33a.odin18
-rw-r--r--core/hash/hash.odin17
2 files changed, 17 insertions, 18 deletions
diff --git a/core/hash/djbx33a.odin b/core/hash/djbx33a.odin
deleted file mode 100644
index db286b660..000000000
--- a/core/hash/djbx33a.odin
+++ /dev/null
@@ -1,18 +0,0 @@
-package hash
-
-djbx33a :: proc(data: []byte) -> (result: [16]byte) #no_bounds_check {
- state := [4]u32{5381, 5381, 5381, 5381}
-
- s: u32 = 0
- for p in data {
- state[s] = (state[s] << 5) + state[s] + u32(p)
- s = (s + 1) & 3
- }
-
-
- (^u32le)(&result[0])^ = u32le(state[0])
- (^u32le)(&result[4])^ = u32le(state[1])
- (^u32le)(&result[8])^ = u32le(state[2])
- (^u32le)(&result[12])^ = u32le(state[3])
- return
-} \ No newline at end of file
diff --git a/core/hash/hash.odin b/core/hash/hash.odin
index f0d01bd25..5044d567a 100644
--- a/core/hash/hash.odin
+++ b/core/hash/hash.odin
@@ -55,6 +55,23 @@ djb2 :: proc(data: []byte, seed := u32(5381)) -> u32 {
return hash
}
+djbx33a :: proc(data: []byte, seed := u32(5381)) -> (result: [16]byte) #no_bounds_check {
+ state := [4]u32{seed, seed, seed, seed}
+
+ s: u32 = 0
+ for p in data {
+ state[s] = (state[s] << 5) + state[s] + u32(p) // hash * 33 + u32(b)
+ s = (s + 1) & 3
+ }
+
+
+ (^u32le)(&result[0])^ = u32le(state[0])
+ (^u32le)(&result[4])^ = u32le(state[1])
+ (^u32le)(&result[8])^ = u32le(state[2])
+ (^u32le)(&result[12])^ = u32le(state[3])
+ return
+}
+
@(optimization_mode="speed")
fnv32 :: proc(data: []byte, seed := u32(0x811c9dc5)) -> u32 {
h: u32 = seed