aboutsummaryrefslogtreecommitdiff
path: root/hash/func.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <sokolyuk@gmail.com>2021-11-22 13:48:19 +0100
committerDimitri Sokolyuk <sokolyuk@gmail.com>2021-11-22 13:48:19 +0100
commit1f1942ec0a4e55b3488a1771475994253bfe9b9e (patch)
tree0963f3b306cf5fdb7846c88102a18c462d096387 /hash/func.go
parent172fe8ad99288d4a4976089955a75bd28f5da764 (diff)
Move
Diffstat (limited to 'hash/func.go')
-rw-r--r--hash/func.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/hash/func.go b/hash/func.go
new file mode 100644
index 0000000..41c4fd5
--- /dev/null
+++ b/hash/func.go
@@ -0,0 +1,13 @@
+package hash
+
+// defaultHash is Chris Torek's hash function
+func defaultHash(key []byte) uint32 {
+ var h uint32
+ for _, v := range key {
+ h = hash4b(h, v)
+ }
+ return h
+}
+
+func hash4a(h uint32, v byte) uint32 { return (h << 5) - h + uint32(v) }
+func hash4b(h uint32, v byte) uint32 { return (h << 5) + h + uint32(v) }