Documentation
¶
Overview ¶
Package registry provides a thread-safe registry; all methods are protected by a read-write mutex.
Index ¶
- Variables
- type Constructable
- type Destroyable
- type Group
- func (g *Group[K, V]) Add(id K, e V) (err error)
- func (g *Group[K, V]) CallWithLock(f func(d map[K]V) (e V, err error)) (V, error)
- func (g *Group[K, V]) Clear()
- func (g *Group[K, V]) Get(id K) (e V, err error)
- func (g *Group[K, V]) GetKeys() []K
- func (g *Group[K, V]) GetMap() map[K]V
- func (g *Group[K, V]) GetValues() []V
- func (g *Group[K, V]) Iterator() chan V
- func (g *Group[K, V]) Remove(id K) (err error)
- func (g *Group[K, V]) Search(key any, result chan V, f SearchFunction)
- func (g *Group[K, V]) SearchOne(key any, f SearchFunction) (d V)
- func (g *Group[K, V]) Size() int
- func (g *Group[K, V]) Tick()
- type Registry
- func (r *Registry[G, I, V]) Add(key G, id I, e V) error
- func (r *Registry[G, I, V]) AddIndex(id uint64, key I)
- func (r *Registry[G, I, V]) AsyncIterator(keys ...G) chan V
- func (r *Registry[G, I, V]) AsyncTick(keys ...G)
- func (r *Registry[G, I, V]) ClearGroup(key G)
- func (r *Registry[G, I, V]) DeleteGroup(key G)
- func (r *Registry[G, I, V]) Get(key G, id I) (e V, err error)
- func (r *Registry[G, I, V]) GetGroup(key G) (group *Group[I, V])
- func (r *Registry[G, I, V]) GetGroups(keys ...G) (groups []*Group[I, V])
- func (r *Registry[G, I, V]) GetIndex(id uint64) I
- func (r *Registry[G, I, V]) GetKeys() []G
- func (r *Registry[G, I, V]) GetValues(key G) []V
- func (r *Registry[G, I, V]) Iterator(keys ...G) chan V
- func (r *Registry[G, I, V]) LatestID() uint64
- func (r *Registry[G, I, V]) NextID() uint64
- func (r *Registry[G, I, V]) RemIndex(id uint64)
- func (r *Registry[G, I, V]) Remove(key G, id I) error
- func (r *Registry[G, I, V]) RemoveIDEverywhere(id I) error
- func (r *Registry[G, I, V]) SearchInGroup(key G, f SearchFunction) chan V
- func (r *Registry[G, I, V]) SearchOne(key G, f SearchFunction) V
- func (r *Registry[G, I, V]) SetLatestID(id uint64)
- func (r *Registry[G, I, V]) Size() int
- func (r *Registry[G, I, V]) TickGroup(key G)
- func (r *Registry[G, I, V]) TickGroups(keys ...G)
- type SearchFunction
- type Ticker
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotFoundEntity = errors.New("not found entity")
)
All kinds of errors for memory
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 (*Group[K, V]) Add ¶
Add inserts an entity into the group and calls Construct if the entity implements Constructable.
func (*Group[K, V]) CallWithLock ¶
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]) 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 ¶
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.
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]) AddIndex ¶
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]) GetGroup ¶
GetGroup returns the group for the given key, creating it if it does not exist.
func (*Registry[G, I, V]) GetGroups ¶
GetGroups returns the groups for the given keys, creating any that do not exist.
func (*Registry[G, I, V]) GetIndex ¶
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 ¶
LatestID returns the current auto-increment ID without incrementing.
func (*Registry[G, I, V]) NextID ¶
NextID atomically increments and returns the next auto-increment ID.
func (*Registry[G, I, V]) RemoveIDEverywhere ¶
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 ¶
SetLatestID atomically sets the auto-increment ID to the given value.
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