xcollection

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Sum   float64
	Count int64
}

type Item added in v1.0.0

type Item struct {
	Value    interface{}
	Priority int64
	Index    int
}

type Key added in v1.0.0

type Key interface{}

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

func NewLRU(maxEntries int) *LRUCache

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) Add added in v1.0.0

func (c *LRUCache) Add(key Key, value interface{})

Add adds a value to the cache.

func (*LRUCache) Clear added in v1.0.0

func (c *LRUCache) Clear()

Clear purges all stored items from the cache.

func (*LRUCache) Get added in v1.0.0

func (c *LRUCache) Get(key Key) (value interface{}, ok bool)

Get looks up a key's value from the cache.

func (*LRUCache) Len added in v1.0.0

func (c *LRUCache) Len() int

Len returns the number of items in the cache.

func (*LRUCache) Remove added in v1.0.0

func (c *LRUCache) Remove(key Key)

Remove removes the provided key 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))

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL