summaryrefslogtreecommitdiff
path: root/lru.go
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2025-09-03 20:59:24 +0300
committerMarin Ivanov <[email protected]>2025-09-03 20:59:24 +0300
commit220671ed46e10e4c67741286da493df1d45cdcfc (patch)
tree0711f179f4619959fd937c2929c6247ed8ab124a /lru.go
Initial release
Diffstat (limited to 'lru.go')
-rw-r--r--lru.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/lru.go b/lru.go
new file mode 100644
index 0000000..e0a386f
--- /dev/null
+++ b/lru.go
@@ -0,0 +1,24 @@
+package main
+
+import "encoding/binary"
+
+const (
+ // FNV-1a
+ offset32 = uint32(2166136261)
+ prime32 = uint32(16777619)
+)
+
+func hashPacket(p PacketTruncated) uint32 {
+ h := offset32
+ b := make([]byte, 12)
+ binary.BigEndian.PutUint32(b[0:4], p.To)
+ binary.BigEndian.PutUint32(b[4:8], p.From)
+ binary.BigEndian.PutUint32(b[8:12], p.ID)
+ for ; len(b) >= 4; b = b[4:] {
+ h = (h ^ uint32(b[0])) * prime32
+ h = (h ^ uint32(b[1])) * prime32
+ h = (h ^ uint32(b[2])) * prime32
+ h = (h ^ uint32(b[3])) * prime32
+ }
+ return h
+}