datastructures

package
v0.0.0-...-bf46863 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringComparator

func StringComparator(s1 string, s2 string) bool

Types

type SyncSet

type SyncSet[T comparable] struct {
	// contains filtered or unexported fields
}

A set-like data structure that is guaranteed to be data race free during write operations. It can return internal data as a slice with a comparator provided, so that the resulting slice has a deterministic ordering.

func NewSyncSet

func NewSyncSet[T comparable](initial []T) SyncSet[T]

func (*SyncSet[T]) Add

func (s *SyncSet[T]) Add(val T)

func (*SyncSet[T]) AddAll

func (s *SyncSet[T]) AddAll(vals []T)

func (*SyncSet[T]) Contains

func (s *SyncSet[T]) Contains(val T) bool

func (*SyncSet[T]) Remove

func (s *SyncSet[T]) Remove(val T)

func (*SyncSet[T]) RemoveAll

func (s *SyncSet[T]) RemoveAll(vals []T)

func (*SyncSet[T]) Size

func (s *SyncSet[T]) Size() int

func (*SyncSet[T]) ToOrderedSlice

func (s *SyncSet[T]) ToOrderedSlice(comparator func(T, T) bool) []T

type TypedNestedSyncMap

type TypedNestedSyncMap[K1 constraints.Ordered, K2 constraints.Ordered, V any] struct {
	*TypedSyncMap[K1, *TypedSyncMap[K2, V]]
	// contains filtered or unexported fields
}

A nested map data structure that is guaranteed to be data race free during write operations. It is the synchronous equivalent of type map[K1]map[K2]V. Besides `sync.Map`'s existing interfaces, it also provides convenient methods to read/write nested values directly. For example, to set value `v` for outer key `k1` and inner key `k2`, one can simply call StoreNested(k1, k2, v), without worrying about creating the inner map if it doesn't exist.

func NewTypedNestedSyncMap

func NewTypedNestedSyncMap[K1 constraints.Ordered, K2 constraints.Ordered, V any]() *TypedNestedSyncMap[K1, K2, V]

func (*TypedNestedSyncMap[K1, K2, V]) DeepApply

func (m *TypedNestedSyncMap[K1, K2, V]) DeepApply(toApply func(V))

func (*TypedNestedSyncMap[K1, K2, V]) DeepCopy

func (m *TypedNestedSyncMap[K1, K2, V]) DeepCopy(copier func(V) V) *TypedNestedSyncMap[K1, K2, V]

func (*TypedNestedSyncMap[K1, K2, V]) DeleteNested

func (m *TypedNestedSyncMap[K1, K2, V]) DeleteNested(key1 K1, key2 K2)

func (*TypedNestedSyncMap[K1, K2, V]) LoadNested

func (m *TypedNestedSyncMap[K1, K2, V]) LoadNested(key1 K1, key2 K2) (value V, ok bool)

func (*TypedNestedSyncMap[K1, K2, V]) LoadOrStoreNested

func (m *TypedNestedSyncMap[K1, K2, V]) LoadOrStoreNested(key1 K1, key2 K2, value V) (actual V, loaded bool)

func (*TypedNestedSyncMap[K1, K2, V]) StoreNested

func (m *TypedNestedSyncMap[K1, K2, V]) StoreNested(key1 K1, key2 K2, value V)

type TypedSyncMap

type TypedSyncMap[K constraints.Ordered, V any] struct {
	// contains filtered or unexported fields
}

A map-like data structure that is guaranteed to be data race free during write operations. It is a typed wrapper over the builtin typeless `sync.Map`. The CRUD interface is exactly the same as those of `sync.Map`.

func NewTypedSyncMap

func NewTypedSyncMap[K constraints.Ordered, V any]() *TypedSyncMap[K, V]

func (*TypedSyncMap[K, V]) DeepApply

func (m *TypedSyncMap[K, V]) DeepApply(toApply func(V))

func (*TypedSyncMap[K, V]) DeepCopy

func (m *TypedSyncMap[K, V]) DeepCopy(copier func(V) V) *TypedSyncMap[K, V]

func (*TypedSyncMap[K, V]) Delete

func (m *TypedSyncMap[K, V]) Delete(key K)

func (*TypedSyncMap[K, V]) Len

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

func (*TypedSyncMap[K, V]) Load

func (m *TypedSyncMap[K, V]) Load(key K) (value V, ok bool)

func (*TypedSyncMap[K, V]) LoadOrStore

func (m *TypedSyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

func (*TypedSyncMap[K, V]) Range

func (m *TypedSyncMap[K, V]) Range(f func(K, V) bool)

func (*TypedSyncMap[K, V]) Store

func (m *TypedSyncMap[K, V]) Store(key K, value V)

Jump to

Keyboard shortcuts

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