containers

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2022 License: ISC Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IDTable

type IDTable[T any] map[uint64]T

IDTable is a map with random indexes for jobs and other cases where a random but unique index is required

func (IDTable[T]) Assign

func (id IDTable[T]) Assign(val T) uint64

Assign adds an object to the map and returns its assigned index

type RWSync

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

RWSync wraps any value in a RWMutex for safe concurrent use. Unlike Sync, concurrent read access is allowed (so don't use it for things like maps and pointers!)

func NewRWSync

func NewRWSync[T any](val T) *RWSync[T]

NewRWSync creates a new RWSync wrapper with a predefined value

func (*RWSync[T]) Get

func (s *RWSync[T]) Get() T

Get reads the wrapped value contained

func (*RWSync[T]) Set

func (s *RWSync[T]) Set(val T)

Set sets the value wrapped by the object

type Sync

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

Sync wraps any value in a mutex for safe concurrent use

func NewSync

func NewSync[T any](val T) *Sync[T]

NewSync creates a new Sync wrapper with a predefined value

func (*Sync[T]) Get

func (s *Sync[T]) Get() T

Get reads the wrapped value contained

func (*Sync[T]) Set

func (s *Sync[T]) Set(val T)

Set sets the value wrapped by the object

type SyncMap

type SyncMap[K comparable, T any] Sync[map[K]T]

SyncMap is a map wrapped in a mutex for safe concurrent use

func NewSyncMap

func NewSyncMap[K comparable, T any]() *SyncMap[K, T]

NewSyncMap creates a new Sync object with an empty map

func (*SyncMap[K, T]) Copy added in v0.0.3

func (s *SyncMap[K, T]) Copy() map[K]T

Copy returns a shallow copy of the wrapped map

func (*SyncMap[K, T]) DeleteKey

func (s *SyncMap[K, T]) DeleteKey(key K)

DeleteKey removes a key from the wrapped map

func (*SyncMap[K, T]) Get added in v0.2.1

func (s *SyncMap[K, T]) Get() map[K]T

Get is a wrapper to SyncMap.Copy for compatibility with Wrapped

func (*SyncMap[K, T]) GetKey

func (s *SyncMap[K, T]) GetKey(key K) (T, bool)

GetKey reads a key from the wrapper map

func (*SyncMap[K, T]) Set added in v0.2.1

func (s *SyncMap[K, T]) Set(val map[K]T)

Set allows to set the entire map at once, for compatibility with Wrapped

func (*SyncMap[K, T]) SetKey

func (s *SyncMap[K, T]) SetKey(key K, val T)

SetKey sets a value to the wrapped map

type SyncSlice added in v0.2.2

type SyncSlice[T any] Sync[[]T]

SyncSlice is a lice wrapped in a mutex for safe concurrent use

func NewSyncSlice added in v0.2.2

func NewSyncSlice[T any]() *SyncSlice[T]

NewSyncSlice creates a new Sync object with an empty slice

func (*SyncSlice[T]) Clear added in v0.2.2

func (s *SyncSlice[T]) Clear()

func (*SyncSlice[T]) Copy added in v0.2.2

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

Copy returns a shallow copy of the wrapped slice

func (*SyncSlice[T]) Get added in v0.2.2

func (s *SyncSlice[T]) Get() []T

Get is a wrapper to SyncSlice.Copy for compatibility with Wrapped

func (*SyncSlice[T]) GetIndex added in v0.2.2

func (s *SyncSlice[T]) GetIndex(index int) T

func (*SyncSlice[T]) Set added in v0.2.2

func (s *SyncSlice[T]) Set(val []T)

Set allows to set the entire slice at once, for compatibility with Wrapped

func (*SyncSlice[T]) SetIndex added in v0.2.2

func (s *SyncSlice[T]) SetIndex(index int, value T)

func (*SyncSlice[T]) Size added in v0.2.2

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

func (*SyncSlice[T]) Splice added in v0.2.2

func (s *SyncSlice[T]) Splice(start int, length int) []T

type Wrapped added in v0.1.1

type Wrapped[T any] interface {
	Get() T
	Set(T)
}

type WrappedMap added in v0.1.1

type WrappedMap[K comparable, V any] interface {
	Wrapped[map[K]V]
	GetKey(K)
	SetKey(K, V)
}

type WrappedSlice added in v0.2.2

type WrappedSlice[T any] interface {
	Wrapped[[]T]
	Size() int
	GetIndex(int) T
	SetIndex(int, T)
}

Jump to

Keyboard shortcuts

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