Documentation
¶
Overview ¶
Package csync provides concurrent data structures for safe access in multi-threaded environments.
Index ¶
- type LazySlice
- type Map
- func (m *Map[K, V]) Del(key K)
- func (m *Map[K, V]) Get(key K) (V, bool)
- func (m *Map[K, V]) GetOrSet(key K, fn func() V) V
- func (Map[K, V]) JSONSchemaAlias() any
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) MarshalJSON() ([]byte, error)
- func (m *Map[K, V]) Reset(input map[K]V)
- func (m *Map[K, V]) Seq() iter.Seq[V]
- func (m *Map[K, V]) Seq2() iter.Seq2[K, V]
- func (m *Map[K, V]) Set(key K, value V)
- func (m *Map[K, V]) Take(key K) (V, bool)
- func (m *Map[K, V]) UnmarshalJSON(data []byte) error
- type Slice
- func (s *Slice[T]) Append(items ...T)
- func (s *Slice[T]) Delete(index int) bool
- func (s *Slice[T]) Get(index int) (T, bool)
- func (s *Slice[T]) Len() int
- func (s *Slice[T]) Prepend(item T)
- func (s *Slice[T]) Seq() iter.Seq[T]
- func (s *Slice[T]) Seq2() iter.Seq2[int, T]
- func (s *Slice[T]) Set(index int, item T) bool
- func (s *Slice[T]) SetSlice(items []T)
- type VersionedMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LazySlice ¶
type LazySlice[K any] struct { // contains filtered or unexported fields }
LazySlice is a thread-safe lazy-loaded slice.
func NewLazySlice ¶
NewLazySlice creates a new slice and runs the [load] function in a goroutine to populate it.
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a concurrent map implementation that provides thread-safe access.
func NewLazyMap ¶
func NewLazyMap[K comparable, V any](load func() map[K]V) *Map[K, V]
NewLazyMap creates a new lazy-loaded map. The provided load function is executed in a separate goroutine to populate the map.
func NewMap ¶
func NewMap[K comparable, V any]() *Map[K, V]
NewMap creates a new thread-safe map with the specified key and value types.
func NewMapFrom ¶
func NewMapFrom[K comparable, V any](m map[K]V) *Map[K, V]
NewMapFrom creates a new thread-safe map from an existing map.
func (*Map[K, V]) GetOrSet ¶
func (m *Map[K, V]) GetOrSet(key K, fn func() V) V
GetOrSet gets and returns the key if it exists, otherwise, it executes the given function, set its return value for the given key, and returns it.
func (Map[K, V]) JSONSchemaAlias ¶
func (*Map[K, V]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Map[K, V]) Reset ¶
func (m *Map[K, V]) Reset(input map[K]V)
Reset replaces the inner map with the new one.
func (*Map[K, V]) Set ¶
func (m *Map[K, V]) Set(key K, value V)
Set sets the value for the specified key in the map.
func (*Map[K, V]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Slice ¶
type Slice[T any] struct { // contains filtered or unexported fields }
Slice is a thread-safe slice implementation that provides concurrent access.
func NewSliceFrom ¶
NewSliceFrom creates a new thread-safe slice from an existing slice.
func (*Slice[T]) Append ¶
func (s *Slice[T]) Append(items ...T)
Append adds an element to the end of the slice.
func (*Slice[T]) Prepend ¶
func (s *Slice[T]) Prepend(item T)
Prepend adds an element to the beginning of the slice.
type VersionedMap ¶
type VersionedMap[K comparable, V any] struct { // contains filtered or unexported fields }
VersionedMap is a thread-safe map that keeps track of its version.
func NewVersionedMap ¶
func NewVersionedMap[K comparable, V any]() *VersionedMap[K, V]
NewVersionedMap creates a new versioned, thread-safe map.
func (*VersionedMap[K, V]) Del ¶
func (m *VersionedMap[K, V]) Del(key K)
Del deletes the specified key from the map and increments the version.
func (*VersionedMap[K, V]) Get ¶
func (m *VersionedMap[K, V]) Get(key K) (V, bool)
Get gets the value for the specified key from the map.
func (*VersionedMap[K, V]) Len ¶
func (m *VersionedMap[K, V]) Len() int
Len returns the number of items in the map.
func (*VersionedMap[K, V]) Seq2 ¶
func (m *VersionedMap[K, V]) Seq2() iter.Seq2[K, V]
Seq2 returns an iter.Seq2 that yields key-value pairs from the map.
func (*VersionedMap[K, V]) Set ¶
func (m *VersionedMap[K, V]) Set(key K, value V)
Set sets the value for the specified key in the map and increments the version.
func (*VersionedMap[K, V]) Version ¶
func (m *VersionedMap[K, V]) Version() uint64
Version returns the current version of the map.