synchronization

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 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 Map

type Map[Key comparable, Value any] struct {
	// contains filtered or unexported fields
}

Map 并发安全的字典数据结构

func NewMap

func NewMap[Key comparable, value any]() *Map[Key, value]

func (*Map[Key, Value]) Atom

func (slf *Map[Key, Value]) Atom(handle func(m hash.Map[Key, Value]))

Atom 原子操作

func (*Map[Key, Value]) AtomGetSet

func (slf *Map[Key, Value]) AtomGetSet(key Key, handle func(value Value, exist bool) (newValue Value, isSet bool))

AtomGetSet 原子方式获取一个值并在之后进行赋值

func (*Map[Key, Value]) Clear

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

func (*Map[Key, Value]) ClearHandle

func (slf *Map[Key, Value]) ClearHandle(handle func(key Key, value Value))

func (*Map[Key, Value]) Delete

func (slf *Map[Key, Value]) Delete(key Key)

func (*Map[Key, Value]) DeleteExist

func (slf *Map[Key, Value]) DeleteExist(key Key) bool

func (*Map[Key, Value]) DeleteGet

func (slf *Map[Key, Value]) DeleteGet(key Key) Value

func (*Map[Key, Value]) DeleteGetExist

func (slf *Map[Key, Value]) DeleteGetExist(key Key) (Value, bool)

func (*Map[Key, Value]) Exist

func (slf *Map[Key, Value]) Exist(key Key) bool

func (*Map[Key, Value]) Get

func (slf *Map[Key, Value]) Get(key Key) Value

func (*Map[Key, Value]) GetExist

func (slf *Map[Key, Value]) GetExist(key Key) (Value, bool)

func (*Map[Key, Value]) GetOne

func (slf *Map[Key, Value]) GetOne() (value Value)

GetOne 获取一个

func (*Map[Key, Value]) Keys

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

func (*Map[Key, Value]) Map

func (slf *Map[Key, Value]) Map() map[Key]Value

func (*Map[Key, Value]) MarshalJSON

func (slf *Map[Key, Value]) MarshalJSON() ([]byte, error)

func (*Map[Key, Value]) Range

func (slf *Map[Key, Value]) Range(handle func(key Key, value Value))

func (*Map[Key, Value]) RangeBreakout

func (slf *Map[Key, Value]) RangeBreakout(handle func(key Key, value Value) bool)

func (*Map[Key, Value]) RangeFree

func (slf *Map[Key, Value]) RangeFree(handle func(key Key, value Value, skip func(), breakout func()))

func (*Map[Key, Value]) RangeSkip

func (slf *Map[Key, Value]) RangeSkip(handle func(key Key, value Value) bool)

func (*Map[Key, Value]) Set

func (slf *Map[Key, Value]) Set(key Key, value Value)

func (*Map[Key, Value]) Size

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

func (*Map[Key, Value]) Slice

func (slf *Map[Key, Value]) Slice() []Value

func (*Map[Key, Value]) UnmarshalJSON

func (slf *Map[Key, Value]) UnmarshalJSON(bytes []byte) error

type MapSegment

type MapSegment[Key comparable, Value any] struct {
	// contains filtered or unexported fields
}

MapSegment 基于分段锁实现的并发安全的字典数据结构map

func NewMapSegment

func NewMapSegment[Key comparable, value any](segmentCount int) *MapSegment[Key, value]

func (*MapSegment[Key, Value]) Atom

func (slf *MapSegment[Key, Value]) Atom(handle func(m hash.Map[Key, Value]))

func (*MapSegment[Key, Value]) AtomGetSet

func (slf *MapSegment[Key, Value]) AtomGetSet(key Key, handle func(value Value, exist bool) (newValue Value, isSet bool))

AtomGetSet 原子方式获取一个值并在之后进行赋值

func (*MapSegment[Key, Value]) Clear

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

func (*MapSegment[Key, Value]) ClearHandle

func (slf *MapSegment[Key, Value]) ClearHandle(handle func(key Key, value Value))

func (*MapSegment[Key, Value]) Delete

func (slf *MapSegment[Key, Value]) Delete(key Key)

func (*MapSegment[Key, Value]) DeleteExist

func (slf *MapSegment[Key, Value]) DeleteExist(key Key) bool

func (*MapSegment[Key, Value]) DeleteGet

func (slf *MapSegment[Key, Value]) DeleteGet(key Key) (value Value)

func (*MapSegment[Key, Value]) DeleteGetExist

func (slf *MapSegment[Key, Value]) DeleteGetExist(key Key) (value Value, exist bool)

func (*MapSegment[Key, Value]) Exist

func (slf *MapSegment[Key, Value]) Exist(key Key) bool

func (*MapSegment[Key, Value]) Get

func (slf *MapSegment[Key, Value]) Get(key Key) (value Value)

func (*MapSegment[Key, Value]) GetExist

func (slf *MapSegment[Key, Value]) GetExist(key Key) (value Value, exist bool)

func (*MapSegment[Key, Value]) GetOne

func (slf *MapSegment[Key, Value]) GetOne() (value Value)

GetOne 获取一个

func (*MapSegment[Key, Value]) Keys

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

func (*MapSegment[Key, Value]) Map

func (slf *MapSegment[Key, Value]) Map() map[Key]Value

func (*MapSegment[Key, Value]) MarshalJSON

func (slf *MapSegment[Key, Value]) MarshalJSON() ([]byte, error)

func (*MapSegment[Key, Value]) Range

func (slf *MapSegment[Key, Value]) Range(handle func(key Key, value Value))

func (*MapSegment[Key, Value]) RangeBreakout

func (slf *MapSegment[Key, Value]) RangeBreakout(handle func(key Key, value Value) bool)

func (*MapSegment[Key, Value]) RangeFree

func (slf *MapSegment[Key, Value]) RangeFree(handle func(key Key, value Value, skip func(), breakout func()))

func (*MapSegment[Key, Value]) RangeSkip

func (slf *MapSegment[Key, Value]) RangeSkip(handle func(key Key, value Value) bool)

func (*MapSegment[Key, Value]) Set

func (slf *MapSegment[Key, Value]) Set(key Key, value Value)

func (*MapSegment[Key, Value]) Size

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

func (*MapSegment[Key, Value]) Slice

func (slf *MapSegment[Key, Value]) Slice() []Value

func (*MapSegment[Key, Value]) UnmarshalJSON

func (slf *MapSegment[Key, Value]) UnmarshalJSON(bytes []byte) error

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

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

func (*Pool[T]) IsClose added in v0.0.7

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