Documentation ¶
Index ¶
- type LeastRecentlyUsedBuffer
- func (lru *LeastRecentlyUsedBuffer) Add(elem string) (alreadyPresent bool, evicted string)
- func (lru *LeastRecentlyUsedBuffer) Clear()
- func (lru *LeastRecentlyUsedBuffer) Contains(elem string) bool
- func (lru *LeastRecentlyUsedBuffer) Len() int
- func (lru *LeastRecentlyUsedBuffer) Remove(elem string)
- func (lru *LeastRecentlyUsedBuffer) String() string
- type RingBuffer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LeastRecentlyUsedBuffer ¶
type LeastRecentlyUsedBuffer struct {
// contains filtered or unexported fields
}
LeastRecentlyUsedBuffer implements the least-recently-used caching algorithm using an in-memory buffer. All buffered elements are strings.
func NewLeastRecentlyUsedBuffer ¶
func NewLeastRecentlyUsedBuffer(maxCapacity int) *LeastRecentlyUsedBuffer
NewLeastRecentlyUsedBuffer returns an initialised LRU buffer.
func (*LeastRecentlyUsedBuffer) Add ¶
func (lru *LeastRecentlyUsedBuffer) Add(elem string) (alreadyPresent bool, evicted string)
Add the element into LRU buffer. If due to capacity reasons the oldest element was evicted in doing so, then return the evited element.
func (*LeastRecentlyUsedBuffer) Clear ¶
func (lru *LeastRecentlyUsedBuffer) Clear()
Clear the buffer.
func (*LeastRecentlyUsedBuffer) Contains ¶
func (lru *LeastRecentlyUsedBuffer) Contains(elem string) bool
Contains returns true only if the element is currently in the LRU buffer.
func (*LeastRecentlyUsedBuffer) Len ¶
func (lru *LeastRecentlyUsedBuffer) Len() int
Len returns the number of elements currently kept in the buffer.
func (*LeastRecentlyUsedBuffer) Remove ¶
func (lru *LeastRecentlyUsedBuffer) Remove(elem string)
Remove the elemnt from LRU buffer, freeing up a unit of capacity for more elements.
func (*LeastRecentlyUsedBuffer) String ¶
func (lru *LeastRecentlyUsedBuffer) String() string
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a rudimentary implementation of a fixed-size circular buffer. All buffered elements are strings.
func NewRingBuffer ¶
func NewRingBuffer(size int64) *RingBuffer
NewRingBuffer returns an initialised ring buffer.
func (*RingBuffer) Clear ¶
func (r *RingBuffer) Clear()
Clear sets all buffered elements to empty string, consequently GetAll function will return an empty string array indicating there's no element.
func (*RingBuffer) GetAll ¶
func (r *RingBuffer) GetAll() (ret []string)
GetAll returns all elements (oldest to the latest) of the ring buffer in a string array.
func (*RingBuffer) IterateReverse ¶
func (r *RingBuffer) IterateReverse(fun func(string) bool)
IterateReverse traverses the ring buffer from the latest element to the oldest element. The iterator function is fed an element value as sole parameter. If the function returns false, iteration is stopped immediately. The total number of elements iterated is not predictable, and iteration loop always skips empty elements.
func (*RingBuffer) Push ¶
func (r *RingBuffer) Push(elem string)
Push places a new element into ring buffer.