Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 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.
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.
func (*RWMap[M, T, U]) Del ¶ added in v0.9.5
func (m *RWMap[M, T, U]) Del(key T) U
Del deletes a key value pair from the map. It checks that key exists. It doesn't panic if key doesn't exist. The return value is valid only if key exists other is Go's default init value for the type.
func (*RWMap[M, T, U]) Get ¶ added in v0.9.5
func (m *RWMap[M, T, U]) Get(key T) U
Get returns value for the key. If key doesn't exist it panics as normal map access without ok idiom does.
func (*RWMap[M, T, U]) Rx ¶ added in v0.9.5
func (m *RWMap[M, T, U]) Rx(f func(m M))
Rx executes a read-only critical section during the function given as an argument. This critical section allows the map be read only. If you only need to write the map please use the Tx function that's for a read-write critical section.
func (*RWMap[M, T, U]) Set ¶ added in v0.9.5
func (m *RWMap[M, T, U]) Set(key T, val U) U
Set sets a key value pair to the map with Go's normal map semantics.
func (*RWMap[M, T, U]) Tx ¶ added in v0.9.5
func (m *RWMap[M, T, U]) Tx(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.