util

package module
v0.0.0-...-413dc11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2022 License: MIT Imports: 17 Imported by: 0

README

util

Documentation

Index

Constants

View Source
const (
	ColorRed      = "\033[31m"
	ColorGreen    = "\033[32m"
	ColorYellow   = "\033[33m"
	ColorBlue     = "\033[34m"
	ColorPurple   = "\033[35m"
	ColorWhite    = "\033[37m"
	ColorHiRed    = "\033[91m"
	ColorHiGreen  = "\033[92m"
	ColorHiYellow = "\033[93m"
	ColorHiBlue   = "\033[94m"
	ColorHiPurple = "\033[95m"
	ColorHiWhite  = "\033[97m"
	ColorReset    = "\033[0m"
)
View Source
const (
	Rad2Deg float32 = 57.29578
	Deg2Rad float32 = 0.01745329
	HalfPi  float32 = 1.5707963267948966
)

Variables

View Source
var Vec2One = Vec2{1, 1}
View Source
var Vec2Zero = Vec2{0, 0}
View Source
var Vec3One = Vec3{1, 1, 1}
View Source
var Vec3Zero = Vec3{0, 0, 0}

Functions

func AbsFloat

func AbsFloat(d float32) float32

func BytesToInt64

func BytesToInt64(bytes []byte) int64

func BytesToStr

func BytesToStr(b []byte) string

func Ceil

func Ceil(d float32, bit int32) float32

func CeilInt32

func CeilInt32(ceil, v int32) (r, o int32)

func ClampFloat

func ClampFloat(min, max, v float32) float32

func ClampInt32

func ClampInt32(min, max, v int32) int32

func ConvBigHump

func ConvBigHump(str string) string

ConvBigHump 转大驼峰命名

func ConvSmallHump

func ConvSmallHump(str string) string

func ConvUnderline

func ConvUnderline(str string) string

ConvUnderline 下划线

func CopyBytes

func CopyBytes(src []byte) []byte

func Debug

func Debug(str string, m M)

func Default

func Default[T any]() (v T)

func DotVec2

func DotVec2(l, r Vec2) float32

func DotVec3

func DotVec3(l, r Vec3) float32

func Error

func Error(err *Err)

func ExeDir

func ExeDir() string

ExeDir 程序执行目录

func ExeName

func ExeName() string

func Fatal

func Fatal(err *Err)

func FloatMax

func FloatMax(l, r float32) float32

func Floor

func Floor(d float32, bit int32) float32

func FloorInt32

func FloorInt32(floor, v int32) (r, o int32)

func Fnv32

func Fnv32(key string) uint32

func GenMask

func GenMask(items ...int64) int64

func GetCaller

func GetCaller(skip int) string

func GetCross

func GetCross(v1, v2, v Vec2) float32

func GetObjVal

func GetObjVal[T any](obj *Object, key string) (T, bool)

func GetStack

func GetStack(skip int) []byte

func GetTimestamp

func GetTimestamp() string

func Hex

func Hex(bytes []byte) string

func Info

func Info(str string, m M)

func Int64ToBytes

func Int64ToBytes(id int64) []byte

func Int64ToStr

func Int64ToStr(id int64) string

func Int64sToStrSlice

func Int64sToStrSlice(ids ...int64) []string

func IsPowerOfTwo

func IsPowerOfTwo(mask int32) bool

func JsonToM

func JsonToM(bytes []byte) (M, *Err)

func LerpFloat32

func LerpFloat32(from, to, t float32) float32

func MaskAddItem

func MaskAddItem(item, mask int64) int64

func MaskDelItem

func MaskDelItem(item, mask int64) int64

func MaxInt

func MaxInt(a, b int) int

func MaxInt32

func MaxInt32(a, b int32) int32

func MaxInt64

func MaxInt64(a, b int64) int64

func MergeStr

func MergeStr(sep string, nodes ...string) string

func MergeUInt32

func MergeUInt32(prevId, lastId uint16) uint32

func MergeUint16

func MergeUint16(sep string, nodes ...uint16) string

func MinFloat

func MinFloat(l, r float32) float32

func MinInt32

func MinInt32(a, b int32) int32

func MinInt64

func MinInt64(a, b int64) int64

func NextPowerOfTwo

func NextPowerOfTwo(v uint32) uint32

func RandStr

func RandStr(n int) string

func RecycleBytes

func RecycleBytes(bytes []byte)

func RecycleCounter

func RecycleCounter(c *Counter)

func Round

func Round(d float32, bit int32) float32

func SetExeDir

func SetExeDir(dir string)

SetExeDir 手动指定执行目录

func SpawnBytes

func SpawnBytes() []byte

func SpawnBytesWithLen

func SpawnBytesWithLen(l uint32) []byte

func SplitInt64

func SplitInt64(sep, str string) ([]int64, error)

func SplitUInt32

func SplitUInt32(code uint32) (prevId, lastId uint16)

func SplitUint16

func SplitUint16(sep, str string) ([]uint16, error)

func Sqr

func Sqr(x float32) float32

func Sqrt

func Sqrt(v float32) float32

func StrToBytes

func StrToBytes(s string) []byte

func StrToInt64

func StrToInt64(id string) int64

func StrToUint16

func StrToUint16(id string) uint16

func StrToUint32

func StrToUint32(id string) uint32

func StrToUint64

func StrToUint64(id string) uint64

func TestMask

func TestMask(item, mask int64) bool

func Uint16ToStr

func Uint16ToStr(id uint16) string

func Uint32ToStr

func Uint32ToStr(id uint32) string

func Uint64ToStr

func Uint64ToStr(id uint64) string

func Vec2Angle

func Vec2Angle(a, b Vec2) float32

func Vec2Distance

func Vec2Distance(a, b Vec2) float32

func Vec2Magnitude

func Vec2Magnitude(inV Vec2) float32

func Vec2SqrMagnitude

func Vec2SqrMagnitude(inV Vec2) float32

func Vec2TestDis

func Vec2TestDis(inV0, inV1 Vec2, inMaxDist float32) bool

func Vec3Angle

func Vec3Angle(a, b Vec3) float32

func Vec3Distance

func Vec3Distance(a, b Vec3) float32

func Vec3Magnitude

func Vec3Magnitude(inV Vec3) float32

func Vec3Perp2D

func Vec3Perp2D(u, v Vec3) float32

func Vec3SqrMagnitude

func Vec3SqrMagnitude(inV Vec3) float32

func Vec3TestDis

func Vec3TestDis(inV0, inV1 Vec3, inMaxDist float32) bool

func Warn

func Warn(err *Err)

Types

type AnyBoolToAnyBool

type AnyBoolToAnyBool func(any, bool) (any, bool)

type AnyBoolToBool

type AnyBoolToBool func(any, bool) bool

type AnyErrToBool

type AnyErrToBool func(any, *Err) bool

type AnyToAny

type AnyToAny func(any) any

type AnyToAnyBool

type AnyToAnyBool func(any) (any, bool)

type AnyToBytesError

type AnyToBytesError func(any) ([]byte, error)

type ByteBuffer

type ByteBuffer struct {
	// contains filtered or unexported fields
}

func NewByteBuffer

func NewByteBuffer() *ByteBuffer

func NewByteBufferWithData

func NewByteBufferWithData(data []byte) *ByteBuffer

func NewByteBufferWithLen

func NewByteBufferWithLen(l uint32) *ByteBuffer

func (*ByteBuffer) All

func (b *ByteBuffer) All() []byte

func (*ByteBuffer) Available

func (b *ByteBuffer) Available() uint32

func (*ByteBuffer) Cap

func (b *ByteBuffer) Cap() uint32

func (*ByteBuffer) Clone

func (b *ByteBuffer) Clone() *ByteBuffer

func (*ByteBuffer) CopyBytes

func (b *ByteBuffer) CopyBytes() ([]byte, uint32)

func (*ByteBuffer) CopyTo

func (b *ByteBuffer) CopyTo(buffer *ByteBuffer) (n int, err error)

func (*ByteBuffer) Dispose

func (b *ByteBuffer) Dispose()

func (*ByteBuffer) Length

func (b *ByteBuffer) Length() uint32

func (*ByteBuffer) Pos

func (b *ByteBuffer) Pos() uint32

func (*ByteBuffer) RAvailable

func (b *ByteBuffer) RAvailable() (v []byte)

RAvailable 读取剩余所有字节

func (*ByteBuffer) RBool

func (b *ByteBuffer) RBool() (v bool, err *Err)

func (*ByteBuffer) RBools

func (b *ByteBuffer) RBools() (v []bool, err *Err)

func (*ByteBuffer) RBytes

func (b *ByteBuffer) RBytes(l uint32) ([]byte, *Err)

func (*ByteBuffer) RBytesWithLen

func (b *ByteBuffer) RBytesWithLen() (v []byte, err *Err)

func (*ByteBuffer) RFloat32

func (b *ByteBuffer) RFloat32() (v float32, err *Err)

func (*ByteBuffer) RFloat32s

func (b *ByteBuffer) RFloat32s() (v []float32, err *Err)

func (*ByteBuffer) RFloat64

func (b *ByteBuffer) RFloat64() (v float64, err *Err)

func (*ByteBuffer) RFloat64s

func (b *ByteBuffer) RFloat64s() (v []float64, err *Err)

func (*ByteBuffer) RInt16

func (b *ByteBuffer) RInt16() (v int16, err *Err)

func (*ByteBuffer) RInt16s

func (b *ByteBuffer) RInt16s() (v []int16, err *Err)

func (*ByteBuffer) RInt32

func (b *ByteBuffer) RInt32() (v int32, err *Err)

func (*ByteBuffer) RInt32s

func (b *ByteBuffer) RInt32s() (v []int32, err *Err)

func (*ByteBuffer) RInt64

func (b *ByteBuffer) RInt64() (v int64, err *Err)

func (*ByteBuffer) RInt64s

func (b *ByteBuffer) RInt64s() (v []int64, err *Err)

func (*ByteBuffer) RInt8

func (b *ByteBuffer) RInt8() (v int8, err *Err)

func (*ByteBuffer) RInt8s

func (b *ByteBuffer) RInt8s() (v []int8, err *Err)

func (*ByteBuffer) RMapInt32

func (b *ByteBuffer) RMapInt32() (m map[string]int32, err *Err)

func (*ByteBuffer) RMapInt32ToInt32

func (b *ByteBuffer) RMapInt32ToInt32() (m map[int32]int32, err *Err)

func (*ByteBuffer) RMapInt32ToInt64

func (b *ByteBuffer) RMapInt32ToInt64() (m map[int32]int64, err *Err)

func (*ByteBuffer) RMapInt64

func (b *ByteBuffer) RMapInt64() (m map[string]int64, err *Err)

func (*ByteBuffer) RMapInt64ToInt32

func (b *ByteBuffer) RMapInt64ToInt32() (m map[int64]int32, err *Err)

func (*ByteBuffer) RMapInt64ToInt64

func (b *ByteBuffer) RMapInt64ToInt64() (m map[int64]int64, err *Err)

func (*ByteBuffer) RMapStrStr

func (b *ByteBuffer) RMapStrStr() (m map[string]string, err *Err)

func (*ByteBuffer) RString

func (b *ByteBuffer) RString() (v string, err *Err)

func (*ByteBuffer) RStringNoLen

func (b *ByteBuffer) RStringNoLen() (v string)

func (*ByteBuffer) RStrings

func (b *ByteBuffer) RStrings() (v []string, err *Err)

func (*ByteBuffer) RUint16

func (b *ByteBuffer) RUint16() (v uint16, err *Err)

func (*ByteBuffer) RUint16s

func (b *ByteBuffer) RUint16s() (v []uint16, err *Err)

func (*ByteBuffer) RUint32

func (b *ByteBuffer) RUint32() (v uint32, err *Err)

func (*ByteBuffer) RUint32s

func (b *ByteBuffer) RUint32s() (v []uint32, err *Err)

func (*ByteBuffer) RUint64

func (b *ByteBuffer) RUint64() (v uint64, err *Err)

func (*ByteBuffer) RUint64s

func (b *ByteBuffer) RUint64s() (v []uint64, err *Err)

func (*ByteBuffer) RUint8

func (b *ByteBuffer) RUint8() (v uint8, err *Err)

func (*ByteBuffer) RUint8s

func (b *ByteBuffer) RUint8s() (v []uint8, err *Err)

func (*ByteBuffer) RVec2

func (b *ByteBuffer) RVec2() (v Vec2, err *Err)

func (*ByteBuffer) RVec2s

func (b *ByteBuffer) RVec2s() (v []Vec2, err *Err)

func (*ByteBuffer) RVec3

func (b *ByteBuffer) RVec3() (v Vec3, err *Err)

func (*ByteBuffer) RVec3s

func (b *ByteBuffer) RVec3s() (v []Vec3, err *Err)

func (*ByteBuffer) Read

func (b *ByteBuffer) Read(p []byte) (n int, err error)

func (*ByteBuffer) Reset

func (b *ByteBuffer) Reset()

func (*ByteBuffer) SetBytes

func (b *ByteBuffer) SetBytes(bytes []byte)

func (*ByteBuffer) SetPos

func (b *ByteBuffer) SetPos(v uint32)

func (*ByteBuffer) ToHex

func (b *ByteBuffer) ToHex() string

func (*ByteBuffer) WBool

func (b *ByteBuffer) WBool(v bool)

func (*ByteBuffer) WBools

func (b *ByteBuffer) WBools(v []bool)

func (*ByteBuffer) WBytesWithLen

func (b *ByteBuffer) WBytesWithLen(v []byte)

func (*ByteBuffer) WFloat32

func (b *ByteBuffer) WFloat32(v float32)

func (*ByteBuffer) WFloat32s

func (b *ByteBuffer) WFloat32s(v []float32)

func (*ByteBuffer) WFloat64

func (b *ByteBuffer) WFloat64(v float64)

func (*ByteBuffer) WFloat64s

func (b *ByteBuffer) WFloat64s(v []float64)

func (*ByteBuffer) WInt16

func (b *ByteBuffer) WInt16(v int16)

func (*ByteBuffer) WInt16s

func (b *ByteBuffer) WInt16s(v []int16)

func (*ByteBuffer) WInt32

func (b *ByteBuffer) WInt32(v int32)

func (*ByteBuffer) WInt32s

func (b *ByteBuffer) WInt32s(v []int32)

func (*ByteBuffer) WInt64

func (b *ByteBuffer) WInt64(v int64)

func (*ByteBuffer) WInt64s

func (b *ByteBuffer) WInt64s(v []int64)

func (*ByteBuffer) WInt8

func (b *ByteBuffer) WInt8(v int8)

func (*ByteBuffer) WInt8s

func (b *ByteBuffer) WInt8s(v []int8)

func (*ByteBuffer) WMapInt32

func (b *ByteBuffer) WMapInt32(m map[string]int32)

func (*ByteBuffer) WMapInt32ToInt32

func (b *ByteBuffer) WMapInt32ToInt32(m map[int32]int32)

func (*ByteBuffer) WMapInt32ToInt64

func (b *ByteBuffer) WMapInt32ToInt64(m map[int32]int64)

func (*ByteBuffer) WMapInt64

func (b *ByteBuffer) WMapInt64(m map[string]int64)

func (*ByteBuffer) WMapInt64ToInt32

func (b *ByteBuffer) WMapInt64ToInt32(m map[int64]int32)

func (*ByteBuffer) WMapInt64ToInt64

func (b *ByteBuffer) WMapInt64ToInt64(m map[int64]int64)

func (*ByteBuffer) WMapStrStr

func (b *ByteBuffer) WMapStrStr(m map[string]string)

func (*ByteBuffer) WString

func (b *ByteBuffer) WString(v string)

func (*ByteBuffer) WStringWithLen

func (b *ByteBuffer) WStringWithLen(v string)

func (*ByteBuffer) WStrings

func (b *ByteBuffer) WStrings(v []string)

func (*ByteBuffer) WUint16

func (b *ByteBuffer) WUint16(v uint16)

func (*ByteBuffer) WUint16s

func (b *ByteBuffer) WUint16s(v []uint16)

func (*ByteBuffer) WUint32

func (b *ByteBuffer) WUint32(v uint32)

func (*ByteBuffer) WUint32s

func (b *ByteBuffer) WUint32s(v []uint32)

func (*ByteBuffer) WUint64

func (b *ByteBuffer) WUint64(v uint64)

func (*ByteBuffer) WUint64s

func (b *ByteBuffer) WUint64s(v []uint64)

func (*ByteBuffer) WUint8

func (b *ByteBuffer) WUint8(v uint8)

func (*ByteBuffer) WUint8s

func (b *ByteBuffer) WUint8s(v []uint8)

func (*ByteBuffer) WVec2

func (b *ByteBuffer) WVec2(v Vec2)

func (*ByteBuffer) WVec2s

func (b *ByteBuffer) WVec2s(v []Vec2)

func (*ByteBuffer) WVec3

func (b *ByteBuffer) WVec3(v Vec3)

func (*ByteBuffer) WVec3s

func (b *ByteBuffer) WVec3s(v []Vec3)

func (*ByteBuffer) Write

func (b *ByteBuffer) Write(v []byte) (int, error)

func (*ByteBuffer) WriteTo

func (b *ByteBuffer) WriteTo(writer io.Writer) (n int, err error)

type BytesAnyToError

type BytesAnyToError func([]byte, any) error

type BytesToAnyErr

type BytesToAnyErr func([]byte) (any, *Err)

type BytesToInt642Err

type BytesToInt642Err func([]byte) (int64, int64, *Err)

type CSet

type CSet[T NumId] []*idCSetShared[T]

func NewCSet

func NewCSet[T NumId]() CSet[T]

func NewStrCSet

func NewStrCSet[T NumId]() CSet[T]

func (CSet[T]) Clear

func (m CSet[T]) Clear()

func (CSet[T]) Count

func (m CSet[T]) Count() int64

func (CSet[T]) Del

func (m CSet[T]) Del(id T)

func (CSet[T]) Get

func (m CSet[T]) Get(id T) (INumId[T], *Err)

func (CSet[T]) GetOrNew

func (m CSet[T]) GetOrNew(id T, f func() INumId[T]) (item INumId[T], exist bool)

func (CSet[T]) Has

func (m CSet[T]) Has(id T) (ok bool)

func (CSet[T]) Pop

func (m CSet[T]) Pop(id T) (v INumId[T], exist bool)

func (CSet[T]) R

func (m CSet[T]) R(id T, fn func(INumId[T], bool))

func (CSet[T]) RAll

func (m CSet[T]) RAll(fn func(T, INumId[T]))

func (CSet[T]) RAny

func (m CSet[T]) RAny(fn func(T, INumId[T]) bool) bool

func (CSet[T]) Set

func (m CSet[T]) Set(item INumId[T])

func (CSet[T]) TestDel

func (m CSet[T]) TestDel(id T, test func(T, INumId[T]) (del bool, brk bool)) (removed bool)

func (CSet[T]) W

func (m CSet[T]) W(id T, fn func(INumId[T], bool))

func (CSet[T]) WAll

func (m CSet[T]) WAll(fn func(T, INumId[T]))

func (CSet[T]) WAny

func (m CSet[T]) WAny(fn func(T, INumId[T]) bool) bool

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

func SpawnCounter

func SpawnCounter() *Counter

func (*Counter) Add

func (c *Counter) Add(v uint32) (uint32, bool)

func (*Counter) Count

func (c *Counter) Count() uint32

func (*Counter) Reset

func (c *Counter) Reset(total uint32)

func (*Counter) Total

func (c *Counter) Total() uint32
type DLink[KT comparable, VT any] struct {
	// contains filtered or unexported fields
}

DLink 双向链表

func NewCLink[KT comparable](cap int, opts ...DLinkOption[KT, KT]) *DLink[KT, KT]
func NewDLink[KT comparable, VT any](cap int, opts ...DLinkOption[KT, VT]) *DLink[KT, VT]

func (*DLink[KT, VT]) Any

func (l *DLink[KT, VT]) Any(fn func(VT) bool)

func (*DLink[KT, VT]) Count

func (l *DLink[KT, VT]) Count() int

func (*DLink[KT, VT]) Get

func (l *DLink[KT, VT]) Get(key KT) (VT, bool)

func (*DLink[KT, VT]) Iter

func (l *DLink[KT, VT]) Iter(fn func(VT))

func (*DLink[KT, VT]) NewOrUpdate

func (l *DLink[KT, VT]) NewOrUpdate(key KT, update func(VT), new func() VT) (exist bool)

func (*DLink[KT, VT]) Pop

func (l *DLink[KT, VT]) Pop() (VT, bool)

func (*DLink[KT, VT]) Push

func (l *DLink[KT, VT]) Push(val VT) bool

Push 推入元素,如果已存在返回false

func (*DLink[KT, VT]) Remove

func (l *DLink[KT, VT]) Remove(val VT)

func (*DLink[KT, VT]) RemoveByKey

func (l *DLink[KT, VT]) RemoveByKey(key KT)

func (*DLink[KT, VT]) TestDel

func (l *DLink[KT, VT]) TestDel(test func(VT) bool) (VT, bool)

TestDel 测试弹出一个符合条件的即停止

func (*DLink[KT, VT]) Values

func (l *DLink[KT, VT]) Values() []VT

type DLinkElem

type DLinkElem[T any] struct {
	Value T
	// contains filtered or unexported fields
}

func (*DLinkElem[T]) Dispose

func (n *DLinkElem[T]) Dispose()

type DLinkOption

type DLinkOption[KT comparable, VT any] func(o *dLinkOption[KT, VT])

func DLinkRecycleElem

func DLinkRecycleElem[KT comparable, VT any](recycle func(*DLinkElem[VT])) DLinkOption[KT, VT]

func DLinkSpawnElem

func DLinkSpawnElem[KT comparable, VT any](spawn func() *DLinkElem[VT]) DLinkOption[KT, VT]

func DLinkValToKey

func DLinkValToKey[KT comparable, VT any](valToKey func(VT) KT) DLinkOption[KT, VT]

type Enable

type Enable struct {
	// contains filtered or unexported fields
}

func NewEnable

func NewEnable() *Enable

func (*Enable) Close

func (e *Enable) Close(fn Fn) *Err

func (*Enable) RAction

func (e *Enable) RAction(fn Fn) *Err

func (*Enable) Reset

func (e *Enable) Reset(fn Fn) *Err

func (*Enable) WAction

func (e *Enable) WAction(fn Fn) *Err

type Err

type Err struct {
	// contains filtered or unexported fields
}

func NewErr

func NewErr(code TErrCode, params M) *Err

func NewErrWithStack

func NewErrWithStack(code TErrCode, stack []byte, params M) *Err

func WrapErr

func WrapErr(code TErrCode, e error) *Err

func (*Err) AddParam

func (e *Err) AddParam(k string, v any)

func (*Err) AddParams

func (e *Err) AddParams(params M)

func (*Err) Code

func (e *Err) Code() TErrCode

func (*Err) GetParam

func (e *Err) GetParam(k string) (v any, ok bool)

func (*Err) Params

func (e *Err) Params() M

func (*Err) Stack

func (e *Err) Stack() []byte

func (*Err) String

func (e *Err) String() string

func (*Err) ToBytes

func (e *Err) ToBytes() []byte

func (*Err) ToError

func (e *Err) ToError() error

func (*Err) UpdateParam

func (e *Err) UpdateParam(k string, action AnyBoolToAnyBool)

type Fn

type Fn func()

func (Fn) Invoke

func (f Fn) Invoke()

type FnAny

type FnAny func(any)

type FnBool

type FnBool func(bool)

type FnErr

type FnErr func(*Err)

type FnInt32

type FnInt32 func(int32)

type FnInt64

type FnInt64 func(int64)

type FnInt642Any

type FnInt642Any func(int64, int64, any)

type FnInt642Bool

type FnInt642Bool func(int64, int64, bool)

type FnInt642Err

type FnInt642Err func(int64, int64, *Err)

type FnInt643

type FnInt643 func(int64, int64, int64)

type FnInt64Any

type FnInt64Any func(int64, any)

func (FnInt64Any) Invoke

func (f FnInt64Any) Invoke(v int64, obj any)

type FnInt64Bool

type FnInt64Bool func(int64, bool)

type FnInt64Err

type FnInt64Err func(int64, *Err)

func (FnInt64Err) Invoke

func (f FnInt64Err) Invoke(v int64, err *Err)

type FnInt64StrBool

type FnInt64StrBool func(int64, string, bool)

type FnM

type FnM func(M)

type FnObj

type FnObj func(*Object)

type FnObjAny

type FnObjAny func(*Object, any)

type FnObjBool

type FnObjBool func(*Object, bool)

type FnObjErr

type FnObjErr func(*Object, *Err)

type FnStr

type FnStr func(string)

type FnStr2Bool

type FnStr2Bool func(string, string, bool)

type FnStrAny

type FnStrAny func(string, any)

type FnStrBool

type FnStrBool func(string, bool)

type FnStrErr

type FnStrErr func(string, *Err)

type FnStrFn

type FnStrFn func(string, Fn)

type FnUint32

type FnUint32 func(uint32)

type IIdx

type IIdx[T Idx] interface {
	Id() T
}

type INumId

type INumId[T NumId] interface {
	Id() T
}
type IdLink[KT Idx, VT any] struct {
	Link[VT]
	// contains filtered or unexported fields
}
func NewIdLink[KT Idx, VT any]() *IdLink[KT, VT]

func (*IdLink[KT, VT]) Id

func (q *IdLink[KT, VT]) Id() KT
func (q *IdLink[KT, VT]) PopLink() *LinkElem[VT]

func (*IdLink[KT, VT]) Push

func (q *IdLink[KT, VT]) Push(val VT)

func (*IdLink[KT, VT]) SetId

func (q *IdLink[KT, VT]) SetId(id KT)

type Idx

type Idx interface {
	~int16 | ~uint16 | ~int32 | ~uint32 | ~int64 | ~uint64 | ~string
}

type IdxToBool2

type IdxToBool2[T Idx] func(item IIdx[T]) (bool, bool)

type Int32

type Int32 int32

func (Int32) Id

func (i Int32) Id() Int32

type Int64

type Int64 int64

func (Int64) Id

func (i Int64) Id() Int64

type Int64AnyToBool

type Int64AnyToBool func(int64, any) bool
type Link[T any] struct {
	// contains filtered or unexported fields
}
func NewLink[T any]() *Link[T]

func (*Link[T]) Count

func (q *Link[T]) Count() uint32

func (*Link[T]) Dispose

func (q *Link[T]) Dispose()

func (*Link[T]) FnAll

func (q *Link[T]) FnAll(fn func(T))

func (*Link[T]) Pop

func (q *Link[T]) Pop() T
func (q *Link[T]) PopLink() *LinkElem[T]

func (*Link[T]) Push

func (q *Link[T]) Push(a T)

func (*Link[T]) Reset

func (q *Link[T]) Reset()

type LinkElem

type LinkElem[T any] struct {
	Next  *LinkElem[T]
	Value T
}

type M

type M map[string]any

func (M) IndentJson

func (m M) IndentJson() []byte

func (M) Json

func (m M) Json() ([]byte, *Err)

type NumId

type NumId interface {
	~int32 | ~uint32 | ~int64 | ~uint64
}

type ObjToAny

type ObjToAny func(*Object) any

type ObjToBool

type ObjToBool func(*Object) bool

type ObjToErr

type ObjToErr func(*Object) *Err

type Object

type Object struct {
	// contains filtered or unexported fields
}

func NewObject

func NewObject(m M) *Object

func (*Object) Bool

func (obj *Object) Bool(key string) (bool, bool)

func (*Object) Bools

func (obj *Object) Bools(key string) ([]bool, bool)

func (*Object) Clear

func (obj *Object) Clear()

func (*Object) Float32

func (obj *Object) Float32(key string) (float32, bool)

func (*Object) Float32s

func (obj *Object) Float32s(key string) ([]float32, bool)

func (*Object) Float64

func (obj *Object) Float64(key string) (float64, bool)

func (*Object) Float64s

func (obj *Object) Float64s(key string) ([]float64, bool)

func (*Object) Get

func (obj *Object) Get(key string) (v any, ok bool)

func (*Object) Has

func (obj *Object) Has(key string) (ok bool)

func (*Object) Int

func (obj *Object) Int(key string) (int, bool)

func (*Object) Int16

func (obj *Object) Int16(key string) (int16, bool)

func (*Object) Int16s

func (obj *Object) Int16s(key string) ([]int16, bool)

func (*Object) Int32

func (obj *Object) Int32(key string) (int32, bool)

func (*Object) Int32s

func (obj *Object) Int32s(key string) ([]int32, bool)

func (*Object) Int64

func (obj *Object) Int64(key string) (int64, bool)

func (*Object) Int64s

func (obj *Object) Int64s(key string) ([]int64, bool)

func (*Object) Int8

func (obj *Object) Int8(key string) (int8, bool)

func (*Object) Int8s

func (obj *Object) Int8s(key string) ([]int8, bool)

func (*Object) Ints

func (obj *Object) Ints(key string) ([]int, bool)

func (*Object) M

func (obj *Object) M() M

func (*Object) MustBool

func (obj *Object) MustBool(key string, def bool) bool

func (*Object) MustBools

func (obj *Object) MustBools(key string, def []bool) []bool

func (*Object) MustFloat32

func (obj *Object) MustFloat32(key string, def float32) float32

func (*Object) MustFloat32s

func (obj *Object) MustFloat32s(key string, def []float32) []float32

func (*Object) MustFloat64

func (obj *Object) MustFloat64(key string, def float64) float64

func (*Object) MustFloat64s

func (obj *Object) MustFloat64s(key string, def []float64) []float64

func (*Object) MustInt

func (obj *Object) MustInt(key string, def int) int

func (*Object) MustInt16

func (obj *Object) MustInt16(key string, def int16) int16

func (*Object) MustInt16s

func (obj *Object) MustInt16s(key string, def []int16) []int16

func (*Object) MustInt32

func (obj *Object) MustInt32(key string, def int32) int32

func (*Object) MustInt32s

func (obj *Object) MustInt32s(key string, def []int32) []int32

func (*Object) MustInt64

func (obj *Object) MustInt64(key string, def int64) int64

func (*Object) MustInt64s

func (obj *Object) MustInt64s(key string, def []int64) []int64

func (*Object) MustInt8

func (obj *Object) MustInt8(key string, def int8) int8

func (*Object) MustInt8s

func (obj *Object) MustInt8s(key string, def []int8) []int8

func (*Object) MustInts

func (obj *Object) MustInts(key string, def []int) []int

func (*Object) MustString

func (obj *Object) MustString(key string, def string) string

func (*Object) MustStrings

func (obj *Object) MustStrings(key string, def []string) []string

func (*Object) MustTime

func (obj *Object) MustTime(key string, def *time.Time) *time.Time

func (*Object) MustTimes

func (obj *Object) MustTimes(key string, def []*time.Time) []*time.Time

func (*Object) MustUint

func (obj *Object) MustUint(key string, def uint) uint

func (*Object) MustUint16

func (obj *Object) MustUint16(key string, def uint16) uint16

func (*Object) MustUint16s

func (obj *Object) MustUint16s(key string, def []uint16) []uint16

func (*Object) MustUint32

func (obj *Object) MustUint32(key string, def uint32) uint32

func (*Object) MustUint32s

func (obj *Object) MustUint32s(key string, def []uint32) []uint32

func (*Object) MustUint64

func (obj *Object) MustUint64(key string, def uint64) uint64

func (*Object) MustUint64s

func (obj *Object) MustUint64s(key string, def []uint64) []uint64

func (*Object) MustUint8

func (obj *Object) MustUint8(key string, def uint8) uint8

func (*Object) MustUint8s

func (obj *Object) MustUint8s(key string, def []uint8) []uint8

func (*Object) MustUints

func (obj *Object) MustUints(key string, def []uint) []uint

func (*Object) MustVec2

func (obj *Object) MustVec2(key string, def Vec2) Vec2

func (*Object) MustVec2s

func (obj *Object) MustVec2s(key string, def []Vec2) []Vec2

func (*Object) MustVec3

func (obj *Object) MustVec3(key string, def Vec3) Vec3

func (*Object) MustVec3s

func (obj *Object) MustVec3s(key string, def []Vec3) []Vec3

func (*Object) Pop

func (obj *Object) Pop(key string) (v any, ok bool)

func (*Object) Remove

func (obj *Object) Remove(key string)

func (*Object) Replace

func (obj *Object) Replace(key string, val any) (oldVal any, ok bool)

func (*Object) Reset

func (obj *Object) Reset(data M)

func (*Object) Set

func (obj *Object) Set(key string, val any)

func (*Object) String

func (obj *Object) String(key string) (string, bool)

func (*Object) Strings

func (obj *Object) Strings(key string) ([]string, bool)

func (*Object) Time

func (obj *Object) Time(key string) (*time.Time, bool)

func (*Object) Times

func (obj *Object) Times(key string) ([]*time.Time, bool)

func (*Object) Uint

func (obj *Object) Uint(key string) (uint, bool)

func (*Object) Uint16

func (obj *Object) Uint16(key string) (uint16, bool)

func (*Object) Uint16s

func (obj *Object) Uint16s(key string) ([]uint16, bool)

func (*Object) Uint32

func (obj *Object) Uint32(key string) (uint32, bool)

func (*Object) Uint32s

func (obj *Object) Uint32s(key string) ([]uint32, bool)

func (*Object) Uint64

func (obj *Object) Uint64(key string) (uint64, bool)

func (*Object) Uint64s

func (obj *Object) Uint64s(key string) ([]uint64, bool)

func (*Object) Uint8

func (obj *Object) Uint8(key string) (uint8, bool)

func (*Object) Uint8s

func (obj *Object) Uint8s(key string) ([]uint8, bool)

func (*Object) Uints

func (obj *Object) Uints(key string) ([]uint, bool)

func (*Object) Update

func (obj *Object) Update(key string, action AnyToAny) (ok bool)

func (*Object) Vec2

func (obj *Object) Vec2(key string) (Vec2, bool)

func (*Object) Vec2s

func (obj *Object) Vec2s(key string) ([]Vec2, bool)

func (*Object) Vec3

func (obj *Object) Vec3(key string) (Vec3, bool)

func (*Object) Vec3s

func (obj *Object) Vec3s(key string) ([]Vec3, bool)

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool[T any](opts ...PoolOption[T]) *Pool[T]

func (*Pool[T]) Push

func (p *Pool[T]) Push(value T)

func (*Pool[T]) Shift

func (p *Pool[T]) Shift() (v T)

type PoolOption

type PoolOption[T any] func(o *poolOption[T])

func PoolMinCap

func PoolMinCap[T any](c uint32) PoolOption[T]

func PoolSpawn

func PoolSpawn[T any](spawn func() T) PoolOption[T]

type Ring

type Ring[T any] struct {
	// contains filtered or unexported fields
}

func NewRing

func NewRing[T any](opts ...RingOption[T]) *Ring[T]

func (*Ring[T]) Available

func (a *Ring[T]) Available() uint32

func (*Ring[T]) Iter

func (a *Ring[T]) Iter(fn FnAny)

func (*Ring[T]) Read

func (a *Ring[T]) Read(s []T, l uint32) *Err

func (*Ring[T]) Write

func (a *Ring[T]) Write(items ...T) *Err

type RingOption

type RingOption[T any] func(o *ringOption[T])

func RingMaxCap

func RingMaxCap[T any](c uint32) RingOption[T]

func RingMinCap

func RingMinCap[T any](c uint32) RingOption[T]

func RingRecycle

func RingRecycle[T any](r func([]T)) RingOption[T]

func RingResize

func RingResize[T any](r func(uint32)) RingOption[T]

type Set

type Set[T Idx] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T Idx](defCap int64) *Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(item IIdx[T]) *Err

func (*Set[T]) Any

func (s *Set[T]) Any(fn func(T, IIdx[T]) bool) bool

func (*Set[T]) Cap

func (s *Set[T]) Cap() int64

func (*Set[T]) Count

func (s *Set[T]) Count() int64

func (*Set[T]) Del

func (s *Set[T]) Del(key T) (val IIdx[T], exist bool)

func (*Set[T]) Get

func (s *Set[T]) Get(id T) (IIdx[T], bool)

func (*Set[T]) Has

func (s *Set[T]) Has(key T) bool

func (*Set[T]) Ids

func (s *Set[T]) Ids() []T

func (*Set[T]) Items

func (s *Set[T]) Items() []IIdx[T]

func (*Set[T]) Iter

func (s *Set[T]) Iter(fn func(T, IIdx[T]))

func (*Set[T]) Replace

func (s *Set[T]) Replace(oldItem, newItem IIdx[T]) bool

func (*Set[T]) ReplaceOrNew

func (s *Set[T]) ReplaceOrNew(oldItem, newItem IIdx[T])

func (*Set[T]) Set

func (s *Set[T]) Set(item IIdx[T])

func (*Set[T]) TestDel

func (s *Set[T]) TestDel(test func(T, IIdx[T]) (del bool, brk bool))

type StrToBool

type StrToBool func(string) bool

type StrToBytesErr

type StrToBytesErr func(string) ([]byte, *Err)

type StrToStr2Err

type StrToStr2Err func(string) (string, string, *Err)

type String

type String string

func (String) Id

func (i String) Id() String

type TErrCode

type TErrCode = uint32
const (
	EcNil TErrCode = iota
	EcRecover
	EcWrong
	EcBusy
	EcNotEnough
	EcUnAuth
	EcTimeout
	EcClosed
	EcOpened
	EcEmptyPacket
	EcBadHead
	EcBadPacket
	EcExistKey
	EcNotExistKey
	EcNotExistCode
	EcNotExistService
	EcMarshallErr
	EcUnmarshallErr
	EcNotExistType
	EcIllegalOperation
	EcIllegalConnection
	EcTooManyConnection
	EcNotExistLoaderType
	EcParamsErr
	EcParseErr
	EcIo
	EcRedisErr
	EcOutOfRange
	EcTooLong
	EcLengthErr
	EcNotExistAgent
	EcSendErr
	EcReceiveErr
	EcAcceptErr
	EcConnectErr
	EcListenErr
	EcServiceErr
	EcDbErr
	EcMax
)

type ToAny

type ToAny func() any

type ToBool

type ToBool func() bool

type ToFnInt64Fn

type ToFnInt64Fn func() FnStrFn

type ToInt64

type ToInt64 func() int64

type ToM

type ToM func() M

type Uint32

type Uint32 uint32

func (Uint32) Id

func (i Uint32) Id() Uint32

type Uint64

type Uint64 uint64

func (Uint64) Id

func (i Uint64) Id() Uint64

type Vec2

type Vec2 struct {
	X, Y float32
}

func MaxVec2

func MaxVec2(l, r Vec2) Vec2

func MinVec2

func MinVec2(l, r Vec2) Vec2

func NewVec2

func NewVec2(x, y float32) Vec2

func Vec2Add

func Vec2Add(v Vec2, val Vec2) Vec2

func Vec2Div

func Vec2Div(v Vec2, val float32) Vec2

func Vec2Mul

func Vec2Mul(v Vec2, val float32) Vec2

func Vec2Normalize

func Vec2Normalize(inV Vec2) Vec2

func Vec2NormalizeSafe

func Vec2NormalizeSafe(inV, defaultV Vec2) Vec2

func Vec2Sub

func Vec2Sub(v1, v2 Vec2) Vec2

type Vec3

type Vec3 struct {
	X, Y, Z float32
}

func MaxVec3

func MaxVec3(l, r Vec3) Vec3

func MinVec3

func MinVec3(l, r Vec3) Vec3

func NewVec3

func NewVec3(x, y, z float32) Vec3

func Vec3Abs

func Vec3Abs(v Vec3) Vec3

func Vec3Add

func Vec3Add(v1, v2 Vec3) Vec3

func Vec3Cross

func Vec3Cross(lhs, rhs Vec3) Vec3

func Vec3Div

func Vec3Div(v1 Vec3, val float32) Vec3

func Vec3Lerp

func Vec3Lerp(from, to Vec3, t float32) Vec3

func Vec3Mulf

func Vec3Mulf(v1 Vec3, val float32) Vec3

func Vec3Mulv

func Vec3Mulv(v1, data Vec3) Vec3

func Vec3Neg

func Vec3Neg(v Vec3) Vec3

func Vec3Normalize

func Vec3Normalize(inV Vec3) Vec3

func Vec3NormalizeSafe

func Vec3NormalizeSafe(inV, defaultV Vec3) Vec3

func Vec3Scale

func Vec3Scale(l, r Vec3) Vec3

func Vec3Sub

func Vec3Sub(v1, v2 Vec3) Vec3

func (*Vec3) GetData

func (v *Vec3) GetData(i int) float32

func (*Vec3) Set

func (v *Vec3) Set(x, y, z float32)

func (*Vec3) SetData

func (v *Vec3) SetData(i int, data float32)

func (*Vec3) SetZero

func (v *Vec3) SetZero()

type VecInt2

type VecInt2 struct {
	X, Y int32
}

func NewVecInt2

func NewVecInt2(x, y int32) VecInt2

func VecInt2Add

func VecInt2Add(v1, v2 VecInt2) VecInt2

func VecInt2Div

func VecInt2Div(v VecInt2, val int32) VecInt2

func VecInt2Mul

func VecInt2Mul(v VecInt2, val int32) VecInt2

func VecInt2Sub

func VecInt2Sub(v1, v2 VecInt2) VecInt2

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL