Documentation
¶
Index ¶
- Constants
- func BitBytesCount(bitSize int) int
- func BitWordsCount(bitSize int) int
- func BoolCmp(a, b bool) int
- func Complex128Cmp(a, b complex128) int
- func Complex64Cmp(a, b complex64) int
- func HeapFix[S ~[]E, E cmp.Ordered](h S, i int)
- func HeapPop[S ~[]E, E cmp.Ordered](h S) (S, E)
- func HeapPush[S ~[]E, E cmp.Ordered](h S, x E) S
- func HeapRemove[S ~[]E, E cmp.Ordered](h S, i int) (S, E)
- func Heapify[S ~[]E, E cmp.Ordered](h S)
- func InsertAt[E any](s []E, i int, v E) []E
- func IsAllZeroElem[E cmp.Ordered | ~bool](s []E) bool
- func MapAdd[M ~map[K]V, K comparable, V cmp.Ordered](a, b M) M
- func MapIntersect[M ~map[K]V, K, V comparable](a, b M) M
- func MapKeyValues[M ~map[K]V, K comparable, V any](m M) ([]K, []V)
- func MapKeys[M ~map[K]V, K comparable, V any](m M) []K
- func MapOrderedKeyValues[M ~map[K]V, K cmp.Ordered, V any](m M) ([]K, []V)
- func MapOrderedKeys[M ~map[K]V, K cmp.Ordered, V any](m M) []K
- func MapOrderedValues[M ~map[K]V, K cmp.Ordered, V any](m M) []V
- func MapUnion[M ~map[K]V, K comparable, V any](a, b M) M
- func MapValues[M ~map[K]V, K comparable, V any](m M) []V
- func OrderedCmp[T cmp.Ordered](a, b T) int
- func OrderedContains[T cmp.Ordered](set []T, elem T) bool
- func OrderedDelete[T cmp.Ordered](set []T, elem T) []T
- func OrderedIndexOf[T cmp.Ordered](set []T, elem T) int
- func OrderedIntersect[T cmp.Ordered](a, b []T) []T
- func OrderedPutIfAbsent[T cmp.Ordered](set []T, elem T) []T
- func OrderedUnion[T cmp.Ordered](a, b []T) []T
- func RemoveAt[E any](s []E, i int) []E
- func RemoveFirst[E comparable](s []E, elem E) []E
- func ReverseOrderedCmp[T cmp.Ordered](a, b T) int
- func Shrink[E any](s []E) []E
- func Shuffle[E any](s []E)
- func SortAndRemoveDup[E cmp.Ordered](s []E) []E
- type BitMap64
- func (bm BitMap64) ClearBit(i int)
- func (bm BitMap64) FlipBit(i int)
- func (bm BitMap64) FormattedString(width int) string
- func (bm BitMap64) IsZero() bool
- func (bm BitMap64) MustSetBit(i int) BitMap64
- func (bm BitMap64) OnesCount() int
- func (bm BitMap64) SetBit(i int)
- func (bm BitMap64) String() string
- func (bm BitMap64) TestAndClearBit(i int) bool
- func (bm BitMap64) TestAndSetBit(i int) bool
- func (bm BitMap64) TestBit(i int) bool
- type BitMap8
- func (bm BitMap8) ClearBit(i int)
- func (bm BitMap8) FlipBit(i int)
- func (bm BitMap8) FormattedString(width int) string
- func (bm BitMap8) IsZero() bool
- func (bm BitMap8) MustSetBit(i int) BitMap8
- func (bm BitMap8) OnesCount() int
- func (bm BitMap8) SetBit(i int)
- func (bm BitMap8) String() string
- func (bm BitMap8) TestAndClearBit(i int) bool
- func (bm BitMap8) TestAndSetBit(i int) bool
- func (bm BitMap8) TestBit(i int) bool
- type Color
- type Comparable
- type Comparator
- type Consistent
- func (c *Consistent) Add(node uint64)
- func (c *Consistent) AddElem(node string)
- func (c *Consistent) Clear()
- func (c *Consistent) Get(name string) string
- func (c *Consistent) GetNode(node uint64) uint64
- func (c *Consistent) GetTwo(name string) []string
- func (c *Consistent) GetTwoNodes(node uint64) []uint64
- func (c *Consistent) HasMember(node string) bool
- func (c *Consistent) HasMemberNode(node uint64) bool
- func (c *Consistent) Len() int
- func (c *Consistent) Members() []string
- func (c *Consistent) Remove(node uint64) bool
- func (c *Consistent) RemoveElem(node string) bool
- type Deque
- func (q *Deque[T]) At(i int) T
- func (q *Deque[T]) Back() T
- func (q *Deque[T]) Cap() int
- func (q *Deque[T]) Clear()
- func (q *Deque[T]) Front() T
- func (q *Deque[T]) IsEmpty() bool
- func (q *Deque[T]) Len() int
- func (q *Deque[T]) PopBack() T
- func (q *Deque[T]) PopFront() T
- func (q *Deque[T]) PushBack(elem T)
- func (q *Deque[T]) PushFront(elem T)
- func (q *Deque[T]) Rotate(n int)
- func (q *Deque[T]) Set(i int, elem T)
- func (q *Deque[T]) SetMinCapacity(minCapacityExp uint)
- type Float32Slice
- type Float64Slice
- type Int16Slice
- type Int32Slice
- type Int64Slice
- type Int8Slice
- type IntSlice
- type Iterator
- type KeyValVisitor
- type LRUCache
- func (c *LRUCache[K, V]) Cap() int
- func (c *LRUCache[K, V]) Contains(key K) bool
- func (c *LRUCache[K, V]) Get(key K) (V, bool)
- func (c *LRUCache[K, V]) GetOldest() (key K, value V, ok bool)
- func (c *LRUCache[K, V]) Keys() []K
- func (c *LRUCache[K, V]) Len() int
- func (c *LRUCache[K, V]) Peek(key K) (V, bool)
- func (c *LRUCache[K, V]) Purge()
- func (c *LRUCache[K, V]) Put(key K, value V) bool
- func (c *LRUCache[K, V]) Remove(key K) bool
- func (c *LRUCache[K, V]) RemoveOldest() (key K, value V, ok bool)
- func (c *LRUCache[K, V]) Resize(size int) int
- type LRUEntry
- type List
- func (l *List[T]) Back() *ListElem[T]
- func (l *List[T]) Front() *ListElem[T]
- func (l *List[T]) Init() *List[T]
- func (l *List[T]) InsertAfter(v T, mark *ListElem[T]) *ListElem[T]
- func (l *List[T]) InsertBefore(v T, mark *ListElem[T]) *ListElem[T]
- func (l *List[T]) Len() int
- func (l *List[T]) MoveAfter(e, mark *ListElem[T])
- func (l *List[T]) MoveBefore(e, mark *ListElem[T])
- func (l *List[T]) MoveToBack(e *ListElem[T])
- func (l *List[T]) MoveToFront(e *ListElem[T])
- func (l *List[T]) PushBack(v T) *ListElem[T]
- func (l *List[T]) PushBackList(other *List[T])
- func (l *List[T]) PushFront(v T) *ListElem[T]
- func (l *List[T]) PushFrontList(other *List[T])
- func (l *List[T]) Remove(e *ListElem[T]) T
- type ListElem
- type MapInterface
- type MutexMap
- func (m *MutexMap[K, V]) CloneMap() map[K]V
- func (m *MutexMap[K, V]) Contains(key K) bool
- func (m *MutexMap[K, V]) Delete(key K)
- func (m *MutexMap[K, V]) IsEmpty() bool
- func (m *MutexMap[K, V]) Keys() []K
- func (m *MutexMap[K, V]) Load(key K) (value V, ok bool)
- func (m *MutexMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *MutexMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *MutexMap[K, V]) Range(f func(key K, value V) (shouldContinue bool))
- func (m *MutexMap[K, V]) Size() int
- func (m *MutexMap[K, V]) Store(key K, value V)
- func (m *MutexMap[K, V]) Values() []V
- type PQItem
- type Pair
- type PriorityQueue
- type Range
- type SortedSet
- func (s *SortedSet[T]) Add(ele T, score int64) bool
- func (s *SortedSet[T]) Count(min, max int64) int
- func (s *SortedSet[T]) GetRange(start, end int, reverse bool) []T
- func (s *SortedSet[T]) GetRangeByScore(min, max int64, reverse bool) []T
- func (s *SortedSet[T]) GetRank(ele T, reverse bool) int
- func (s *SortedSet[T]) GetScore(ele T) int64
- func (s *SortedSet[T]) Len() int
- func (s *SortedSet[T]) Remove(ele T) bool
- func (s *SortedSet[T]) RemoveRangeByRank(start, end int) int
- func (s *SortedSet[T]) RemoveRangeByScore(min, max int64) int
- type StringSlice
- type TreeEntry
- type TreeMap
- func (m *TreeMap[K, V]) CeilingEntry(key K) *TreeEntry[K, V]
- func (m *TreeMap[K, V]) CeilingKey(key K) (K, bool)
- func (m *TreeMap[K, V]) Clear()
- func (m *TreeMap[K, V]) CloneMap() map[K]V
- func (m *TreeMap[K, V]) Contains(key K) bool
- func (m *TreeMap[K, V]) Delete(key K)
- func (m *TreeMap[K, V]) FirstEntry() *TreeEntry[K, V]
- func (m *TreeMap[K, V]) FirstKey() (K, bool)
- func (m *TreeMap[K, V]) FloorEntry(key K) *TreeEntry[K, V]
- func (m *TreeMap[K, V]) FloorKey(key K) (K, bool)
- func (m *TreeMap[K, V]) Get(key K) (V, bool)
- func (m *TreeMap[K, V]) GetEntry(key K) *TreeEntry[K, V]
- func (m *TreeMap[K, V]) GetOrDefault(key K, defVal V) V
- func (m *TreeMap[K, V]) HigherEntry(key K) *TreeEntry[K, V]
- func (m *TreeMap[K, V]) HigherKey(key K) (K, bool)
- func (m *TreeMap[K, V]) IsEmpty() bool
- func (m *TreeMap[K, V]) IterBackwards() iter.Seq2[K, V]
- func (m *TreeMap[K, V]) IterSeq() iter.Seq2[K, V]
- func (m *TreeMap[K, V]) Keys() []K
- func (m *TreeMap[K, V]) LastEntry() *TreeEntry[K, V]
- func (m *TreeMap[K, V]) LastKey() (K, bool)
- func (m *TreeMap[K, V]) Load(key K) (V, bool)
- func (m *TreeMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *TreeMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *TreeMap[K, V]) Put(key K, value V) V
- func (m *TreeMap[K, V]) PutIfAbsent(key K, value V) V
- func (m *TreeMap[K, V]) Range(visit func(key K, value V) (shouldContinue bool))
- func (m *TreeMap[K, V]) Remove(key K) bool
- func (m *TreeMap[K, V]) RootEntry() *TreeEntry[K, V]
- func (m *TreeMap[K, V]) Size() int
- func (m *TreeMap[K, V]) Store(key K, value V)
- func (m *TreeMap[K, V]) String() string
- func (m *TreeMap[K, V]) Swap(key K, value V) (previous V, loaded bool)
- func (m *TreeMap[K, V]) Values() []V
- type Uint16Slice
- type Uint32Slice
- type Uint64Slice
- type Uint8Slice
- type UintSlice
- type Visitor
- type ZSkipList
- func (zsl *ZSkipList[T]) Clear()
- func (zsl *ZSkipList[T]) Delete(score int64, ele T) *ZSkipListNode[T]
- func (zsl *ZSkipList[T]) DeleteRangeByRank(start, end int, dict map[T]int64) int
- func (zsl *ZSkipList[T]) DeleteRangeByScore(min, max int64, dict map[T]int64) int
- func (zsl *ZSkipList[T]) Dump(w io.Writer)
- func (zsl *ZSkipList[T]) FirstInRange(min, max int64) *ZSkipListNode[T]
- func (zsl *ZSkipList[T]) GetElementByRank(rank int) *ZSkipListNode[T]
- func (zsl *ZSkipList[T]) GetRank(score int64, ele T) int
- func (zsl *ZSkipList[T]) HeadNode() *ZSkipListNode[T]
- func (zsl *ZSkipList[T]) Height() int
- func (zsl *ZSkipList[T]) Insert(score int64, ele T) *ZSkipListNode[T]
- func (zsl *ZSkipList[T]) IsInRange(min, max int64) bool
- func (zsl *ZSkipList[T]) LastInRange(min, max int64) *ZSkipListNode[T]
- func (zsl *ZSkipList[T]) Len() int
- func (zsl *ZSkipList[T]) Range(action func(score int64, elem T))
- func (zsl *ZSkipList[T]) String() string
- func (zsl *ZSkipList[T]) TailNode() *ZSkipListNode[T]
- func (zsl *ZSkipList[T]) ToMap() map[T]int64
- func (zsl *ZSkipList[T]) UpdateScore(ele T, curScore, newScore int64) *ZSkipListNode[T]
- type ZSkipListNode
Constants ¶
const ( ZSKIPLIST_MAXLEVEL = 32 // Should be enough for 2^64 elements ZSKIPLIST_P = 0.25 // Skiplist P = 1/4 )
const (
ReplicaCount = 20 // 固定大小的虚拟节点数量
)
Variables ¶
This section is empty.
Functions ¶
func BitBytesCount ¶
func BitWordsCount ¶
func Complex128Cmp ¶
func Complex128Cmp(a, b complex128) int
func Complex64Cmp ¶
func HeapFix ¶
HeapFix re-establishes the heap ordering after the element at index i has changed its Value. Changing the Value of the element at index i and then calling Fix is equivalent to, but less expensive than, calling Remove(h, i) followed by a Push of the new Value. The complexity is O(log n) where n = h.Len().
func HeapPop ¶
HeapPop removes and returns the minimum element (according to Less) from the heap. Pop is equivalent to Remove(h, 0).
func HeapRemove ¶
HeapRemove removes and returns the element at index i from the heap.
func Heapify ¶
Heapify establishes the heap invariants required by the other routines in this package. Init is idempotent with respect to the heap invariants and may be called whenever the heap invariants may have been invalidated.
func IsAllZeroElem ¶
IsAllZeroElem 是否数组的所有元素都为0
func MapIntersect ¶
func MapIntersect[M ~map[K]V, K, V comparable](a, b M) M
MapIntersect 返回两个map的交集, a ∩ b
func MapKeyValues ¶
func MapKeyValues[M ~map[K]V, K comparable, V any](m M) ([]K, []V)
MapKeyValues 返回map的key和value列表
func MapOrderedKeyValues ¶
MapOrderedKeyValues 返回map里已排序的key和value列表
func MapOrderedKeys ¶
MapOrderedKeys 返回map里已排序的key列表
func MapOrderedValues ¶
MapOrderedValues 返回map里按key排序的value列表
func MapUnion ¶
func MapUnion[M ~map[K]V, K comparable, V any](a, b M) M
MapUnion 返回两个map的并集, copy of a ∪ b
func OrderedCmp ¶
func OrderedContains ¶
OrderedContains `elem`是否在有序数组`set`中
func OrderedDelete ¶
OrderedDelete 把`n`从有序数组中删除
func OrderedIndexOf ¶
OrderedIndexOf `elem`在有序数组`set`中的索引,如果不存在返回-1
func OrderedIntersect ¶
OrderedIntersect 有序数组交集, A ∩ B
func OrderedPutIfAbsent ¶
OrderedPutIfAbsent 插入`n`到有序数组
func ReverseOrderedCmp ¶
Types ¶
type BitMap64 ¶
type BitMap64 []uint64
func NewBitMap64 ¶
func (BitMap64) FormattedString ¶
FormattedString 按指定宽度对齐
func (BitMap64) MustSetBit ¶
MustSetBit 指定位是否为1,并且自动增长数组
func (BitMap64) TestAndClearBit ¶
TestAndClearBit returns the old Value of the bit at the given index and clears it.
func (BitMap64) TestAndSetBit ¶
TestAndSetBit returns the old Value of the bit at the given index and sets it to 1.
type BitMap8 ¶
type BitMap8 []uint8
func NewBitMap8 ¶
func (BitMap8) FormattedString ¶
FormattedString 按指定宽度对齐
func (BitMap8) TestAndClearBit ¶
TestAndClearBit returns the old Value of the bit at the given index and clears it.
func (BitMap8) TestAndSetBit ¶
TestAndSetBit returns the old Value of the bit at the given index and sets it to 1.
type Comparable ¶
type Comparable interface { // CompareTo returns an integer comparing two Comparables. // a.CompareTo(b) < 0 implies a < b // a.CompareTo(b) > 0 implies a > b // a.CompareTo(b) == 0 implies a == b CompareTo(b Comparable) int }
Comparable compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.) The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0. Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.
type Comparator ¶
Comparator compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. In the foregoing description, the notation sgn(expression) designates the mathematical signum function, which is defined to return one of -1, 0, or 1 according to whether the Value of expression is negative, zero or positive.
The implementor must ensure that sgn(compare(x, y)) == -sgn(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.) The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0. Finally, the implementor must ensure that compare(x, y)==0 implies that sgn(compare(x, z))==sgn(compare(y, z)) for all z. It is generally the case, but not strictly required that (compare(x, y)==0) == (x.equals(y)). Generally speaking, any comparator that violates this condition should clearly indicate this fact.
func Reversed ¶
func Reversed[T any](cmp Comparator[T]) Comparator[T]
type Consistent ¶
type Consistent struct {
// contains filtered or unexported fields
}
Consistent 一致性hash code inspired by github.com/stathat/consistent
func NewConsistent ¶
func NewConsistent() *Consistent
func (*Consistent) Add ¶
func (c *Consistent) Add(node uint64)
func (*Consistent) AddElem ¶
func (c *Consistent) AddElem(node string)
AddElem inserts an element node in the consistent hash.
func (*Consistent) Clear ¶
func (c *Consistent) Clear()
func (*Consistent) Get ¶
func (c *Consistent) Get(name string) string
Get returns an element close to where name hashes to in the circle.
func (*Consistent) GetNode ¶
func (c *Consistent) GetNode(node uint64) uint64
func (*Consistent) GetTwo ¶
func (c *Consistent) GetTwo(name string) []string
GetTwo returns the two closest distinct elements to the name input in the circle.
func (*Consistent) GetTwoNodes ¶
func (c *Consistent) GetTwoNodes(node uint64) []uint64
GetTwoNodes returns the two closest distinct elements to the name input in the circle.
func (*Consistent) HasMember ¶
func (c *Consistent) HasMember(node string) bool
func (*Consistent) HasMemberNode ¶
func (c *Consistent) HasMemberNode(node uint64) bool
func (*Consistent) Len ¶
func (c *Consistent) Len() int
func (*Consistent) Members ¶
func (c *Consistent) Members() []string
func (*Consistent) Remove ¶
func (c *Consistent) Remove(node uint64) bool
func (*Consistent) RemoveElem ¶
func (c *Consistent) RemoveElem(node string) bool
RemoveElem removes an element node from the hash.
type Deque ¶
type Deque[T any] struct { // contains filtered or unexported fields }
func NewDeque ¶
NewDeque creates a new Deque, optionally setting the current and minimum capacity when non-zero values are given for these.
To create a Deque with capacity to store 2048 items without resizing, and that will not resize below space for 32 items when removing itmes:
d := deque.NewList(2048, 32)
To create a Deque that has not yet allocated memory, but after it does will never resize to have space for less than 64 items:
d := deque.NewList(0, 64)
Note that interface{} values supplied here are rounded up to the nearest power of 2.
func (*Deque[T]) At ¶
At returns the element at index i in the queue without removing the element from the queue. This method accepts only non-negative index values. At(0) refers to the first element and is the same as Front(). At(Len()-1) refers to the last element and is the same as Back(). If the index is invalid, the call panics.
The purpose of At is to allow Deque to serve as a more general purpose circular buffer, where items are only added to and removed from the ends of the deque, but may be read from T place within the deque. Consider the case of a fixed-size circular log buffer: A new entry is pushed onto one end and when full the oldest is popped from the other end. All the log entries in the buffer must be readable without altering the buffer contents.
func (*Deque[T]) Back ¶
func (q *Deque[T]) Back() T
Back returns the element at the back of the queue. This is the element that would be returned by PopBack(). This call panics if the queue is empty.
func (*Deque[T]) Clear ¶
func (q *Deque[T]) Clear()
Clear removes all elements from the queue, but retains the current capacity. This is useful when repeatedly reusing the queue at high frequency to avoid GC during reuse. The queue will not be resized smaller as long as items are only added. Only when items are removed is the queue subject to getting resized smaller.
func (*Deque[T]) Front ¶
func (q *Deque[T]) Front() T
Front returns the element at the front of the queue. This is the element that would be returned by PopFront(). This call panics if the queue is empty.
func (*Deque[T]) PopBack ¶
func (q *Deque[T]) PopBack() T
PopBack removes and returns the element from the back of the queue. Implements LIFO when used with PushBack(). If the queue is empty, the call panics.
func (*Deque[T]) PopFront ¶
func (q *Deque[T]) PopFront() T
PopFront removes and returns the element from the front of the queue. Implements FIFO when used with PushBack(). If the queue is empty, the call panics.
func (*Deque[T]) PushBack ¶
func (q *Deque[T]) PushBack(elem T)
PushBack appends an element to the back of the queue. Implements FIFO when elements are removed with PopFront(), and LIFO when elements are removed with PopBack().
func (*Deque[T]) PushFront ¶
func (q *Deque[T]) PushFront(elem T)
PushFront prepends an element to the front of the queue.
func (*Deque[T]) Rotate ¶
Rotate rotates the deque n steps front-to-back. If n is negative, rotates back-to-front. Having Deque provide Rotate() avoids resizing that could happen if implementing rotation using only Pop and Push methods.
func (*Deque[T]) Set ¶
Set puts the element at index i in the queue. Set shares the same purpose than At() but perform the opposite operation. The index i is the same index defined by At(). If the index is invalid, the call panics.
func (*Deque[T]) SetMinCapacity ¶
SetMinCapacity sets a minimum capacity of 2^minCapacityExp. If the Value of the minimum capacity is less than or equal to the minimum allowed, then capacity is set to the minimum allowed. This may be called at anytime to set a new minimum capacity.
Setting a larger minimum capacity may be used to prevent resizing when the number of stored items changes frequently across a wide range.
type Float32Slice ¶
type Float32Slice []float32
func (Float32Slice) Len ¶
func (x Float32Slice) Len() int
func (Float32Slice) Less ¶
func (x Float32Slice) Less(i, j int) bool
func (Float32Slice) Swap ¶
func (x Float32Slice) Swap(i, j int)
type Float64Slice ¶
type Float64Slice = sort.Float64Slice
type Int16Slice ¶
type Int16Slice []int16
func (Int16Slice) Len ¶
func (x Int16Slice) Len() int
func (Int16Slice) Less ¶
func (x Int16Slice) Less(i, j int) bool
func (Int16Slice) Swap ¶
func (x Int16Slice) Swap(i, j int)
type Int32Slice ¶
type Int32Slice []int32
func (Int32Slice) Len ¶
func (x Int32Slice) Len() int
func (Int32Slice) Less ¶
func (x Int32Slice) Less(i, j int) bool
func (Int32Slice) Swap ¶
func (x Int32Slice) Swap(i, j int)
type Int64Slice ¶
type Int64Slice []int64
func (Int64Slice) Len ¶
func (x Int64Slice) Len() int
func (Int64Slice) Less ¶
func (x Int64Slice) Less(i, j int) bool
func (Int64Slice) Swap ¶
func (x Int64Slice) Swap(i, j int)
type KeyValVisitor ¶
type LRUCache ¶
type LRUCache[K comparable, V any] struct { // contains filtered or unexported fields }
LRUCache LRU缓存 https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)
func NewLRUCache ¶
func NewLRUCache[K comparable, V any](size int, onEvicted func(key K, value V)) *LRUCache[K, V]
func (*LRUCache[K, V]) RemoveOldest ¶
RemoveOldest 删除最老的的key-Value,并返回
type LRUEntry ¶
type LRUEntry[K comparable, V any] struct { Key K Value V }
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
List represents a doubly linked list. The zero Value for List is an empty list ready to use.
func (*List[T]) InsertAfter ¶
InsertAfter inserts a new element e with Value v immediately after mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.
func (*List[T]) InsertBefore ¶
InsertBefore inserts a new element e with Value v immediately before mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.
func (*List[T]) MoveAfter ¶
MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.
func (*List[T]) MoveBefore ¶
MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.
func (*List[T]) MoveToBack ¶
MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified. The element must not be nil.
func (*List[T]) MoveToFront ¶
MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil.
func (*List[T]) PushBack ¶
PushBack inserts a new element e with Value v at the back of list l and returns e.
func (*List[T]) PushBackList ¶
PushBackList inserts a copy of another list at the back of list l. The lists l and other may be the same. They must not be nil.
func (*List[T]) PushFront ¶
PushFront inserts a new element e with Value v at the front of list l and returns e.
func (*List[T]) PushFrontList ¶
PushFrontList inserts a copy of another list at the front of list l. The lists l and other may be the same. They must not be nil.
type ListElem ¶
type ListElem[T any] struct { // The Value stored with this element. Value T // contains filtered or unexported fields }
ListElem is an element of a linked list.
type MapInterface ¶
type MapInterface[K comparable, V any] interface { Size() int Contains(K) bool Load(K) (V, bool) Store(key K, value V) LoadOrStore(key K, value V) (actual V, loaded bool) LoadAndDelete(key K) (value V, loaded bool) Delete(K) Range(func(key K, value V) (shouldContinue bool)) Keys() []K Values() []V CloneMap() map[K]V }
MapInterface is the interface SyncMap implements.
type MutexMap ¶
type MutexMap[K comparable, V any] struct { // contains filtered or unexported fields }
MutexMap is an implementation of mapInterface using a sync.RWMutex.
func (*MutexMap[K, V]) LoadAndDelete ¶
func (*MutexMap[K, V]) LoadOrStore ¶
type Pair ¶ added in v1.0.12
type Pair[T1, T2 any] struct { First T1 Second T2 }
Pair is a type that provides a way to store two heterogeneous objects as a single unit.
type PriorityQueue ¶
A PriorityQueue implements heap.Interface and holds Items.
func (PriorityQueue[T]) Len ¶
func (pq PriorityQueue[T]) Len() int
func (PriorityQueue[T]) Less ¶
func (pq PriorityQueue[T]) Less(i, j int) bool
func (*PriorityQueue[T]) Pop ¶
func (pq *PriorityQueue[T]) Pop() any
func (*PriorityQueue[T]) Push ¶
func (pq *PriorityQueue[T]) Push(x any)
func (PriorityQueue[T]) Swap ¶
func (pq PriorityQueue[T]) Swap(i, j int)
type Range ¶ added in v1.0.12
Range contains a min value and a max value
func ParseRange ¶ added in v1.0.12
type SortedSet ¶
type SortedSet[T comparable] struct { // contains filtered or unexported fields }
SortedSet 跳表实现的有序字典
func NewSortedSet ¶
func NewSortedSet[T comparable](comparator Comparator[T]) *SortedSet[T]
func NewSortedSetCmp ¶
func (*SortedSet[T]) GetRangeByScore ¶
GetRangeByScore 获取score在[min, max]之间的所有元素
func (*SortedSet[T]) RemoveRangeByRank ¶
RemoveRangeByRank 删除排名在[start, end]之间的元素,排名从1开始
func (*SortedSet[T]) RemoveRangeByScore ¶
RemoveRangeByScore 删除score区间[min, max]的元素
type StringSlice ¶
type StringSlice = sort.StringSlice
type TreeEntry ¶
type TreeEntry[K comparable, V any] struct { Key K Value V // contains filtered or unexported fields }
func NewTreeEntry ¶
func NewTreeEntry[K comparable, V any](key K, val V, parent *TreeEntry[K, V]) *TreeEntry[K, V]
type TreeMap ¶
type TreeMap[K comparable, V any] struct { // contains filtered or unexported fields }
TreeMap is a Red-Black tree based map implementation. The map is sorted by a comparator passed to its constructor. This implementation provides guaranteed log(n) time cost for the Contains(), Get(), Put() and Remove() operations. Algorithms are adaptations of those in Cormen, Leiserson, and Rivest's <Introduction to Algorithms>.
func NewTreeMap ¶
func NewTreeMap[K comparable, V any](comparator Comparator[K]) *TreeMap[K, V]
func (*TreeMap[K, V]) CeilingEntry ¶
CeilingEntry gets the entry corresponding to the specified Key; returns the entry for the least Key greater than the specified Key if not exist.
func (*TreeMap[K, V]) CeilingKey ¶
CeilingKey gets the specified Key, return the least Key greater than the specified Key if not exist.
func (*TreeMap[K, V]) Clear ¶
func (m *TreeMap[K, V]) Clear()
Clear removes all the mappings from this map.
func (*TreeMap[K, V]) Contains ¶
Contains return true if this map contains a mapping for the specified Key
func (*TreeMap[K, V]) FirstEntry ¶
func (*TreeMap[K, V]) FirstKey ¶
FirstKey returns the first Key in the TreeMap (according to the Key's order)
func (*TreeMap[K, V]) FloorEntry ¶
FloorEntry gets the entry corresponding to the specified Key; if no such entry exists, returns the entry for the greatest Key less than the specified Key;
func (*TreeMap[K, V]) FloorKey ¶
FloorKey gets the specified Key, returns the greatest Key less than the specified Key if not exist.
func (*TreeMap[K, V]) Get ¶
Get returns the Value to which the specified Key is mapped, or nil if this map contains no mapping for the Key.
func (*TreeMap[K, V]) GetOrDefault ¶
func (m *TreeMap[K, V]) GetOrDefault(key K, defVal V) V
GetOrDefault returns the Value to which the specified Key is mapped, or `defaultValue` if this map contains no mapping for the Key.
func (*TreeMap[K, V]) HigherEntry ¶
HigherEntry gets the entry for the least Key greater than the specified Key
func (*TreeMap[K, V]) IterBackwards ¶
func (*TreeMap[K, V]) LastKey ¶
LastKey returns the last Key in the TreeMap (according to the Key's order)
func (*TreeMap[K, V]) LoadAndDelete ¶
LoadAndDelete deletes the Value for a Key, returning the previous Value if any. The loaded result reports whether the Key was present.
func (*TreeMap[K, V]) LoadOrStore ¶
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 (*TreeMap[K, V]) Put ¶
func (m *TreeMap[K, V]) Put(key K, value V) V
Put associates the specified Value with the specified Key in this map. If the map previously contained a mapping for the Key, the old Value is replaced.
func (*TreeMap[K, V]) PutIfAbsent ¶
func (m *TreeMap[K, V]) PutIfAbsent(key K, value V) V
PutIfAbsent put a Key-Value pair if the Key is not already associated with a Value.
func (*TreeMap[K, V]) Range ¶
Range calls f sequentially for each Key and Value present in the map. If f returns false, range stops the iteration.
func (*TreeMap[K, V]) Remove ¶
Remove removes the mapping for this Key from this TreeMap if present.
func (*TreeMap[K, V]) Store ¶
func (m *TreeMap[K, V]) Store(key K, value V)
Store sets the Value for a Key, equivalent to Put.
type Uint16Slice ¶
type Uint16Slice []uint16
func (Uint16Slice) Len ¶
func (x Uint16Slice) Len() int
func (Uint16Slice) Less ¶
func (x Uint16Slice) Less(i, j int) bool
func (Uint16Slice) Swap ¶
func (x Uint16Slice) Swap(i, j int)
type Uint32Slice ¶
type Uint32Slice []uint32
func (Uint32Slice) Len ¶
func (x Uint32Slice) Len() int
func (Uint32Slice) Less ¶
func (x Uint32Slice) Less(i, j int) bool
func (Uint32Slice) Swap ¶
func (x Uint32Slice) Swap(i, j int)
type Uint64Slice ¶
type Uint64Slice []uint64
func (Uint64Slice) Len ¶
func (x Uint64Slice) Len() int
func (Uint64Slice) Less ¶
func (x Uint64Slice) Less(i, j int) bool
func (Uint64Slice) Swap ¶
func (x Uint64Slice) Swap(i, j int)
type Uint8Slice ¶
type Uint8Slice []uint8
func (Uint8Slice) Len ¶
func (x Uint8Slice) Len() int
func (Uint8Slice) Less ¶
func (x Uint8Slice) Less(i, j int) bool
func (Uint8Slice) Swap ¶
func (x Uint8Slice) Swap(i, j int)
type ZSkipList ¶
type ZSkipList[T comparable] struct { // contains filtered or unexported fields }
ZSkipList 带索引的排序链表
func NewZSkipList ¶
func NewZSkipList[T comparable](comparator Comparator[T]) *ZSkipList[T]
func NewZSkipListCmp ¶
func (*ZSkipList[T]) Delete ¶
func (zsl *ZSkipList[T]) Delete(score int64, ele T) *ZSkipListNode[T]
Delete 删除对应score的节点
func (*ZSkipList[T]) DeleteRangeByRank ¶
DeleteRangeByRank delete nodes with rank [rank >= start && rank <= end]
func (*ZSkipList[T]) DeleteRangeByScore ¶
DeleteRangeByScore delete nodes with [score >= min && score <= max]
func (*ZSkipList[T]) FirstInRange ¶
func (zsl *ZSkipList[T]) FirstInRange(min, max int64) *ZSkipListNode[T]
FirstInRange find the first node that is contained in the specified range. Returns NULL when no element is contained in the range.
func (*ZSkipList[T]) GetElementByRank ¶
func (zsl *ZSkipList[T]) GetElementByRank(rank int) *ZSkipListNode[T]
GetElementByRank 根据排名获得节点,排名从1开始
func (*ZSkipList[T]) HeadNode ¶
func (zsl *ZSkipList[T]) HeadNode() *ZSkipListNode[T]
func (*ZSkipList[T]) Insert ¶
func (zsl *ZSkipList[T]) Insert(score int64, ele T) *ZSkipListNode[T]
Insert 插入一个不存在的节点
func (*ZSkipList[T]) LastInRange ¶
func (zsl *ZSkipList[T]) LastInRange(min, max int64) *ZSkipListNode[T]
LastInRange find the last node that is contained in the specified range. Returns NULL when no element is contained in the range.
func (*ZSkipList[T]) TailNode ¶
func (zsl *ZSkipList[T]) TailNode() *ZSkipListNode[T]
func (*ZSkipList[T]) UpdateScore ¶
func (zsl *ZSkipList[T]) UpdateScore(ele T, curScore, newScore int64) *ZSkipListNode[T]
UpdateScore 更新分数
type ZSkipListNode ¶
type ZSkipListNode[T comparable] struct { Ele T Score int64 // contains filtered or unexported fields }
ZSkipListNode
func (*ZSkipListNode[T]) Before ¶
func (n *ZSkipListNode[T]) Before() *ZSkipListNode[T]
func (*ZSkipListNode[T]) Next ¶
func (n *ZSkipListNode[T]) Next() *ZSkipListNode[T]
Next return next forward pointer