Documentation
¶
Index ¶
- func AtomicDo[T any](actor *AtomicActor, owner *T, f func(*T))
- func AtomicDoWithInit[T any](actor *AtomicActor, owner *T, f func(*T), initHook func())
- type AtomicActor
- type AtomicGroup
- type BiIndex
- func (s *BiIndex) Assign(name string) (int, bool)
- func (s *BiIndex) Clear()
- func (s *BiIndex) Clone() *BiIndex
- func (s *BiIndex) DeleteAndShift(id int) (string, map[int]int, bool)
- func (s *BiIndex) DeleteByID(id int) (string, bool)
- func (s *BiIndex) DeleteByName(name string) bool
- func (s *BiIndex) Get(id int) (string, bool)
- func (s *BiIndex) Has(name string) bool
- func (s *BiIndex) IDs() []int
- func (s *BiIndex) Index(name string) (int, bool)
- func (s *BiIndex) Len() int
- func (s *BiIndex) Set(id int, name string) (string, bool)
- type Ring
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicDo ¶ added in v0.2.14
func AtomicDo[T any](actor *AtomicActor, owner *T, f func(*T))
AtomicDo executes f with actor-style serialization.
func AtomicDoWithInit ¶ added in v0.2.14
func AtomicDoWithInit[T any](actor *AtomicActor, owner *T, f func(*T), initHook func())
AtomicDoWithInit executes f with actor-style serialization and runs initHook once.
Types ¶
type AtomicActor ¶ added in v0.2.14
type AtomicActor struct {
// contains filtered or unexported fields
}
AtomicActor provides actor-style serialized execution for any struct. Use AtomicDo to run a function with serialized access.
func NewAtomicActor ¶ added in v0.2.14
func NewAtomicActor(group *AtomicGroup) *AtomicActor
NewAtomicActor creates a new AtomicActor bound to the provided group. If group is nil, DefaultAtomicGroup is used.
func (*AtomicActor) Close ¶ added in v0.2.14
func (a *AtomicActor) Close()
Close closes the actor loop and prevents further scheduling.
func (*AtomicActor) IsClosed ¶ added in v0.2.14
func (a *AtomicActor) IsClosed() bool
IsClosed reports whether the actor has been closed.
func (*AtomicActor) SetGroupOnce ¶ added in v0.2.14
func (a *AtomicActor) SetGroupOnce(group *AtomicGroup)
SetGroupOnce assigns the reentrancy group for this actor once.
type AtomicGroup ¶ added in v0.2.14
type AtomicGroup struct {
// contains filtered or unexported fields
}
AtomicGroup defines a reentrancy scope for AtomicActor. If a goroutine is inside any AtomicActor belonging to the same group, subsequent AtomicDo calls within that goroutine will run inline.
func DefaultAtomicGroup ¶ added in v0.2.14
func DefaultAtomicGroup() *AtomicGroup
DefaultAtomicGroup returns the package-wide default group.
func NewAtomicGroup ¶ added in v0.2.14
func NewAtomicGroup() *AtomicGroup
NewAtomicGroup creates a new AtomicGroup.
type BiIndex ¶
type BiIndex struct {
// contains filtered or unexported fields
}
BiIndex maps between integer ids and string names with stable ids. Deleted ids are pushed onto a free list for reuse.
func NewBiIndex ¶
NewBiIndex create a new BiIndex with optional capacity hint.
func (*BiIndex) Assign ¶
Assign assigns a new id for name if it doesn't exist, reusing freed ids if any. Returns (id, true) if newly assigned, or (existingID, false) if name existed.
func (*BiIndex) Clear ¶
func (s *BiIndex) Clear()
Clear removes all mappings and resets free list and counters.
func (*BiIndex) DeleteAndShift ¶
DeleteAndShift deletes the mapping at id and shifts all mappings with ids greater than id down by 1. It returns the deleted name, a mapping of oldID->newID for all shifted ids, and true on success. This operation is O(n) and will change many ids; mapping helps callers update references.
func (*BiIndex) DeleteByID ¶
DeleteByID removes the mapping at id and returns the deleted name. The id is pushed to free list for reuse.
func (*BiIndex) DeleteByName ¶
DeleteByName removes the mapping for name.
type Ring ¶ added in v0.2.14
type Ring[T any] struct { // contains filtered or unexported fields }
Ring is a non-thread-safe circular buffer with dynamic growth. It is suitable for building higher-level queues or error rings.
func (*Ring[T]) Clear ¶ added in v0.2.14
func (r *Ring[T]) Clear()
Clear removes all elements while keeping the capacity.