Skip to content

Commit

Permalink
redundant struct embedding for 2q backend
Browse files Browse the repository at this point in the history
  • Loading branch information
motoki317 committed Apr 17, 2022
1 parent acd525c commit 6d4dab2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
9 changes: 1 addition & 8 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ func (l lruBackend[K, V]) Purge() {
l.Cache.Flush()
}

type twoQueueBackend[K comparable, V any] struct {
*tq.Cache[K, V]
// As of Go 1.18, Go does not allow type alias of generic types, so we cannot write it like below and have to fall back
// to embedding in a struct.
// type twoQueueBackend[K comparable, V any] = *tq.Cache[K, V]
}

func new2QBackend[K comparable, V any](cap int) backend[K, V] {
return twoQueueBackend[K, V]{tq.New[K, V](cap)}
return tq.New[K, V](cap)
}
6 changes: 4 additions & 2 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"time"

"github.com/stretchr/testify/assert"

"github.com/motoki317/sc/tq"
)

func TestNewMust(t *testing.T) {
Expand Down Expand Up @@ -203,7 +205,7 @@ func TestNew(t *testing.T) {
c, err := New[string, string](fn, 0, 0, With2QBackend(10))
assert.NoError(t, err)
assert.IsType(t, &Cache[string, string]{}, c)
assert.IsType(t, twoQueueBackend[string, value[string]]{}, c.values)
assert.IsType(t, &tq.Cache[string, value[string]]{}, c.values)
assert.False(t, c.strictCoalescing)
})

Expand All @@ -213,7 +215,7 @@ func TestNew(t *testing.T) {
c, err := New[string, string](fn, 0, 0, With2QBackend(10), EnableStrictCoalescing())
assert.NoError(t, err)
assert.IsType(t, &Cache[string, string]{}, c)
assert.IsType(t, twoQueueBackend[string, value[string]]{}, c.values)
assert.IsType(t, &tq.Cache[string, value[string]]{}, c.values)
assert.True(t, c.strictCoalescing)
})
}
Expand Down

0 comments on commit 6d4dab2

Please sign in to comment.