Documentation
¶
Index ¶
- func GetFuncName(i interface{}, seps ...rune) string
- func HASH32(data []byte) uint32
- func HASH64(data []byte) uint64
- func HexStringToUint32(hexStr string) (uint32, error)
- func If(condition bool, trueVal interface{}, falseVal interface{}) interface{}
- func IsDuplicate(slice []interface{}, equals func(a, b interface{}) bool) bool
- func IsLittleEndian() bool
- func IsNetErrClosing(err error) bool
- func IsNetErrorTemporary(err error) bool
- func IsNetErrorTimeout(err error) bool
- func MD5File(pathFile string) (md5sum string, err error)
- func Md5(data []byte) (md5sum string)
- func MutableCopy(src proto.Message, dst proto.Message) error
- func PushEventWithTimeout(eventChan chan<- interface{}, event interface{}, timeout time.Duration) error
- func RandomInt(min int, max int) int
- func RandomString(len uint32) (container string, err error)
- func RandomValueBySlice(except []interface{}, slice []interface{}, equals func(a, b interface{}) bool) (interface{}, error)
- func RandomWeighted(weights []uint32) (idx int, err error)
- func RearRangeData(dataSlice []byte, removeLen int, resetCnt int) []byte
- func Split2MapU32U32(s string, sep1 string, sep2 string) (map[uint32]uint32, error)
- func Split2SliceU32(s string, sep string) (u32Slice []uint32, err error)
- type IDisplay
- type IObject
- type MapMgr
- type OrderedMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HexStringToUint32 ¶
func If ¶
func If(condition bool, trueVal interface{}, falseVal interface{}) interface{}
If 三目运算符 [NOTE] 传递的实参,会在调用时计算所有参数 e.g.: If(true, 1, 2) => 1
func IsDuplicate ¶
IsDuplicate 是否有重复 e.g.: [1, 2, 3, 1] => true
func IsNetErrClosing ¶
IsNetErrClosing checks if a network error is due to a closed connection.
func IsNetErrorTemporary ¶
IsNetErrorTemporary checks if a network error is temporary. [NOTE] 不建议使用
func IsNetErrorTimeout ¶
IsNetErrorTimeout checks if a network error is a timeout.
func PushEventWithTimeout ¶
func PushEventWithTimeout(eventChan chan<- interface{}, event interface{}, timeout time.Duration) error
todo menglc 每次创建定时器, 性能堪忧, 需要优化
func RandomValueBySlice ¶
func RandomValueBySlice(except []interface{}, slice []interface{}, equals func(a, b interface{}) bool) (interface{}, error)
RandomValueBySlice 生成 随机值
参数: except:排除 数据 slice:从该slice中随机一个,与except不重复 返回值: slice 中的值
e.g.: except = [1, 2, 3], slice = [1, 2, 3, 4, 5], 则返回 4 或 5
func RandomWeighted ¶
RandomWeighted 从权重中选出序号.[0 ... ]
[NOTE] 参数 weights 必须有长度 参数: weights:权重 返回值: idx:weights 的序号 idx
e.g.: weights = [1, 2, 3], 则返回 0, 1, 2 的概率分别为 1/6, 2/6, 3/6
func RearRangeData ¶
RearRangeData 重新整理-数据 removeLen: 移除长度 resetCnt: 重置长度, 大于该长度则重新创建新的数据单元
func Split2MapU32U32 ¶
Split2MapU32U32 拆分字符串, 返回key为uint32类型、val为uint32类型的map e.g.: "1,2;3,4" => map[uint32]int64{1:2, 3:4}
Types ¶
type MapMgr ¶
type MapMgr[TKey comparable, TVal interface{}] struct { // contains filtered or unexported fields }
func NewMapMgr ¶
func NewMapMgr[TKey comparable, TVal interface{}]() *MapMgr[TKey, TVal]
NewMapMgr 创建 Mgr 实例
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap 是一个泛型结构体,它结合了 slice 和 map 来保持元素顺序并提供快速查找 [NOTE]当从 keys 切片中删除元素时,使用了切片的拼接操作来保持剩余元素的顺序。 这个操作在切片较大时可能效率不高,但在大多数情况下是可以接受的。 如果需要频繁地删除元素,并且关心性能,需要考虑使用其他数据结构,如链表或双向队列,来维护键的顺序。
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]
NewOrderedMap 创建一个新的 OrderedMap 实例
func (*OrderedMap[K, V]) Delete ¶
func (p *OrderedMap[K, V]) Delete(key K)
Delete 从 OrderedMap 中删除一个键值对
func (*OrderedMap[K, V]) Get ¶
func (p *OrderedMap[K, V]) Get(key K) (V, bool)
Get 从 OrderedMap 中根据键获取值
func (*OrderedMap[K, V]) Range ¶
func (p *OrderedMap[K, V]) Range(fn func(key K, value V) bool)
Range 迭代 OrderedMap 中的键值对,按插入顺序
func (*OrderedMap[K, V]) Set ¶
func (p *OrderedMap[K, V]) Set(key K, value V)
Set 向 OrderedMap 中添加一个键值对