Documentation
¶
Index ¶
- type Element
- type Int
- 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) (swapped 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) *Ring[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 Element ¶
type Element[T any] struct { // contains filtered or unexported fields }
Element is a thread-safe element of a linked list.
type Int ¶ added in v0.1.82
type Int[T ~int64 | ~int32 | ~int16 | ~int8 | ~int] struct { // contains filtered or unexported fields }
An Int provides atomic operations on an integer value of type T. It is a generic wrapper around atomic.Int64, allowing usage with signed integer types such as int, int8, int16, int32, and int64.
func (*Int[T]) Add ¶ added in v0.1.82
func (v *Int[T]) Add(delta T) (new T)
Add atomically adds delta to the value and returns the new value.
func (*Int[T]) And ¶ added in v0.1.82
func (v *Int[T]) And(mask T) (old T)
And atomically performs a bitwise AND operation with mask and returns the previous value.
func (*Int[T]) CompareAndSwap ¶ added in v0.1.82
CompareAndSwap executes the compare-and-swap operation for the Int. It compares the current value with old, and if they are equal, sets it to new and returns true. Otherwise, it returns false.
func (*Int[T]) Load ¶ added in v0.1.82
func (v *Int[T]) Load() T
Load atomically loads and returns the current value.
func (*Int[T]) Or ¶ added in v0.1.82
func (v *Int[T]) Or(mask T) (old T)
Or atomically performs a bitwise OR operation with mask and returns the previous value.
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
List represents a thread-safe 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 comparable, Value any] struct { // contains filtered or unexported fields }
Map is a generic concurrency-safe map that wraps sync.Map and provides type-safe access for keys and values.
func NewMap ¶
func NewMap[Key comparable, Value any]() *Map[Key, Value]
NewMap creates and returns a new, empty generic concurrency-safe Map.
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 thread-safe, generic 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[T] is a one-element ring with a zero Value of type T.
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 ¶
func (v *Value[T]) Load() (val T)
Load returns the value set by the most recent Value.Store. If there has been no call to Value.Store for this Value, it returns the zero value of T.