Make hash procedures contextless where possible

This commit is contained in:
gingerBill
2024-03-27 12:54:37 +00:00
parent 3bc7c51325
commit 6422c090f2
4 changed files with 22 additions and 22 deletions
+4 -4
View File
@@ -1,6 +1,6 @@
package hash
ginger_hash8 :: proc(x: u8) -> u8 {
ginger_hash8 :: proc "contextless" (x: u8) -> u8 {
h := x * 251
h += ~(x << 3)
h ~= (x >> 1)
@@ -11,7 +11,7 @@ ginger_hash8 :: proc(x: u8) -> u8 {
}
ginger_hash16 :: proc(x: u16) -> u16 {
ginger_hash16 :: proc "contextless" (x: u16) -> u16 {
z := (x << 8) | (x >> 8)
h := z
h += ~(z << 5)
@@ -24,14 +24,14 @@ ginger_hash16 :: proc(x: u16) -> u16 {
}
ginger8 :: proc(data: []byte) -> u8 {
ginger8 :: proc "contextless" (data: []byte) -> u8 {
h := ginger_hash8(0)
for b in data {
h ~= ginger_hash8(b)
}
return h
}
ginger16 :: proc(data: []byte) -> u16 {
ginger16 :: proc "contextless" (data: []byte) -> u16 {
h := ginger_hash16(0)
for b in data {
h ~= ginger_hash16(u16(b))