core

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

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

func NewBiIndex(cap int) *BiIndex

NewBiIndex create a new BiIndex with optional capacity hint.

func (*BiIndex) Assign

func (s *BiIndex) Assign(name string) (int, bool)

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) Clone

func (s *BiIndex) Clone() *BiIndex

Clone creates a deep copy of the BiIndex including reuse metadata.

func (*BiIndex) DeleteAndShift

func (s *BiIndex) DeleteAndShift(id int) (string, map[int]int, bool)

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

func (s *BiIndex) DeleteByID(id int) (string, bool)

DeleteByID removes the mapping at id and returns the deleted name. The id is pushed to free list for reuse.

func (*BiIndex) DeleteByName

func (s *BiIndex) DeleteByName(name string) bool

DeleteByName removes the mapping for name.

func (*BiIndex) Get

func (s *BiIndex) Get(id int) (string, bool)

Get returns the name for the given id.

func (*BiIndex) Has

func (s *BiIndex) Has(name string) bool

Has reports whether the given name exists.

func (*BiIndex) IDs

func (s *BiIndex) IDs() []int

IDs returns a slice of active ids.

func (*BiIndex) Index

func (s *BiIndex) Index(name string) (int, bool)

Index returns the id for the given name.

func (*BiIndex) Len

func (s *BiIndex) Len() int

Len returns number of active mappings.

func (*BiIndex) Set

func (s *BiIndex) Set(id int, name string) (string, bool)

Set assigns name to a specific id. Returns previous name at that id ("" if none) and true on success. If the name previously existed at a different id, that old mapping is removed.

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 NewRing added in v0.2.14

func NewRing[T any](capacity int) *Ring[T]

NewRing creates a ring with the given initial capacity.

func (*Ring[T]) Clear added in v0.2.14

func (r *Ring[T]) Clear()

Clear removes all elements while keeping the capacity.

func (*Ring[T]) DeleteAt added in v0.2.14

func (r *Ring[T]) DeleteAt(idx int) (T, bool)

DeleteAt removes the element at logical index idx.

func (*Ring[T]) Get added in v0.2.14

func (r *Ring[T]) Get(i int) (T, bool)

Get returns the element at logical index i (0..Len-1).

func (*Ring[T]) Len added in v0.2.14

func (r *Ring[T]) Len() int

Len returns the number of elements currently in the ring.

func (*Ring[T]) PopBack added in v0.2.14

func (r *Ring[T]) PopBack() (T, bool)

PopBack removes and returns the last element.

func (*Ring[T]) PopFront added in v0.2.14

func (r *Ring[T]) PopFront() (T, bool)

PopFront removes and returns the front element.

func (*Ring[T]) Push added in v0.2.14

func (r *Ring[T]) Push(v T)

Push adds an element to the back of the ring.

func (*Ring[T]) ToSlice added in v0.2.14

func (r *Ring[T]) ToSlice() []T

ToSlice returns a copy of the ring contents in logical order.

Jump to

Keyboard shortcuts

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