Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace djb2 with xored hash func
- Loading branch information
Showing
2 changed files
with
19 additions
and
19 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package hashing | ||
|
||
// XORHash applies XOR to the given bytearray and then hashes it. | ||
func XORHash(s []byte) uint64 { | ||
k := []byte{'h', 'a', 'd', 'e', 's'} // randomize? | ||
for i := 0; i < len(s); i++ { | ||
s[i] ^= k[i%len(k)] | ||
} | ||
return djb2(s) | ||
} | ||
|
||
// simple djb2 hashing algorithm implementation. | ||
func djb2(s []byte) uint64 { | ||
var hash uint64 = 5381 | ||
for _, c := range s { | ||
hash = ((hash << 5) + hash) + uint64(c) | ||
} | ||
return hash | ||
} |