mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
Make hash procedures contextless where possible
This commit is contained in:
+4
-4
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user