Documentation
¶
Overview ¶
Package concurrent provides a handful of thread-safe generic types.
Index ¶
- type Map
- func (m *Map[K, V]) Exists(k K) (exists bool)
- func (m *Map[K, V]) Get(k K) (v V, ok bool)
- func (m *Map[K, V]) Length() int
- func (m *Map[K, V]) ReadFunc(fn func(map[K]V))
- func (m *Map[K, V]) Remove(k K) (exists bool)
- func (m *Map[K, V]) Set(k K, v V)
- func (m *Map[K, V]) Values() []V
- func (m *Map[K, V]) WriteFunc(fn func(map[K]V))
- type OrderedSet
- type Set
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a concurrent map. It wraps the standard library's map with a mutex for concurrent access.
func (*Map[K, V]) ReadFunc ¶
func (m *Map[K, V]) ReadFunc(fn func(map[K]V))
ReadFunc runs fn with the mutex locked for reading. The raw map is passed to fn.
func (*Map[K, V]) Remove ¶
Remove removes a key from the map. It returns true if the key existed in the map, false otherwise.
type OrderedSet ¶
type OrderedSet[T comparable] struct { // contains filtered or unexported fields }
OrderedSet has the same usage as Set, but is ordered.
func NewOrderedSet ¶
func NewOrderedSet[T comparable](initial ...T) *OrderedSet[T]
NewOrderedSet returns a new OrderedSet.
func (*OrderedSet[T]) Add ¶
func (s *OrderedSet[T]) Add(v T) bool
Add adds a value to the set. It returns true if the value doesn't already exist, false otherwise.
func (*OrderedSet[T]) Append ¶
func (s *OrderedSet[T]) Append(values ...T)
Append adds a slice of values to the set.
func (*OrderedSet[T]) Exists ¶
func (s *OrderedSet[T]) Exists(v T) (exists bool)
Exists returns true if v exists in the set, false otherwise.
func (*OrderedSet[T]) Length ¶
func (s *OrderedSet[T]) Length() int
Length returns the length of the set.
func (*OrderedSet[T]) Remove ¶
func (s *OrderedSet[T]) Remove(v T) (exists bool)
Remove removes a value from the set. It returns true if the value existed in the set, false otherwise.
func (*OrderedSet[T]) Values ¶
func (s *OrderedSet[T]) Values() []T
Values returns all values in the set. The return slice is unordered.
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is a concurrent set. It is not ordered.
func (*Set[T]) Add ¶
Add adds a value to the set. It returns true if the value doesn't already exist, false otherwise.
func (*Set[T]) Append ¶
func (s *Set[T]) Append(values ...T)
Append adds a slice of values to the set.