Skip to content

Commit

Permalink
[Chore] Switch from swiss.Map to standard map
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey Mayshev committed Mar 12, 2024
1 parent ffa6afc commit 40d56e2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ go 1.19

require (
github.com/dolthub/maphash v0.1.0
github.com/dolthub/swiss v0.2.1
github.com/gammazero/deque v0.2.1
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ=
github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4=
github.com/dolthub/swiss v0.2.1 h1:gs2osYs5SJkAaH5/ggVJqXQxRXtWshF6uE0lgR/Y3Gw=
github.com/dolthub/swiss v0.2.1/go.mod h1:8AhKZZ1HK7g18j7v7k6c5cYIGEZJcPn0ARsai8cUrh0=
github.com/gammazero/deque v0.2.1 h1:qSdsbG6pgp6nL7A0+K/B7s12mcCY/5l5SIUpMOl+dC0=
github.com/gammazero/deque v0.2.1/go.mod h1:LFroj8x4cMYCukHJDbxFCkT+r9AndaJnFMuZDV34tuU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
18 changes: 10 additions & 8 deletions internal/s3fifo/ghost.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ package s3fifo

import (
"github.com/dolthub/maphash"
"github.com/dolthub/swiss"
"github.com/gammazero/deque"

"github.com/maypok86/otter/internal/generated/node"
)

type ghost[K comparable, V any] struct {
q *deque.Deque[uint64]
m *swiss.Map[uint64, struct{}]
m map[uint64]struct{}
main *main[K, V]
small *small[K, V]
hasher maphash.Hasher[K]
Expand All @@ -33,14 +32,15 @@ type ghost[K comparable, V any] struct {
func newGhost[K comparable, V any](main *main[K, V]) *ghost[K, V] {
return &ghost[K, V]{
q: deque.New[uint64](),
m: swiss.NewMap[uint64, struct{}](64),
m: make(map[uint64]struct{}),
main: main,
hasher: maphash.NewHasher[K](),
}
}

func (g *ghost[K, V]) isGhost(n node.Node[K, V]) bool {
_, ok := g.m.Get(g.hasher.Hash(n.Key()))
h := g.hasher.Hash(n.Key())
_, ok := g.m[h]
return ok
}

Expand All @@ -49,7 +49,7 @@ func (g *ghost[K, V]) insert(deleted []node.Node[K, V], n node.Node[K, V]) []nod

h := g.hasher.Hash(n.Key())

if _, ok := g.m.Get(h); ok {
if _, ok := g.m[h]; ok {
return deleted
}

Expand All @@ -60,16 +60,18 @@ func (g *ghost[K, V]) insert(deleted []node.Node[K, V], n node.Node[K, V]) []nod

for g.q.Len() >= maxLength {
v := g.q.PopFront()
g.m.Delete(v)
delete(g.m, v)
}

g.q.PushBack(h)
g.m.Put(h, struct{}{})
g.m[h] = struct{}{}

return deleted
}

func (g *ghost[K, V]) clear() {
g.q.Clear()
g.m.Clear()
for k := range g.m {
delete(g.m, k)
}
}

0 comments on commit 40d56e2

Please sign in to comment.