registry

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

README

registry

Implementation of in-memory data store

Documentation

Overview

Package registry provides a thread-safe registry; all methods are protected by a read-write mutex.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFoundEntity = errors.New("not found entity")
)

All kinds of errors for memory

View Source
var Nothing = struct{}{}

Nothing empty struct

Functions

This section is empty.

Types

type Constructable

type Constructable interface {
	Construct() error
}

Constructable able to be construct in memory

type Destroyable

type Destroyable interface {
	Destroy() error
}

Destroyable able to be destroyed in memory

type Group

type Group[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Group contains all entities for given type. Thread-safe via SafeOrderedMap.

func NewGroup

func NewGroup[K comparable, V any]() *Group[K, V]

NewGroup return registry

func (*Group[K, V]) Add

func (g *Group[K, V]) Add(id K, e V) (err error)

Add inserts an entity into the group and calls Construct if the entity implements Constructable.

func (*Group[K, V]) CallWithLock

func (g *Group[K, V]) CallWithLock(f func(d map[K]V) (e V, err error)) (V, error)

CallWithLock executes f with a snapshot of the group's map and returns the result.

func (*Group[K, V]) Clear

func (g *Group[K, V]) Clear()

Clear removes all entities from the group.

func (*Group[K, V]) Get

func (g *Group[K, V]) Get(id K) (e V, err error)

Get returns the entity with the given ID or ErrNotFoundEntity if absent.

func (*Group[K, V]) GetKeys

func (g *Group[K, V]) GetKeys() []K

GetKeys returns all entity keys in the group.

func (*Group[K, V]) GetMap

func (g *Group[K, V]) GetMap() map[K]V

GetMap returns a plain map copy of all entities in the group.

func (*Group[K, V]) GetValues

func (g *Group[K, V]) GetValues() []V

GetValues returns all entity values in the group.

func (*Group[K, V]) Iterator

func (g *Group[K, V]) Iterator() chan V

Iterator returns a channel that yields all entity values in the group.

func (*Group[K, V]) Remove

func (g *Group[K, V]) Remove(id K) (err error)

Remove deletes the entity with the given ID and calls Destroy if it implements Destroyable.

func (*Group[K, V]) Search

func (g *Group[K, V]) Search(key any, result chan V, f SearchFunction)

Search iterates over all entities in parallel and sends those matching f to the result channel.

func (*Group[K, V]) SearchOne

func (g *Group[K, V]) SearchOne(key any, f SearchFunction) (d V)

SearchOne returns the first entity matching f, or the zero value if none match.

func (*Group[K, V]) Size

func (g *Group[K, V]) Size() int

Size returns the number of entities in the group.

func (*Group[K, V]) Tick

func (g *Group[K, V]) Tick()

Tick calls Tick on every entity in the group that implements Ticker.

type Registry

type Registry[G comparable, I comparable, V any] struct {
	// contains filtered or unexported fields
}

Registry is a thread-safe collection of named groups, each holding entities keyed by ID.

func NewRegistry

func NewRegistry[G comparable, I comparable, V any]() *Registry[G, I, V]

NewRegistry creates a new empty Registry.

func (*Registry[G, I, V]) Add

func (r *Registry[G, I, V]) Add(key G, id I, e V) error

Add inserts an entity into the specified group.

func (*Registry[G, I, V]) AddIndex

func (r *Registry[G, I, V]) AddIndex(id uint64, key I)

AddIndex associates a uint64 ID with an entity key in the index.

func (*Registry[G, I, V]) AsyncIterator

func (r *Registry[G, I, V]) AsyncIterator(keys ...G) chan V

AsyncIterator returns a channel that yields entities from the given groups concurrently.

func (*Registry[G, I, V]) AsyncTick

func (r *Registry[G, I, V]) AsyncTick(keys ...G)

AsyncTick calls Tick concurrently on all entities in each specified group.

func (*Registry[G, I, V]) ClearGroup

func (r *Registry[G, I, V]) ClearGroup(key G)

ClearGroup removes all entities from the specified group.

func (*Registry[G, I, V]) DeleteGroup

func (r *Registry[G, I, V]) DeleteGroup(key G)

DeleteGroup removes the group for the given key.

func (*Registry[G, I, V]) Get

func (r *Registry[G, I, V]) Get(key G, id I) (e V, err error)

Get retrieves an entity by group key and entity ID.

func (*Registry[G, I, V]) GetGroup

func (r *Registry[G, I, V]) GetGroup(key G) (group *Group[I, V])

GetGroup returns the group for the given key, creating it if it does not exist.

func (*Registry[G, I, V]) GetGroups

func (r *Registry[G, I, V]) GetGroups(keys ...G) (groups []*Group[I, V])

GetGroups returns the groups for the given keys, creating any that do not exist.

func (*Registry[G, I, V]) GetIndex

func (r *Registry[G, I, V]) GetIndex(id uint64) I

GetIndex returns the entity key associated with the given uint64 ID.

func (*Registry[G, I, V]) GetKeys

func (r *Registry[G, I, V]) GetKeys() []G

GetKeys returns all group keys in the registry.

func (*Registry[G, I, V]) GetValues

func (r *Registry[G, I, V]) GetValues(key G) []V

GetValues returns all entity values from the specified group.

func (*Registry[G, I, V]) Iterator

func (r *Registry[G, I, V]) Iterator(keys ...G) chan V

Iterator returns a channel that yields entities from the given groups sequentially.

func (*Registry[G, I, V]) LatestID

func (r *Registry[G, I, V]) LatestID() uint64

LatestID returns the current auto-increment ID without incrementing.

func (*Registry[G, I, V]) NextID

func (r *Registry[G, I, V]) NextID() uint64

NextID atomically increments and returns the next auto-increment ID.

func (*Registry[G, I, V]) RemIndex

func (r *Registry[G, I, V]) RemIndex(id uint64)

RemIndex removes the index entry for the given uint64 ID.

func (*Registry[G, I, V]) Remove

func (r *Registry[G, I, V]) Remove(key G, id I) error

Remove deletes an entity from the specified group.

func (*Registry[G, I, V]) RemoveIDEverywhere

func (r *Registry[G, I, V]) RemoveIDEverywhere(id I) error

RemoveIDEverywhere removes the entity with the given ID from all groups.

func (*Registry[G, I, V]) SearchInGroup

func (r *Registry[G, I, V]) SearchInGroup(key G, f SearchFunction) chan V

SearchInGroup searches for entities matching f within the specified group and returns results via channel.

func (*Registry[G, I, V]) SearchOne

func (r *Registry[G, I, V]) SearchOne(key G, f SearchFunction) V

SearchOne returns the first entity matching f within the specified group.

func (*Registry[G, I, V]) SetLatestID

func (r *Registry[G, I, V]) SetLatestID(id uint64)

SetLatestID atomically sets the auto-increment ID to the given value.

func (*Registry[G, I, V]) Size

func (r *Registry[G, I, V]) Size() int

Size returns the number of groups in the registry.

func (*Registry[G, I, V]) TickGroup

func (r *Registry[G, I, V]) TickGroup(key G)

TickGroup calls Tick on all entities in the specified group.

func (*Registry[G, I, V]) TickGroups

func (r *Registry[G, I, V]) TickGroups(keys ...G)

TickGroups calls Tick sequentially on all entities in each specified group.

type SearchFunction

type SearchFunction func(key interface{}, id interface{}, data interface{}) bool

SearchFunction describe specification for filter function

type Ticker

type Ticker interface {
	Tick()
}

Ticker describe function for execute tick

Jump to

Keyboard shortcuts

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