Documentation
¶
Index ¶
- func Camel(s string) string
- func Cased(s string, fn ...CasedFn) string
- func Clamp[T Float](v T, minimum T, maximum T) T
- func Clamp01[T Float](v T) T
- func ClampFit[T Float](x T, oldMin T, oldMax T, newMin T, newMax T) T
- func ClampFit01[T Float](x T, newMin T, newMax T) T
- func CtxSlog(ctx context.Context) (logger *slog.Logger, ok bool)
- func CtxWithSlog(ctx context.Context, slog *slog.Logger) context.Context
- func DebounceWithMaxWait(waitTime time.Duration, maxWaitTime time.Duration, ...) func(context.Context) error
- func EaseInBack[T Float](t T) T
- func EaseInBounce[T Float](t T) T
- func EaseInCirc[T Float](t T) T
- func EaseInCubic[T Float](t T) T
- func EaseInElastic[T Float](t T) T
- func EaseInExpo[T Float](t T) T
- func EaseInOutBack[T Float](t T) T
- func EaseInOutBounce[T Float](t T) T
- func EaseInOutCirc[T Float](t T) T
- func EaseInOutCubic[T Float](t T) T
- func EaseInOutElastic[T Float](t T) T
- func EaseInOutExpo[T Float](t T) T
- func EaseInOutQuad[T Float](t T) T
- func EaseInOutQuart[T Float](t T) T
- func EaseInOutQuint[T Float](t T) T
- func EaseInOutSine[T Float](t T) T
- func EaseInQuad[T Float](t T) T
- func EaseInQuart[T Float](t T) T
- func EaseInQuint[T Float](t T) T
- func EaseInSine[T Float](t T) T
- func EaseLinear[T Float](t T) T
- func EaseOutBack[T Float](t T) T
- func EaseOutBounce[T Float](t T) T
- func EaseOutCirc[T Float](t T) T
- func EaseOutCubic[T Float](t T) T
- func EaseOutElastic[T Float](t T) T
- func EaseOutExpo[T Float](t T) T
- func EaseOutQuad[T Float](t T) T
- func EaseOutQuart[T Float](t T) T
- func EaseOutQuint[T Float](t T) T
- func EaseOutSine[T Float](t T) T
- func Fit[T Float](x T, oldMin T, oldMax T, newMin T, newMax T) T
- func Fit01[T Float](x T, newMin T, newMax T) T
- func FitMax[T Float](x T, newMax T) T
- func FreePort() (port int, err error)
- func Kebab(s string) string
- func Lower(s string) string
- func MusicalRatio(name MusicalRatioName) float64
- func Pascal(s string) string
- func RandIntRange[T Integer](r *rand.Rand, min, max T) T
- func RandNegOneToOneClamped[T Float](r *rand.Rand) T
- func RandSliceItem[T any](r *rand.Rand, slice []T) T
- func ReadFloat32(r io.Reader) (float32, error)
- func ReadInt32(r io.Reader) (int32, error)
- func ReadInt64(r io.Reader) (int64, error)
- func ReadString(r io.Reader) (string, error)
- func ReadUint8(r io.Reader) (uint8, error)
- func ReadUint32(r io.Reader) (uint32, error)
- func ReadUint64(r io.Reader) (uint64, error)
- func RoundFit01[T Float](x T, newMin T, newMax T) T
- func ScreamingSnake(s string) string
- func Snake(s string) string
- func Upper(s string) string
- func WriteFloat32(w io.Writer, v float32) error
- func WriteInt32(w io.Writer, v int32) error
- func WriteInt64(w io.Writer, v int64) error
- func WriteString(w io.Writer, s string) error
- func WriteUint8(w io.Writer, v uint8) error
- func WriteUint32(w io.Writer, v uint32) error
- func WriteUint64(w io.Writer, v uint64) error
- type CasedFn
- type CasedString
- type CtxErrFunc
- type CtxKey
- type EasingFunc
- type EasingMode
- type EventBus
- type EventBusAsync
- type EventBusSync
- type Float
- type Handle
- type Integer
- type MusicalRatioName
- type Pool
- type PoolOption
- type SparseSet
- func (s *SparseSet[T]) Cap() int
- func (s *SparseSet[T]) Clear()
- func (s *SparseSet[T]) Contains(h Handle) bool
- func (s *SparseSet[T]) Get(h Handle) (T, bool)
- func (s *SparseSet[T]) GetRef(h Handle) (*T, bool)
- func (s *SparseSet[T]) Handles() []Handle
- func (s *SparseSet[T]) Insert(v T) Handle
- func (s *SparseSet[T]) Len() int
- func (s *SparseSet[T]) Range(f func(h Handle, v *T) bool)
- func (s *SparseSet[T]) Remove(h Handle) bool
- func (s *SparseSet[T]) Reserve(n int)
- func (s *SparseSet[T]) ReserveSlots(n int)
- func (s *SparseSet[T]) Values() []T
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClampFit01 ¶
func ClampFit01[T Float](x T, newMin T, newMax T) T
func DebounceWithMaxWait ¶
func DebounceWithMaxWait(waitTime time.Duration, maxWaitTime time.Duration, fn func(context.Context) error) func(context.Context) error
DebounceWithMaxWait creates a debounced function that waits for a quiet period before executing, but guarantees execution within a maximum wait time.
func EaseInOutBack ¶
func EaseInOutBack[T Float](t T) T
func EaseInOutBounce ¶
func EaseInOutBounce[T Float](t T) T
func EaseInOutCirc ¶
func EaseInOutCirc[T Float](t T) T
func EaseInOutCubic ¶
func EaseInOutCubic[T Float](t T) T
func EaseInOutElastic ¶
func EaseInOutElastic[T Float](t T) T
func EaseInOutExpo ¶
func EaseInOutExpo[T Float](t T) T
func EaseInOutQuad ¶
func EaseInOutQuad[T Float](t T) T
func EaseInOutQuart ¶
func EaseInOutQuart[T Float](t T) T
func EaseInOutQuint ¶
func EaseInOutQuint[T Float](t T) T
func EaseInOutSine ¶
func EaseInOutSine[T Float](t T) T
func EaseOutBack ¶
func EaseOutBack[T Float](t T) T
func EaseOutBounce ¶
func EaseOutBounce[T Float](t T) T
func EaseOutCirc ¶
func EaseOutCirc[T Float](t T) T
func EaseOutCubic ¶
func EaseOutCubic[T Float](t T) T
func EaseOutElastic ¶
func EaseOutElastic[T Float](t T) T
func EaseOutExpo ¶
func EaseOutExpo[T Float](t T) T
func EaseOutQuad ¶
func EaseOutQuad[T Float](t T) T
func EaseOutQuart ¶
func EaseOutQuart[T Float](t T) T
func EaseOutQuint ¶
func EaseOutQuint[T Float](t T) T
func EaseOutSine ¶
func EaseOutSine[T Float](t T) T
func MusicalRatio ¶
func MusicalRatio(name MusicalRatioName) float64
func RandIntRange ¶
func RandNegOneToOneClamped ¶
func RandSliceItem ¶
func ReadFloat32 ¶
ReadFloat32 reads a little-endian IEEE 754 float32.
func ReadString ¶
ReadString reads a length-prefixed string with a uint32 length.
func ReadUint32 ¶
ReadUint32 reads a little-endian uint32.
func ReadUint64 ¶
ReadUint64 reads a little-endian uint64.
func RoundFit01 ¶
func RoundFit01[T Float](x T, newMin T, newMax T) T
func ScreamingSnake ¶
func WriteFloat32 ¶
WriteFloat32 writes v in little-endian IEEE 754 binary form.
func WriteInt32 ¶
WriteInt32 writes v in little-endian order.
func WriteInt64 ¶
WriteInt64 writes v in little-endian order.
func WriteString ¶
WriteString writes a length-prefixed string with a uint32 length.
func WriteUint8 ¶
WriteUint8 writes v in little-endian order.
func WriteUint32 ¶
WriteUint32 writes v in little-endian order.
Types ¶
type CasedString ¶
type CasedString struct {
Original string
Pascal string
Camel string
Snake string
ScreamingSnake string
Kebab string
Upper string
Lower string
}
func ToCasedString ¶
func ToCasedString(s string) CasedString
type CtxErrFunc ¶
func CallNTimesWithDelay ¶
func CallNTimesWithDelay(d time.Duration, n int, fn CtxErrFunc) CtxErrFunc
func Debounce ¶
func Debounce(d time.Duration, fn CtxErrFunc) CtxErrFunc
Debounce will only call the function after d duration has passed since the last call.
func Throttle ¶
func Throttle(d time.Duration, fn CtxErrFunc) CtxErrFunc
Throttle will only allow the function to be called once every d duration.
type EasingFunc ¶
type EasingFunc[T Float] func(t T) T
EasingFunc is a function that takes a normalized time t in [0,1] and returns the eased value in [0,1].
func Ease ¶
func Ease[T Float](mode EasingMode) EasingFunc[T]
Ease returns a named easing function. Unknown names fall back to linear. Accepted names are case-insensitive and allow dashes/underscores/spaces, e.g.:
"linear", "in-quad", "easeInCubic", "inout-sine", "out_bounce", etc.
type EasingMode ¶
type EasingMode string
const ( EasingModeLinear EasingMode = "linear" EasingModeInQuad EasingMode = "inquad" EasingModeOutQuad EasingMode = "outquad" EasingModeInOutQuad EasingMode = "inoutquad" EasingModeInCubic EasingMode = "incubic" EasingModeOutCubic EasingMode = "outcubic" EasingModeInOutCubic EasingMode = "inoutcubic" EasingModeInQuart EasingMode = "inquart" EasingModeOutQuart EasingMode = "outquart" EasingModeInOutQuart EasingMode = "inoutquart" EasingModeInQuint EasingMode = "inquint" EasingModeOutQuint EasingMode = "outquint" EasingModeInOutQuint EasingMode = "inoutquint" EasingModeInSine EasingMode = "insine" EasingModeOutSine EasingMode = "outsine" EasingModeInOutSine EasingMode = "inoutsine" EasingModeInExpo EasingMode = "inexpo" EasingModeOutExpo EasingMode = "outexpo" EasingModeInOutExpo EasingMode = "inoutexpo" EasingModeInCirc EasingMode = "incirc" EasingModeOutCirc EasingMode = "outcirc" EasingModeInOutCirc EasingMode = "inoutcirc" EasingModeInElastic EasingMode = "inelastic" EasingModeOutElastic EasingMode = "outelastic" EasingModeInOutElastic EasingMode = "inoutelastic" EasingModeInBack EasingMode = "inback" EasingModeOutBack EasingMode = "outback" EasingModeInOutBack EasingMode = "inoutback" EasingModeInBounce EasingMode = "inbounce" EasingModeOutBounce EasingMode = "outbounce" EasingModeInOutBounce EasingMode = "inoutbounce" )
type EventBus ¶
type EventBus[T any] interface { Subscribe(ctx context.Context, fn Subscriber[T]) context.CancelFunc Emit(ctx context.Context, msg T) error Count() int }
type EventBusAsync ¶
type EventBusAsync[T any] struct { // contains filtered or unexported fields }
func NewEventBusAsync ¶
func NewEventBusAsync[T any]() *EventBusAsync[T]
func (EventBusAsync) Subscribe ¶
func (b EventBusAsync) Subscribe(ctx context.Context, fn Subscriber[T]) context.CancelFunc
type EventBusSync ¶
type EventBusSync[T any] struct { // contains filtered or unexported fields }
func NewEventBusSync ¶
func NewEventBusSync[T any]() *EventBusSync[T]
func (EventBusSync) Subscribe ¶
func (b EventBusSync) Subscribe(ctx context.Context, fn Subscriber[T]) context.CancelFunc
type Handle ¶
Handle is a stable reference to an element in a SparseSet. Index and Generation are both uint32. A handle is valid if its generation matches the current generation for its slot in the set in which it was created.
type MusicalRatioName ¶
type MusicalRatioName string
const ( MusicalRatioMinorSecond MusicalRatioName = "Minor Second" MusicalRatioMajorSecond MusicalRatioName = "Major Second" MusicalRatioMinorThird MusicalRatioName = "Minor Third" MusicalRatioMajorThird MusicalRatioName = "Major Third" MusicalRatioPerfectFourth MusicalRatioName = "Perfect Fourth" MusicalRatioAugmentedFourth MusicalRatioName = "Augmented Fourth" MusicalRatioPerfectFifth MusicalRatioName = "Perfect Fifth" MusicalRatioGoldenRatio MusicalRatioName = "Golden Ratio" MusicalRatioMinorSixth MusicalRatioName = "Minor Sixth" MusicalRatioMajorSixth MusicalRatioName = "Major Sixth" MusicalRatioMajorSeventh MusicalRatioName = "Major Seventh" MusicalRatioOctave MusicalRatioName = "Octave" )
type Pool ¶
type Pool[T any] struct { // contains filtered or unexported fields }
A Pool is a generic wrapper around a sync.Pool.
func New ¶
func New[T any](fn func() T, opts ...PoolOption[T]) *Pool[T]
New creates a new Pool with the provided new function.
The equivalent sync.Pool construct is "sync.Pool{New: fn}"
func (*Pool[T]) Get ¶
func (p *Pool[T]) Get() T
Get is a generic wrapper around sync.Pool's Get method.
func (*Pool[T]) GetWithReset ¶
func (p *Pool[T]) GetWithReset() T
GetWithReset returns an item from the pool and applies the optional reset.
type PoolOption ¶
PoolOption configures pool behavior.
func WithReset ¶
func WithReset[T any](reset func(T) T) PoolOption[T]
WithReset configures a reset function applied by GetWithReset.
type SparseSet ¶
type SparseSet[T any] struct { // contains filtered or unexported fields }
SparseSet is a growable, O(1) add/get/remove container that uses stable, generational handles to reference elements without exposing internal indices. Removals are constant time by swapping the last element into the removed slot in the dense array.
This is a Go port inspired by Karl Zylinski's odin-handle-map (handle_map_growing), adapted to Go generics and idioms.
The zero value is ready to use; use NewSparseSet to pre-reserve.
func NewSparseSet ¶
NewSparseSet constructs a SparseSet with an optional initial slot capacity. A capacity of 0 creates an empty set with no pre-allocated slots.
func (*SparseSet[T]) Cap ¶
Cap returns the number of total slots (live + free) that can be used without growing the sparse structures.
func (*SparseSet[T]) Clear ¶
func (s *SparseSet[T]) Clear()
Clear removes all elements. Existing handles become invalid.
func (*SparseSet[T]) GetRef ¶
GetRef returns a pointer to the value for h if valid. Note: Removing other elements may move the value due to swap-remove, invalidating previously taken pointers. Use only transiently.
func (*SparseSet[T]) Insert ¶
Insert adds v to the set and returns a stable handle to it. Amortized O(1). May grow the internal storage.
func (*SparseSet[T]) Range ¶
Range iterates over all live elements. The callback receives a current handle for each element and a pointer to its value. If f returns false, iteration stops early.
func (*SparseSet[T]) Remove ¶
Remove deletes the element referenced by h if present. Returns true if the element existed and was removed.
func (*SparseSet[T]) Reserve ¶
Reserve ensures the set can accommodate at least n live elements without reallocating dense storage. Note: this does not change the number of available slots for handles. To increase the number of potential handles without insertions, call ReserveSlots.
func (*SparseSet[T]) ReserveSlots ¶
ReserveSlots ensures the set has at least n slots available to be populated by future Insert calls before growing the sparse structures.