xcollection

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 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
}

Bucket is a rolling window bucket

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
}

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 NewSafeMap added in v1.2.0

func NewSafeMap() *SafeMap

NewSafeMap returns a SafeMap

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

func (m *SafeMap) Load(key interface{}) (value interface{}, ok bool)

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

func (m *SafeMap) LoadAndDelete(key interface{}) (value interface{}, loaded bool)

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

func (m *SafeMap) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)

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

func (m *SafeMap) Range(f func(key, value interface{}) bool)

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

func (*SafeMap) Store added in v1.2.0

func (m *SafeMap) Store(key, value interface{})

Store sets the value for a key

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

func (t *Trie) Add(keyword string)

Add add a keyword to trie

func (*Trie) Delete added in v1.3.5

func (t *Trie) Delete(keyword string)

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

func (*Trie) Query added in v1.3.5

func (t *Trie) Query(text string) (sanitize string, keywords []string, exist bool)

Query find sensitive keywords and return them.

func (*Trie) QueryAll added in v1.3.5

func (t *Trie) QueryAll() (keywords []string)

QueryAll return all the keywords

type TrieOption added in v1.3.0

type TrieOption func(root *Trie)

func WithMask added in v1.3.0

func WithMask(mask rune) TrieOption

WithMask mask option

Jump to

Keyboard shortcuts

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