Documentation ¶
Index ¶
- Variables
- func MapRingBuffer[Key comparable, Value, Output any](rb *RingBuffer[Key, Value], callback func(key Key, val Value) (Output, error)) ([]Output, error)
- type Event
- type EventChan
- type Map
- 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 ReturnableOncedeprecated
- type RingBuffer
- 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
- type Set
Constants ¶
This section is empty.
Variables ¶
var ( // StopIteration can be returned by the RingBuffer.Iter or MapRingBuffer callbacks to stop iteration immediately. StopIteration = errors.New("stop iteration") //lint:ignore ST1012 not an error // SkipItem can be returned by the MapRingBuffer callback to skip adding a specific item. SkipItem = errors.New("skip item") //lint:ignore ST1012 not an error )
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 Event ¶ added in v0.7.0
type Event struct {
// contains filtered or unexported fields
}
Event is a wrapper around a channel that can be used to notify multiple waiters that some event has happened.
It's modelled after Python's asyncio.Event: https://docs.python.org/3/library/asyncio-sync.html#asyncio.Event
func NewEvent ¶ added in v0.7.0
func NewEvent() *Event
NewEvent creates a new event. It will initially be unset.
func (*Event) Clear ¶ added in v0.7.0
func (e *Event) Clear()
Clear clears the event, making it unset. Future calls to Wait will now block until Set is called again. If the event is not already set, this is a no-op and existing calls to Wait will keep working.
func (*Event) GetChan ¶ added in v0.7.0
GetChan returns the channel that will be closed when the event is set.
func (*Event) Set ¶ added in v0.7.0
func (e *Event) Set()
Set sets the event, notifying all waiters.
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]) 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).
type ReturnableOnce
deprecated
type ReturnableOnce[Value any] struct { // contains filtered or unexported fields }
ReturnableOnce is a wrapper for sync.Once that can return a value
Deprecated: Use sync.OnceValues instead.
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
type Set ¶ added in v0.3.0
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is a wrapper around a map[T]struct{} with a built-in mutex.
func NewSet ¶ added in v0.3.0
func NewSet[T comparable]() *Set[T]
NewSet constructs a Set with an empty map.
func NewSetWithItems ¶ added in v0.3.0
func NewSetWithItems[T comparable](items []T) *Set[T]
NewSetWithItems constructs a Set with items from the given slice pre-filled. The slice is not modified or used after the function returns, so using it after this is safe.
func NewSetWithMap ¶ added in v0.3.0
func NewSetWithMap[T comparable](m map[T]empty) *Set[T]
NewSetWithMap constructs a Set with the given map. Accessing the map directly after passing it here is not safe.
func NewSetWithSize ¶ added in v0.3.0
func NewSetWithSize[T comparable](size int) *Set[T]
NewSetWithSize constructs a Set with a map that has been allocated the given amount of space.
func (*Set[T]) Add ¶ added in v0.3.0
Add adds an item to the set. The return value is true if the item was added to the set, or false otherwise.
func (*Set[T]) Pop ¶ added in v0.8.0
Pop removes the given item from the set. The return value is true if the item was in the set, or false otherwise.
func (*Set[T]) Remove ¶ added in v0.3.0
func (s *Set[T]) Remove(item T)
Remove removes the given item from the set.
func (*Set[T]) ReplaceAll ¶ added in v0.8.0
ReplaceAll replaces this set with the given set. If the given set is nil, the set is cleared.