Documentation
¶
Index ¶
- func Del[M ~map[T]U, T comparable, U any](m *RWMap[M, T, U], key T) U
- func Get[M ~map[T]U, T comparable, U any](m *RWMap[M, T, U], key T) U
- func GetAndSet[T any](ptr *T, val T) (old T)
- func Rx[M ~map[T]U, T comparable, U any](m *RWMap[M, T, U], f func(m M))
- func SReverse[S ~[]E, E any](s S) S
- func SSReverse[S ~[]E, E any](s S) S
- func Set[M ~map[T]U, T comparable, U any](m *RWMap[M, T, U], key T, val U) U
- func Swap[T any](lhs, rhs *T) (nlhs T)
- func Tx[M ~map[T]U, T comparable, U any](m *RWMap[M, T, U], f func(m M))
- func Whom[T any](b bool, yes, no T) T
- type RWMap
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.
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())
})