csync

package
v1.11.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package csync provides concurrent data structures for safe access in multi-threaded environments.

Index

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

func NewLazySlice[K any](load func() []K) *LazySlice[K]

NewLazySlice creates a new slice and runs the [load] function in a goroutine to populate it.

func (*LazySlice[K]) Seq

func (s *LazySlice[K]) Seq() iter.Seq[K]

Seq returns an iterator that yields elements from the slice.

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]) Copy

func (m *Map[K, V]) Copy() map[K]V

Copy returns a copy of the inner map.

func (*Map[K, V]) Del

func (m *Map[K, V]) Del(key K)

Del deletes the specified key from the map.

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) (V, bool)

Get gets the value for the specified key from the 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]) JSONSchemaAlias() any

JSONSchemaAlias returns the underlying map type for JSON schema generation. Value receiver is required because github.com/invopop/jsonschema checks interface satisfaction on the non-pointer type after stripping pointers.

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

Len returns the number of items in the map.

func (*Map[K, V]) MarshalJSON

func (m *Map[K, V]) MarshalJSON() ([]byte, error)

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]) Seq

func (m *Map[K, V]) Seq() iter.Seq[V]

Seq returns an iter.Seq that yields values from the map.

func (*Map[K, V]) Seq2

func (m *Map[K, V]) Seq2() iter.Seq2[K, V]

Seq2 returns an iter.Seq2 that yields key-value pairs from the map.

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]) Take

func (m *Map[K, V]) Take(key K) (V, bool)

Take gets an item and then deletes it.

func (*Map[K, V]) UnmarshalJSON

func (m *Map[K, V]) UnmarshalJSON(data []byte) error

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 NewSlice

func NewSlice[T any]() *Slice[T]

NewSlice creates a new thread-safe slice.

func NewSliceFrom

func NewSliceFrom[T any](s []T) *Slice[T]

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]) Copy

func (s *Slice[T]) Copy() []T

Copy returns a copy of the inner slice.

func (*Slice[T]) Get

func (s *Slice[T]) Get(index int) (T, bool)

Get returns the element at the specified index.

func (*Slice[T]) Len

func (s *Slice[T]) Len() int

Len returns the number of elements in the slice.

func (*Slice[T]) Seq

func (s *Slice[T]) Seq() iter.Seq[T]

Seq returns an iterator that yields elements from the slice.

func (*Slice[T]) Seq2

func (s *Slice[T]) Seq2() iter.Seq2[int, T]

Seq2 returns an iterator that yields index-value pairs from the slice.

func (*Slice[T]) SetSlice

func (s *Slice[T]) SetSlice(items []T)

SetSlice replaces the entire slice with a new one.

type Value

type Value[T any] struct {
	// contains filtered or unexported fields
}

Value is a generic thread-safe wrapper for any value type.

For slices, use Slice. For maps, use Map. Pointers are not supported.

func NewValue

func NewValue[T any](t T) *Value[T]

NewValue creates a new Value with the given initial value.

Panics if t is a pointer, slice, or map. Use the dedicated types for those.

func (*Value[T]) Get

func (v *Value[T]) Get() T

Get returns the current value.

func (*Value[T]) Set

func (v *Value[T]) Set(t T)

Set updates the value.

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]) Copy

func (m *VersionedMap[K, V]) Copy() map[K]V

Copy returns a copy of the inner 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL