Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAndSet ¶
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 ¶
func SReverse[S ~[]E, E any](s S) S
SReverse reverse slice order. Doesn't clone slice. This is Fastest of these.
func SSReverse ¶
func SSReverse[S ~[]E, E any](s S) S
SSReverse reverse slice order. Doesn't clone slice. This is a Sample.
Types ¶
type RWMap ¶
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 ¶
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 ¶
func (m *RWMap[M, T, U]) Del(key T) U
Del deletes a key value pair from the map.
type RWSlice ¶
RWSlice is a type for a thread-safe Go slice. It tries to be short and simple. Tip: It's useful to create a type alias (it allows it):
type testersSlice = [int]testing.TB
Which shortens and makes easier to read its usage:
x.TxSlice(testers, func(s testersSlice) { s[goid()] = val })
func NewRWSlice ¶
NewRWSlice creates a new thread-safe slice that's as simple as possible. The first version had only two functions Tx and Rx to allow interact with the slice.
func (*RWSlice[S, T]) Add ¶
func (s *RWSlice[S, T]) Add(val T) T
Add adds a value to the thread-safe slice.
func (*RWSlice[S, T]) Rx ¶
func (s *RWSlice[S, T]) Rx(f func(s S))
Rx executes thread-safe read transaction i.e. critical section for the RWSlice.