Documentation ¶
Index ¶
- type LRUMap
- func (m *LRUMap[K, V]) Add(key K, value V) bool
- func (m *LRUMap[K, V]) AddWithHook(key K, value V, evict func(K, V)) bool
- func (m *LRUMap[K, V]) Cap() int
- func (m *LRUMap) Delete(key K) bool
- func (m *LRUMap[K, V]) Format(state fmt.State, verb rune)
- func (m *LRUMap[K, V]) Get(key K) (V, bool)
- func (m *LRUMap) Has(key K) bool
- func (m *LRUMap[K, V]) Init(len, cap int)
- func (m *LRUMap) Len() int
- func (m *LRUMap) Range(start, length int, fn func(int, K, V))
- func (m *LRUMap) RangeIf(start, length int, fn func(int, K, V) bool)
- func (m *LRUMap[K, V]) Set(key K, value V)
- func (m *LRUMap[K, V]) SetWithHook(key K, value V, evict func(K, V))
- func (m *LRUMap) Std() map[K]V
- func (m *LRUMap) Truncate(sz int, fn func(K, V))
- type OrderedMap
- func (m *OrderedMap[K, V]) Add(key K, value V) bool
- func (m *OrderedMap) Delete(key K) bool
- func (m *OrderedMap[K, V]) Format(state fmt.State, verb rune)
- func (m *OrderedMap[K, V]) Get(key K) (V, bool)
- func (m *OrderedMap) Has(key K) bool
- func (m *OrderedMap[K, V]) Index(idx int) (K, V, bool)
- func (m *OrderedMap[K, V]) Init(len int)
- func (m *OrderedMap) Len() int
- func (m *OrderedMap[K, V]) Pop(idx int) (K, V)
- func (m *OrderedMap[K, V]) Push(idx int, key K, value V)
- func (m *OrderedMap) Range(start, length int, fn func(int, K, V))
- func (m *OrderedMap) RangeIf(start, length int, fn func(int, K, V) bool)
- func (m *OrderedMap[K, V]) Set(key K, value V)
- func (m *OrderedMap) Std() map[K]V
- func (m *OrderedMap) Truncate(sz int, fn func(K, V))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRUMap ¶
type LRUMap[K comparable, V any] struct { // contains filtered or unexported fields }
LRU provides an ordered hashmap implementation that keeps elements ordered according to last recently used (hence, LRU).
func NewLRU ¶
func NewLRU[K comparable, V any](len, cap int) *LRUMap[K, V]
NewLRU returns a new instance of LRUMap with given initializing length and maximum capacity.
func (*LRUMap[K, V]) Add ¶
Add will add the given key-value pair to the map, pushing them to the front of the map. Returns false if already exists. Evicts old at maximum capacity.
func (*LRUMap[K, V]) AddWithHook ¶
AddWithHook performs .Add() but passing any evicted entry to given hook function.
func (*LRUMap) Delete ¶
func (m *LRUMap) Delete(key K) bool
Delete will delete given key from map, returns false if not found.
func (*LRUMap[K, V]) Format ¶
Format implements fmt.Formatter, allowing performant string formatting of map.
func (*LRUMap[K, V]) Get ¶
Get will fetch value for given key from map, in the process pushing it to the front of the map. Returns false if not found.
func (*LRUMap) RangeIf ¶
RangeIf passes given function over the requested range of the map. Returns early on 'fn' -> false.
func (*LRUMap[K, V]) Set ¶
func (m *LRUMap[K, V]) Set(key K, value V)
Set will ensure that given key-value pair exists in the map, by either adding new or updating existing, pushing them to the front of the map. Evicts old at maximum capacity.
func (*LRUMap[K, V]) SetWithHook ¶
func (m *LRUMap[K, V]) SetWithHook(key K, value V, evict func(K, V))
SetWithHook performs .Set() but passing any evicted entry to given hook function.
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap provides a hashmap implementation that tracks the order in which keys are added.
func NewOrdered ¶
func NewOrdered[K comparable, V any](len int) *OrderedMap[K, V]
NewOrdered returns a new instance of LRUMap with given initializing length and maximum capacity.
func (*OrderedMap[K, V]) Add ¶
func (m *OrderedMap[K, V]) Add(key K, value V) bool
Add will add the given key-value pair to the map, returns false if already exists.
func (*OrderedMap) Delete ¶
func (m *OrderedMap) Delete(key K) bool
Delete will delete given key from map, returns false if not found.
func (*OrderedMap[K, V]) Format ¶
func (m *OrderedMap[K, V]) Format(state fmt.State, verb rune)
Format implements fmt.Formatter, allowing performant string formatting of map.
func (*OrderedMap[K, V]) Get ¶
func (m *OrderedMap[K, V]) Get(key K) (V, bool)
Get will fetch value for given key from map. Returns false if not found.
func (*OrderedMap) Has ¶
func (m *OrderedMap) Has(key K) bool
Has returns whether key exists in map.
func (*OrderedMap[K, V]) Index ¶
func (m *OrderedMap[K, V]) Index(idx int) (K, V, bool)
Index returns the key-value pair at index from map. Returns false if index out of range.
func (*OrderedMap[K, V]) Init ¶
func (m *OrderedMap[K, V]) Init(len int)
Init will initialize this map with initial length.
func (*OrderedMap[K, V]) Pop ¶
func (m *OrderedMap[K, V]) Pop(idx int) (K, V)
Pop will remove and return the key-value pair at index in the map. Panics if index out of range.
func (*OrderedMap[K, V]) Push ¶
func (m *OrderedMap[K, V]) Push(idx int, key K, value V)
Push will insert the given key-value pair at index in the map. Panics if index out of range.
func (*OrderedMap) RangeIf ¶
RangeIf passes given function over the requested range of the map. Returns early on 'fn' -> false.
func (*OrderedMap[K, V]) Set ¶
func (m *OrderedMap[K, V]) Set(key K, value V)
Set will ensure that given key-value pair exists in the map, by either adding new or updating existing.