Skip to content

Commit

Permalink
refactor: replace djb2 with xored hash func
Browse files Browse the repository at this point in the history
  • Loading branch information
f1zm0 committed Apr 19, 2023
1 parent 5b80e14 commit 7c1bca0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
19 changes: 0 additions & 19 deletions pkg/hashing/djb2.go

This file was deleted.

19 changes: 19 additions & 0 deletions pkg/hashing/xorhash.go
@@ -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
}

0 comments on commit 7c1bca0

Please sign in to comment.