unpack_string/hw04_lru_cache/cache.go

26 lines
421 B
Go
Raw Normal View History

2023-10-30 15:21:12 +03:00
package hw04lrucache
type Key string
type Cache interface {
Set(key Key, value interface{}) bool
Get(key Key) (interface{}, bool)
Clear()
}
type lruCache struct {
Cache // Remove me after realization.
capacity int
queue List
items map[Key]*ListItem
}
func NewCache(capacity int) Cache {
return &lruCache{
capacity: capacity,
queue: NewList(),
items: make(map[Key]*ListItem, capacity),
}
}