Documentation ¶
Index ¶
- type BalanceMap
- func (slf *BalanceMap[Key, Value]) Atom(handle func(m map[Key]Value))
- func (slf *BalanceMap[Key, Value]) Clear()
- func (slf *BalanceMap[Key, Value]) ClearHandle(handle func(key Key, value Value))
- func (slf *BalanceMap[Key, Value]) Delete(key Key)
- func (slf *BalanceMap[Key, Value]) DeleteExist(key Key) bool
- func (slf *BalanceMap[Key, Value]) DeleteGet(key Key) Value
- func (slf *BalanceMap[Key, Value]) DeleteGetExist(key Key) (Value, bool)
- func (slf *BalanceMap[Key, Value]) Exist(key Key) bool
- func (slf *BalanceMap[Key, Value]) Get(key Key) Value
- func (slf *BalanceMap[Key, Value]) GetExist(key Key) (Value, bool)
- func (slf *BalanceMap[Key, Value]) Keys() []Key
- func (slf *BalanceMap[Key, Value]) Map() map[Key]Value
- func (slf *BalanceMap[Key, Value]) MarshalJSON() ([]byte, error)
- func (slf *BalanceMap[Key, Value]) Range(handle func(key Key, value Value) bool)
- func (slf *BalanceMap[Key, Value]) Set(key Key, value Value)
- func (slf *BalanceMap[Key, Value]) Size() int
- func (slf *BalanceMap[Key, Value]) Slice() []Value
- func (slf *BalanceMap[Key, Value]) UnmarshalJSON(bytes []byte) error
- type BalanceMapOption
- type Pool
- type Slice
- type SliceOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BalanceMap ¶
type BalanceMap[Key comparable, Value any] struct { // contains filtered or unexported fields }
BalanceMap 并发安全且性能在普通读写和并发读写的情况下较为平衡的字典数据结构
- 适用于要考虑并发读写但是并发读写的频率不高的情况
func NewBalanceMap ¶
func NewBalanceMap[Key comparable, value any](options ...BalanceMapOption[Key, value]) *BalanceMap[Key, value]
NewBalanceMap 创建一个并发安全且性能在普通读写和并发读写的情况下较为平衡的字典数据结构
func (*BalanceMap[Key, Value]) Atom ¶
func (slf *BalanceMap[Key, Value]) Atom(handle func(m map[Key]Value))
Atom 原子操作
func (*BalanceMap[Key, Value]) ClearHandle ¶
func (slf *BalanceMap[Key, Value]) ClearHandle(handle func(key Key, value Value))
ClearHandle 清空并处理
func (*BalanceMap[Key, Value]) Delete ¶
func (slf *BalanceMap[Key, Value]) Delete(key Key)
Delete 删除一个值
func (*BalanceMap[Key, Value]) DeleteExist ¶
func (slf *BalanceMap[Key, Value]) DeleteExist(key Key) bool
DeleteExist 删除一个值并返回是否存在
func (*BalanceMap[Key, Value]) DeleteGet ¶
func (slf *BalanceMap[Key, Value]) DeleteGet(key Key) Value
DeleteGet 删除一个值并返回
func (*BalanceMap[Key, Value]) DeleteGetExist ¶
func (slf *BalanceMap[Key, Value]) DeleteGetExist(key Key) (Value, bool)
DeleteGetExist 删除一个值并返回是否存在
func (*BalanceMap[Key, Value]) Exist ¶
func (slf *BalanceMap[Key, Value]) Exist(key Key) bool
Exist 判断是否存在
func (*BalanceMap[Key, Value]) Get ¶
func (slf *BalanceMap[Key, Value]) Get(key Key) Value
Get 获取一个值
func (*BalanceMap[Key, Value]) GetExist ¶
func (slf *BalanceMap[Key, Value]) GetExist(key Key) (Value, bool)
GetExist 获取一个值并判断是否存在
func (*BalanceMap[Key, Value]) Map ¶
func (slf *BalanceMap[Key, Value]) Map() map[Key]Value
Map 转换为普通 map
func (*BalanceMap[Key, Value]) MarshalJSON ¶
func (slf *BalanceMap[Key, Value]) MarshalJSON() ([]byte, error)
func (*BalanceMap[Key, Value]) Range ¶
func (slf *BalanceMap[Key, Value]) Range(handle func(key Key, value Value) bool)
Range 遍历所有值,如果 handle 返回 true 则停止遍历
func (*BalanceMap[Key, Value]) Set ¶
func (slf *BalanceMap[Key, Value]) Set(key Key, value Value)
Set 设置一个值
func (*BalanceMap[Key, Value]) Slice ¶
func (slf *BalanceMap[Key, Value]) Slice() []Value
Slice 获取所有的值
func (*BalanceMap[Key, Value]) UnmarshalJSON ¶
func (slf *BalanceMap[Key, Value]) UnmarshalJSON(bytes []byte) error
type BalanceMapOption ¶
type BalanceMapOption[Key comparable, Value any] func(m *BalanceMap[Key, Value])
BalanceMapOption BalanceMap 的选项
func WithBalanceMapSource ¶
func WithBalanceMapSource[Key comparable, Value any](source map[Key]Value) BalanceMapOption[Key, Value]
WithBalanceMapSource 通过传入的 map 初始化
type Pool ¶
type Pool[T any] struct { // contains filtered or unexported fields }
Pool 线程安全的对象缓冲池
- 一些高频临时生成使用的对象可以通过 Pool 进行管理,例如属性计算等
- 缓冲区内存在可用对象时直接返回,否则新建一个进行返回
- 通过 Release 将使用完成的对象放回缓冲区,超出缓冲区大小的对象将被放弃
type Slice ¶
type Slice[T any] struct { // contains filtered or unexported fields }
func NewSlice ¶
func NewSlice[T any](options ...SliceOption[T]) *Slice[T]
func (*Slice[T]) GetWithRange ¶
type SliceOption ¶
func WithSliceCap ¶
func WithSliceCap[T any](cap int) SliceOption[T]
func WithSliceLen ¶
func WithSliceLen[T any](len int) SliceOption[T]
func WithSliceLenCap ¶
func WithSliceLenCap[T any](len, cap int) SliceOption[T]
Click to show internal directories.
Click to hide internal directories.