x

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Del added in v0.9.1

func Del[M ~map[T]U, T comparable, U any](m *RWMap[M, T, U], key T) U

Del deletes a key value pair from the map.

func Get added in v0.9.1

func Get[M ~map[T]U, T comparable, U any](m *RWMap[M, T, U], key T) U

func GetAndSet added in v0.9.1

func GetAndSet[T any](ptr *T, val T) (old T)

GetAndSet gets value to the *ptr and returns the old one, after setting new.

func Rx added in v0.9.1

func Rx[M ~map[T]U, T comparable, U any](m *RWMap[M, T, U], f func(m M))

func SReverse added in v0.9.1

func SReverse[S ~[]E, E any](s S) S

SReverse reverse slice order. Doesn't clone slice. This is Fastest of these.

func SSReverse added in v0.9.1

func SSReverse[S ~[]E, E any](s S) S

SSReverse reverse slice order. Doesn't clone slice. This is a Sample.

func Set added in v0.9.1

func Set[M ~map[T]U, T comparable, U any](m *RWMap[M, T, U], key T, val U) U

Set sets a key value pair to the map.

func Swap added in v0.9.1

func Swap[T any](lhs, rhs *T) (nlhs T)

Swap two values, which must be given as ptr. Returns new lhs, aka rhs.

func Tx added in v0.9.1

func Tx[M ~map[T]U, T comparable, U any](m *RWMap[M, T, U], f func(m M))

Tx executes a critical section during the function given as an argument. This critical section allows the map be updated. If you only need to read the map please use the Rx function that's for a read-only critical section.

func Whom

func Whom[T any](b bool, yes, no T) T

Whom is exactly same as C/C++ ternary operator. In Go it's implemented with generics.

Types

type RWMap added in v0.9.1

type RWMap[M ~map[T]U, T comparable, U any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RWMap is a type for a thread-safe Go map. It tries to be short and simple. Tip: It's useful to create a type alias (it allows it):

testersMap = map[int]testing.TB

Which shortens and makes easier to read its usage:

x.Tx(testers, func(m testersMap) {
    delete(m, goid())
})

func NewRWMap added in v0.9.1

func NewRWMap[M ~map[T]U, T comparable, U any](size ...int) *RWMap[M, T, U]

NewRWMap creates a new thread-safe map that's as simple as possible. The first version had only two functions Tx and Rx to allow interact with the map.

Jump to

Keyboard shortcuts

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