concurrent

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

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]) Clear

func (slf *BalanceMap[Key, Value]) Clear()

Clear 清空

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]) Keys

func (slf *BalanceMap[Key, Value]) Keys() []Key

Keys 获取所有的键

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]) Size

func (slf *BalanceMap[Key, Value]) Size() int

Size 获取数量

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 将使用完成的对象放回缓冲区,超出缓冲区大小的对象将被放弃

func NewPool

func NewPool[T any](bufferSize int, generator func() T, releaser func(data T)) *Pool[T]

func (*Pool[T]) Close

func (slf *Pool[T]) Close()

func (*Pool[T]) EAC added in v0.0.31

func (slf *Pool[T]) EAC(size int)

EAC 动态调整缓冲区大小,适用于突发场景使用

  • 当 size <= 0 时,不进行调整
  • 当缓冲区大小不足时,会导致大量的新对象生成、销毁,增加 GC 压力。此时应考虑调整缓冲区大小
  • 当缓冲区大小过大时,会导致大量的对象占用内存,增加内存压力。此时应考虑调整缓冲区大小

func (*Pool[T]) Get

func (slf *Pool[T]) Get() T

func (*Pool[T]) IsClose

func (slf *Pool[T]) IsClose() bool

func (*Pool[T]) Release

func (slf *Pool[T]) Release(data T)

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]) Append

func (slf *Slice[T]) Append(values ...T)

func (*Slice[T]) Clear

func (slf *Slice[T]) Clear()

func (*Slice[T]) Get

func (slf *Slice[T]) Get(index int) T

func (*Slice[T]) GetData

func (slf *Slice[T]) GetData() []T

func (*Slice[T]) GetWithRange

func (slf *Slice[T]) GetWithRange(start, end int) []T

func (*Slice[T]) Release

func (slf *Slice[T]) Release()

func (*Slice[T]) Set

func (slf *Slice[T]) Set(index int, value T)

type SliceOption

type SliceOption[T any] func(slice *Slice[T])

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]

Jump to

Keyboard shortcuts

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