Documentation
¶
Index ¶
- type Cache
- func (c *Cache[Key, Value]) Clear()
- func (c *Cache[Key, Value]) Delete(key Key)
- func (c *Cache[Key, Value]) Get(key Key) (value Value, ok bool)
- func (c *Cache[Key, Value]) Set(key Key, value Value, lifecycle time.Duration, fn func() (Value, error))
- func (c *Cache[Key, Value]) Swap(key Key, value Value) (previous Value, loaded bool)
- type Element
- type List
- func (l *List[T]) Back() *Element[T]
- func (l *List[T]) Front() *Element[T]
- func (l *List[T]) Init() *List[T]
- func (l *List[T]) InsertAfter(v T, mark *Element[T]) *Element[T]
- func (l *List[T]) InsertBefore(v T, mark *Element[T]) *Element[T]
- func (l *List[T]) Len() int
- func (l *List[T]) MoveAfter(e, mark *Element[T])
- func (l *List[T]) MoveBefore(e, mark *Element[T])
- func (l *List[T]) MoveToBack(e *Element[T])
- func (l *List[T]) MoveToFront(e *Element[T])
- func (l *List[T]) PushBack(v T) *Element[T]
- func (l *List[T]) PushBackList(other *List[T])
- func (l *List[T]) PushFront(v T) *Element[T]
- func (l *List[T]) PushFrontList(other *List[T])
- func (l *List[T]) Remove(e *Element[T]) T
- type Map
- func (m *Map[Key, Value]) Clear()
- func (m *Map[Key, Value]) CompareAndDelete(key Key, old Value) (deleted bool)
- func (m *Map[Key, Value]) CompareAndSwap(key Key, old Value, new Value) bool
- func (m *Map[Key, Value]) Delete(key Key)
- func (m *Map[Key, Value]) Load(key Key) (value Value, ok bool)
- func (m *Map[Key, Value]) LoadAndDelete(key Key) (value Value, loaded bool)
- func (m *Map[Key, Value]) LoadOrStore(key Key, value Value) (actual Value, loaded bool)
- func (m *Map[Key, Value]) Range(f func(Key, Value) bool)
- func (m *Map[Key, Value]) Store(key Key, value Value)
- func (m *Map[Key, Value]) Swap(key Key, value Value) (previous Value, loaded bool)
- type Ring
- func (r *Ring[T]) Do(f func(*T))
- func (r *Ring[T]) Len() int
- func (r *Ring[T]) Link(s *Ring[T]) *Ring[T]
- func (r *Ring[T]) Move(n int) *Ring[T]
- func (r *Ring[T]) Next() *Ring[T]
- func (r *Ring[T]) Prev() *Ring[T]
- func (r *Ring[T]) Set(v T)
- func (r *Ring[T]) Unlink(n int) *Ring[T]
- func (r *Ring[T]) Value() *T
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[Key, Value any] struct { // contains filtered or unexported fields }
Cache is cache struct.
func (*Cache[Key, Value]) Clear ¶
func (c *Cache[Key, Value]) Clear()
Clear deletes all values in cache.
func (*Cache[Key, Value]) Delete ¶
func (c *Cache[Key, Value]) Delete(key Key)
Delete deletes the value for a key.
type Element ¶
type Element[T any] struct { // contains filtered or unexported fields }
Element is an element of a linked list.
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 Map ¶
type Map[Key, Value any] struct { // contains filtered or unexported fields }
func (*Map[Key, Value]) Clear ¶
func (m *Map[Key, Value]) Clear()
Clear deletes all the entries, resulting in an empty Map.
func (*Map[Key, Value]) CompareAndDelete ¶
CompareAndDelete deletes the entry for key if its value is equal to old. The old value must be of a comparable type.
If there is no current value for key in the map, CompareAndDelete returns false (even if the old value is the nil interface value).
func (*Map[Key, Value]) CompareAndSwap ¶
CompareAndSwap swaps the old and new values for key if the value stored in the map is equal to old. The old value must be of a comparable type.
func (*Map[Key, Value]) Delete ¶
func (m *Map[Key, Value]) Delete(key Key)
Delete deletes the value for a key.
func (*Map[Key, Value]) Load ¶
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 (*Map[Key, Value]) LoadAndDelete ¶
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.
func (*Map[Key, Value]) 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 (*Map[Key, Value]) Range ¶
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 (including by f), Range may reflect any mapping for that key from any point during the Range call. Range does not block other methods on the receiver; even f itself may call any method on m.
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 Ring ¶
type Ring[T any] struct { // contains filtered or unexported fields }
A Ring is an element of a circular list, or ring. Rings do not have a beginning or end; a pointer to any ring element serves as reference to the entire ring. Empty rings are represented as nil Ring pointers. The zero value for a Ring is a one-element ring with a nil Value.
func (*Ring[T]) Do ¶
func (r *Ring[T]) Do(f func(*T))
Do calls function f on each element of the ring, in forward order. The behavior of Do is undefined if f changes *r.
func (*Ring[T]) Len ¶
Len computes the number of elements in ring r. It executes in time proportional to the number of elements.
func (*Ring[T]) Link ¶
Link connects ring r with ring s such that r.Next() becomes s and returns the original value for r.Next(). r must not be empty.
If r and s point to the same ring, linking them removes the elements between r and s from the ring. The removed elements form a subring and the result is a reference to that subring (if no elements were removed, the result is still the original value for r.Next(), and not nil).
If r and s point to different rings, linking them creates a single ring with the elements of s inserted after r. The result points to the element following the last element of s after insertion.
func (*Ring[T]) Move ¶
Move moves n % r.Len() elements backward (n < 0) or forward (n >= 0) in the ring and returns that ring element. r must not be empty.
type Value ¶
type Value[T any] struct { // contains filtered or unexported fields }
A Value provides an atomic load and store of a specified typed value. Once Value.Store has been called, a Value must not be copied.
A Value must not be copied after first use.
func (*Value[T]) CompareAndSwap ¶
CompareAndSwap executes the compare-and-swap operation for the Value.
func (*Value[T]) Load ¶
Load returns the value set by the most recent Store and a boolean indicating whether a value was stored. If there has been no call to Store for this Value, it returns the zero value of T and false.
func (*Value[T]) MustLoad ¶
func (v *Value[T]) MustLoad() (val T)
MustLoad returns the value set by the most recent Store. It panics if there has been no call to Store for this Value.