Documentation
¶
Index ¶
- Variables
- func Add[T Number](x, y T) T
- func Clamp[T Number](number, min, max T) T
- func ClampMax[T Number](number, max T) T
- func ClampMin[T Number](number, min T) T
- func CompareFloats[T constraints.Float](a, b, tolerance, relativeTolerance T) bool
- func Dereference[T any](pointer *T) T
- func Divide[T Number](x, y T) T
- func IsNil(value any) bool
- func Multiply[T Number](x, y T) T
- func RequireTypeAssert[T any](value any) (typ T, err error)
- func SetValue[T any](pointer **T, value T)
- func Subtract[T Number](x, y T) T
- func Ternary[T any](condition bool, incase T, otherwise T) T
- func TypeAssert[T any](value any) T
- type AltArray
- type Array
- type Channel
- type CircularArray
- type CircularChannel
- type CircularSlice
- type Map
- func (m *Map[Key, Value]) Clear(key Key)
- func (m *Map[Key, Value]) Delete(key Key)
- func (m *Map[Key, Value]) Len() int
- func (m *Map[Key, Value]) Load(key Key) (value Value, ok bool)
- func (m *Map[Key, Value]) Range() iter.Seq2[Key, Value]
- func (m *Map[Key, Value]) Store(key Key, value Value)
- func (m *Map[Key, Value]) Swap(key Key, value Value) (previous Value, loaded bool)
- type NonBlockingChannel
- func (c *NonBlockingChannel[T]) Clear()
- func (c *NonBlockingChannel[T]) Close()
- func (c *NonBlockingChannel[T]) Len() int
- func (c *NonBlockingChannel[T]) Overflow() T
- func (c *NonBlockingChannel[T]) OverflowCount() uint64
- func (c *NonBlockingChannel[T]) Pop() T
- func (c *NonBlockingChannel[T]) Push(item T)
- func (c *NonBlockingChannel[T]) Range() iter.Seq[T]
- type Number
- type Slice
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CompareFloats ¶
func CompareFloats[T constraints.Float](a, b, tolerance, relativeTolerance T) bool
func Dereference ¶
func Dereference[T any](pointer *T) T
Dereference with nil pointer dereference protection. Returns the zero value of the underlying type is the provided pointer is nil.
func Divide ¶
func Divide[T Number](x, y T) T
A generic divide function with divide by zero protection. If the denominator is zero, the maximum or mininum value of the generic type will be returned based on the sign of numerator.
func Multiply ¶
func Multiply[T Number](x, y T) T
A generic multiply function with overflow protection.
func RequireTypeAssert ¶
TODO: test Safer type assertion with error return that can panic and recover in case the type cannot be asserted and the generic zero value is nil. Returns an error if type assertion fails. If the generic zero value is nil, panic and recover instead.
func SetValue ¶
func SetValue[T any](pointer **T, value T)
Set the underlying value of a pointer with nil pointer dereference protection.
func Subtract ¶
func Subtract[T Number](x, y T) T
A generic subtract function with overflow protection.
func TypeAssert ¶
Safer generic type assertion. Returns zero value of the provided type is assertion fails. Beware that the asserted type can be nil in case of an interface, so this is not runtime safe!
Types ¶
type AltArray ¶
type AltArray[T any] struct { // contains filtered or unexported fields }
A generic fixed size slice with out-of-bounds protection by clamping indices to [0, len-1].
func NewAltArray ¶
type Array ¶
type Array[T any] struct { // contains filtered or unexported fields }
A generic fixed size slice with out-of-bounds protection by clamping indices to [0, len-1].
type Channel ¶
type Channel[T any] struct { // contains filtered or unexported fields }
A generic blocking channel with double closing and nil channel protection.
func NewChannel ¶
A generic channel with double closing and nil channel protection.
type CircularArray ¶
type CircularArray[T any] struct { // contains filtered or unexported fields }
A generic fixed size slice with out-of-bounds protection by allowing index overflow. Out-of-bounds indices are wrapped around like in a circular buffer.
func NewCircularArray ¶
func NewCircularArray[T any](length int) *CircularArray[T]
func (*CircularArray[T]) Clear ¶
func (a *CircularArray[T]) Clear()
func (*CircularArray[T]) Index ¶
func (a *CircularArray[T]) Index(i int) T
func (*CircularArray[T]) Len ¶
func (a *CircularArray[T]) Len() int
func (*CircularArray[T]) Set ¶
func (a *CircularArray[T]) Set(i int, value T)
type CircularChannel ¶
type CircularChannel[T any] struct { // contains filtered or unexported fields }
A generic, circular channel that blocks on pop, but not on push,
with double closing and nil channel protection.
Block until an new entry is available on pop. If the channel is full, the oldest entry will be dropped on push.
func NewCircularChannel ¶
func NewCircularChannel[T any](size int) *CircularChannel[T]
func (*CircularChannel[T]) Close ¶
func (c *CircularChannel[T]) Close()
func (*CircularChannel[T]) Len ¶
func (c *CircularChannel[T]) Len() int
func (*CircularChannel[T]) Pop ¶
func (c *CircularChannel[T]) Pop() T
func (*CircularChannel[T]) Push ¶
func (c *CircularChannel[T]) Push(item T)
type CircularSlice ¶
type CircularSlice[T any] struct { // contains filtered or unexported fields }
A generic slice with out-of-bounds protection by allowing index overflow. For reading, out-of-bounds indices are wrapped around like in a circular buffer. For writing, the slice will automatically grow its underlying capacity up to, a pre-determined maximum capacity base on the system memory statistics.
func NewCircularSlice ¶
func NewCircularSlice[T any](capacity int) CircularSlice[T]
func (CircularSlice[T]) Cap ¶
func (s CircularSlice[T]) Cap() int
func (CircularSlice[T]) Grow ¶
func (s CircularSlice[T]) Grow(n int)
func (CircularSlice[T]) Index ¶
func (s CircularSlice[T]) Index(index int) T
func (CircularSlice[T]) Len ¶
func (s CircularSlice[T]) Len() int
func (CircularSlice[T]) MaxCap ¶
func (s CircularSlice[T]) MaxCap() int
func (CircularSlice[T]) Set ¶
func (s CircularSlice[T]) Set(index int, value T)
type Map ¶
type Map[Key comparable, Value any] struct { // contains filtered or unexported fields }
type NonBlockingChannel ¶
type NonBlockingChannel[T any] struct { // contains filtered or unexported fields }
A generic non-blocking channel with double closing and nil channel protection. Returns the zero value of the generic type if no item is available on the channel. Increases the overflow counter when the channel is full.
func NewNonBlockingChannel ¶
func NewNonBlockingChannel[T any](size int) *NonBlockingChannel[T]
func (*NonBlockingChannel[T]) Close ¶
func (c *NonBlockingChannel[T]) Close()
func (*NonBlockingChannel[T]) Len ¶
func (c *NonBlockingChannel[T]) Len() int
func (*NonBlockingChannel[T]) Overflow ¶
func (c *NonBlockingChannel[T]) Overflow() T
func (*NonBlockingChannel[T]) OverflowCount ¶
func (c *NonBlockingChannel[T]) OverflowCount() uint64
func (*NonBlockingChannel[T]) Pop ¶
func (c *NonBlockingChannel[T]) Pop() T
func (*NonBlockingChannel[T]) Push ¶
func (c *NonBlockingChannel[T]) Push(item T)
func (*NonBlockingChannel[T]) Range ¶
func (c *NonBlockingChannel[T]) Range() iter.Seq[T]
TODO: test
type Number ¶
type Number interface { constraints.Integer | constraints.Float }
type Slice ¶
type Slice[T any] struct { // contains filtered or unexported fields }
A generic slice with out-of-bounds protection. For reading, out-of-bounds indices will be clamped to [0, len-1]. For writing, the slice will automatically grow its underlying capacity up to, a pre-determined maximum capacity base on the system memory statistics.