package exsync
import "go.mau.fi/util/exsync"
Index ¶
- Variables
- func MapRingBuffer[Key comparable, Value, Output any](rb *RingBuffer[Key, Value], callback func(key Key, val Value) (Output, error)) ([]Output, error)
- type Map
- func NewMap[Key comparable, Value any]() *Map[Key, Value]
- func (sm *Map[Key, Value]) Clone() *Map[Key, Value]
- func (sm *Map[Key, Value]) CopyData() map[Key]Value
- func (sm *Map[Key, Value]) Delete(key Key)
- func (sm *Map[Key, Value]) Get(key Key) (value Value, ok bool)
- func (sm *Map[Key, Value]) GetOrSet(key Key, value Value) (actual Value, wasGet bool)
- func (sm *Map[Key, Value]) Pop(key Key) (value Value, ok bool)
- func (sm *Map[Key, Value]) Set(key Key, value Value)
- func (sm *Map[Key, Value]) Swap(key Key, value Value) (oldValue Value, wasReplaced bool)
- type ReturnableOnce
- type RingBuffer
- func NewRingBuffer[Key comparable, Value any](size int) *RingBuffer[Key, Value]
- func (rb *RingBuffer[Key, Value]) Contains(val Key) bool
- func (rb *RingBuffer[Key, Value]) Get(key Key) (val Value, found bool)
- func (rb *RingBuffer[Key, Value]) Iter(callback func(key Key, val Value) error) error
- func (rb *RingBuffer[Key, Value]) Push(key Key, val Value)
- func (rb *RingBuffer[Key, Value]) Replace(key Key, val Value) bool
- func (rb *RingBuffer[Key, Value]) Size() int
Variables ¶
var ( // StopIteration can be returned by the RingBuffer.Iter or MapRingBuffer callbacks to stop iteration immediately. StopIteration = errors.New("stop iteration") // SkipItem can be returned by the MapRingBuffer callback to skip adding a specific item. SkipItem = errors.New("skip item") )
Functions ¶
func MapRingBuffer ¶
func MapRingBuffer[Key comparable, Value, Output any](rb *RingBuffer[Key, Value], callback func(key Key, val Value) (Output, error)) ([]Output, error)
Types ¶
type Map ¶
type Map[Key comparable, Value any] struct { // contains filtered or unexported fields }
Map is a simple map with a built-in mutex.
func NewMap ¶
func NewMap[Key comparable, Value any]() *Map[Key, Value]
func (*Map[Key, Value]) Clone ¶
Clone returns a copy of the map.
func (*Map[Key, Value]) CopyData ¶
func (sm *Map[Key, Value]) CopyData() map[Key]Value
CopyData returns a copy of the data in the map as a normal (non-atomic) map.
func (*Map[Key, Value]) Delete ¶
func (sm *Map[Key, Value]) Delete(key Key)
Delete removes a key from the map.
func (*Map[Key, Value]) Get ¶
Get gets a value in the map.
The boolean return parameter is the same as with normal Go map access (true if the key exists, false if not).
func (*Map[Key, Value]) GetOrSet ¶
GetOrSet gets a value in the map if the key already exists, otherwise inserts the given value and returns it.
The boolean return parameter is true if the key already exists, and false if the given value was inserted.
func (*Map[Key, Value]) Pop ¶
Pop removes a key from the map and returns the old value.
The boolean return parameter is the same as with normal Go map access (true if the key exists, false if not).
func (*Map[Key, Value]) Set ¶
func (sm *Map[Key, Value]) Set(key Key, value Value)
Set stores a value in the map.
func (*Map[Key, Value]) Swap ¶
Swap sets a value in the map and returns the old value.
The boolean return parameter is true if the value already existed, false if not.
type ReturnableOnce ¶
type ReturnableOnce[Value any] struct { // contains filtered or unexported fields }
ReturnableOnce is a wrapper for sync.Once that can return a value
func (*ReturnableOnce[Value]) Do ¶
func (ronce *ReturnableOnce[Value]) Do(fn func() (Value, error)) (Value, error)
type RingBuffer ¶
type RingBuffer[Key comparable, Value any] struct { // contains filtered or unexported fields }
func NewRingBuffer ¶
func NewRingBuffer[Key comparable, Value any](size int) *RingBuffer[Key, Value]
func (*RingBuffer[Key, Value]) Contains ¶
func (rb *RingBuffer[Key, Value]) Contains(val Key) bool
func (*RingBuffer[Key, Value]) Get ¶
func (rb *RingBuffer[Key, Value]) Get(key Key) (val Value, found bool)
func (*RingBuffer[Key, Value]) Iter ¶
func (rb *RingBuffer[Key, Value]) Iter(callback func(key Key, val Value) error) error
func (*RingBuffer[Key, Value]) Push ¶
func (rb *RingBuffer[Key, Value]) Push(key Key, val Value)
func (*RingBuffer[Key, Value]) Replace ¶
func (rb *RingBuffer[Key, Value]) Replace(key Key, val Value) bool
func (*RingBuffer[Key, Value]) Size ¶
func (rb *RingBuffer[Key, Value]) Size() int
Source Files ¶
returnonce.go ringbuffer.go syncmap.go
- Version
- v0.2.1
- Published
- Nov 16, 2023
- Platform
- linux/amd64
- Imports
- 2 packages
- Last checked
- 5 hours ago –
Tools for package owners.