Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRUCache ¶ added in v1.0.0
type LRUCache struct {
// MaxEntries is the maximum number of cache entries before
// an item is evicted. Zero means no limit.
MaxEntries int
// OnEvicted optionally specifies a callback function to be
// executed when an entry is purged from the cache.
OnEvicted func(key Key, value interface{})
// contains filtered or unexported fields
}
Cache is an LRU cache. It is not safe for concurrent access.
func NewLRU ¶ added in v1.0.0
New creates a new Cache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.
func (*LRUCache) Clear ¶ added in v1.0.0
func (c *LRUCache) Clear()
Clear purges all stored items from the cache.
func (*LRUCache) RemoveOldest ¶ added in v1.0.0
func (c *LRUCache) RemoveOldest()
RemoveOldest removes the oldest item from the cache.
type PriorityQueue ¶ added in v1.0.0
type PriorityQueue []*Item
this is a priority queue as implemented by a min heap ie. the 0th element is the *lowest* value
func NewPriorityQueue ¶ added in v1.0.0
func NewPriorityQueue(capacity int) PriorityQueue
func (PriorityQueue) Len ¶ added in v1.0.0
func (pq PriorityQueue) Len() int
Len returns the number of items in the queue
func (PriorityQueue) Less ¶ added in v1.0.0
func (pq PriorityQueue) Less(i, j int) bool
Less check the priority of two element in the queue
func (*PriorityQueue) PeekAndShift ¶ added in v1.0.0
func (pq *PriorityQueue) PeekAndShift(max int64) (*Item, int64)
PeekAndShift return the first element or nil, and update the item priority at the same time
func (*PriorityQueue) Pop ¶ added in v1.0.0
func (pq *PriorityQueue) Pop() interface{}
Pop pop out an element from the queue
func (*PriorityQueue) Push ¶ added in v1.0.0
func (pq *PriorityQueue) Push(x interface{})
Push push an element into the queue
func (PriorityQueue) Swap ¶ added in v1.0.0
func (pq PriorityQueue) Swap(i, j int)
Swap swap two element index in the queue
type RollingWindow ¶
type RollingWindow struct {
// contains filtered or unexported fields
}
func NewRollingWindow ¶
func NewRollingWindow(bucketSize int, bucketDuration time.Duration) *RollingWindow
func (*RollingWindow) Add ¶
func (rw *RollingWindow) Add(v float64)
func (*RollingWindow) Reduce ¶
func (rw *RollingWindow) Reduce(fn func(*Bucket))