csync

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 6 Imported by: 0

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

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

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

Delete removes the element at the specified index.

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

func (s *Slice[T]) Prepend(item T)

Prepend adds an element to the beginning of 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]) Set

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

Set updates the element at the specified index.

func (*Slice[T]) SetSlice

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

SetSlice replaces the entire slice with a new one.

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.

Jump to

Keyboard shortcuts

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