Documentation ¶
Index ¶
- type Bucket
- type Item
- type Key
- type LRUCache
- type PriorityQueue
- type RollingWindow
- type SafeMap
- func (m *SafeMap) Delete(key interface{})
- func (m *SafeMap) Load(key interface{}) (value interface{}, ok bool)
- func (m *SafeMap) LoadAndDelete(key interface{}) (value interface{}, loaded bool)
- func (m *SafeMap) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)
- func (m *SafeMap) Range(f func(key, value interface{}) bool)
- func (m *SafeMap) Store(key, value interface{})
- type Trie
- type TrieOption
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
}
RollingWindow is a window Accumulator implementation that uses some duration of time to determine the content of the window
func NewRollingWindow ¶
func NewRollingWindow(bucketSize int, bucketDuration time.Duration) *RollingWindow
NewRollingWindow manages a window with rolling time durations The given duration will be used to bucket data within the window
func (*RollingWindow) Add ¶
func (rw *RollingWindow) Add(v float64)
Add a value to the window using a time bucketing strategy
func (*RollingWindow) Reduce ¶
func (rw *RollingWindow) Reduce(fn func(*Bucket))
Reduce the window to a single value using a reduction function
type SafeMap ¶ added in v1.2.0
type SafeMap struct {
// contains filtered or unexported fields
}
SafeMap is an implementation of sync.Map using a sync.RWMutex
func (*SafeMap) Delete ¶ added in v1.2.0
func (m *SafeMap) Delete(key interface{})
Delete deletes the value for a key
func (*SafeMap) Load ¶ added in v1.2.0
Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map
func (*SafeMap) LoadAndDelete ¶ added in v1.2.0
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present
func (*SafeMap) LoadOrStore ¶ added in v1.2.0
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored
func (*SafeMap) Range ¶ added in v1.2.0
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently, Range may reflect any mapping for that key from any point during the Range call Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls
type Trie ¶ added in v1.3.5
type Trie struct {
// contains filtered or unexported fields
}
func NewTrie ¶ added in v1.3.0
func NewTrie(keywords []string, opts ...TrieOption) *Trie
NewTrie return a pointer of trie
func (*Trie) Delete ¶ added in v1.3.5
Delete delete a keyword from trie, be aware of that Delete execute soft delete
func (*Trie) DeleteAll ¶ added in v1.3.5
func (t *Trie) DeleteAll()
DeleteAll delete all keywords from trie
type TrieOption ¶ added in v1.3.0
type TrieOption func(root *Trie)