26 lines
421 B
Go
26 lines
421 B
Go
|
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),
|
||
|
}
|
||
|
}
|