linter fixes
This commit is contained in:
2
go.mod
2
go.mod
@@ -1,5 +1,5 @@
|
|||||||
module git.wntrmute.dev/kyle/go-mru
|
module git.wntrmute.dev/kyle/go-mru
|
||||||
|
|
||||||
go 1.17
|
go 1.22
|
||||||
|
|
||||||
require github.com/benbjohnson/clock v1.3.5
|
require github.com/benbjohnson/clock v1.3.5
|
||||||
|
|||||||
12
mru.go
12
mru.go
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type item struct {
|
type item struct {
|
||||||
V interface{}
|
V any
|
||||||
access int64
|
access int64
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,11 +28,11 @@ type Cache struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New must be used to create a new Cache.
|
// New must be used to create a new Cache.
|
||||||
func New(cap int) *Cache {
|
func New(icap int) *Cache {
|
||||||
return &Cache{
|
return &Cache{
|
||||||
store: map[string]*item{},
|
store: map[string]*item{},
|
||||||
access: newTimestamps(cap),
|
access: newTimestamps(icap),
|
||||||
cap: cap,
|
cap: icap,
|
||||||
clock: clock.New(),
|
clock: clock.New(),
|
||||||
mtx: &sync.Mutex{},
|
mtx: &sync.Mutex{},
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ func (c *Cache) ConsistencyCheck() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store adds the value v to the cache under the k.
|
// Store adds the value v to the cache under the k.
|
||||||
func (c *Cache) Store(k string, v interface{}) {
|
func (c *Cache) Store(k string, v any) {
|
||||||
c.lock()
|
c.lock()
|
||||||
defer c.unlock()
|
defer c.unlock()
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ func (c *Cache) Store(k string, v interface{}) {
|
|||||||
|
|
||||||
// Get returns the value stored in the cache. If the item isn't present,
|
// Get returns the value stored in the cache. If the item isn't present,
|
||||||
// it will return false.
|
// it will return false.
|
||||||
func (c *Cache) Get(k string) (interface{}, bool) {
|
func (c *Cache) Get(k string) (any, bool) {
|
||||||
c.lock()
|
c.lock()
|
||||||
defer c.unlock()
|
defer c.unlock()
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package mru
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,10 +20,10 @@ type timestamps struct {
|
|||||||
cap int
|
cap int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTimestamps(cap int) *timestamps {
|
func newTimestamps(icap int) *timestamps {
|
||||||
return ×tamps{
|
return ×tamps{
|
||||||
ts: make([]timestamp, 0, cap),
|
ts: make([]timestamp, 0, icap),
|
||||||
cap: cap,
|
cap: icap,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ func (ts *timestamps) Swap(i, j int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ts *timestamps) Find(k string) (int, bool) {
|
func (ts *timestamps) Find(k string) (int, bool) {
|
||||||
for i := 0; i < len(ts.ts); i++ {
|
for i := range len(ts.ts) {
|
||||||
if ts.ts[i].k == k {
|
if ts.ts[i].k == k {
|
||||||
return i, true
|
return i, true
|
||||||
}
|
}
|
||||||
@@ -93,8 +94,8 @@ func (ts *timestamps) Delete(i int) {
|
|||||||
ts.ts = append(ts.ts[:i], ts.ts[i+1:]...)
|
ts.ts = append(ts.ts[:i], ts.ts[i+1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *timestamps) Dump() {
|
func (ts *timestamps) Dump(w io.Writer) {
|
||||||
for i := range ts.ts {
|
for i := range ts.ts {
|
||||||
fmt.Printf("%d: %s, %d\n", i, ts.K(i), ts.T(i))
|
fmt.Fprintf(w, "%d: %s, %d\n", i, ts.K(i), ts.T(i))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,5 +46,4 @@ func TestTimestamps(t *testing.T) {
|
|||||||
if ts.K(2) != "owl" {
|
if ts.K(2) != "owl" {
|
||||||
t.Fatalf("third key should be owl, have %s", ts.K(2))
|
t.Fatalf("third key should be owl, have %s", ts.K(2))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user