Documentation
¶
Index ¶
- Constants
- func NewStates(numberOfStates int) []state
- type EIndex
- type EjectionMode
- type Pool
- func (p *Pool[K, V]) Add(key K, value V, owner uint64) (valueIndex EIndex, slotAvailable bool, ejectedValue V, wasEjected bool)
- func (p *Pool[K, V]) All() []PoolEntity[K, V]
- func (p *Pool[K, V]) Get(valueIndex EIndex) (K, V, uint64)
- func (p *Pool[K, V]) Head() (key K, value V, ok bool)
- func (p *Pool[K, V]) Remove(sliceIndex EIndex) V
- func (p *Pool[K, V]) Size() uint32
- func (p *Pool[K, V]) Touch(idx EIndex)
- func (p *Pool[K, V]) UpdateAtIndex(idx EIndex, newValue V)
- type PoolEntity
- type StateIndex
Constants ¶
const ( RandomEjection = EjectionMode("random-ejection") LRUEjection = EjectionMode("lru-ejection") NoEjection = EjectionMode("no-ejection") )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EjectionMode ¶
type EjectionMode string
type Pool ¶
type Pool[K comparable, V any] struct { // contains filtered or unexported fields }
func NewHeroPool ¶
func NewHeroPool[K comparable, V any](sizeLimit uint32, ejectionMode EjectionMode, logger zerolog.Logger) *Pool[K, V]
NewHeroPool returns a pointer to a new hero pool constructed based on a provided EjectionMode, logger and a provided fixed size.
func (*Pool[K, V]) Add ¶
func (p *Pool[K, V]) Add(key K, value V, owner uint64) ( valueIndex EIndex, slotAvailable bool, ejectedValue V, wasEjected bool)
Add writes given value into a poolEntity on the underlying values linked-list.
The boolean return value (slotAvailable) says whether pool has an available slot. Pool goes out of available slots if it is full and no ejection is set.
If the pool has no available slots and an ejection is set, ejection occurs when adding a new value. If an ejection occurred, ejectedEntity holds the ejected value.
Returns:
- valueIndex: The index in the pool where the new entity was inserted. If no slot is available (and no ejection occurs), this will be set to InvalidIndex.
- slotAvailable: Indicates whether an available slot was found. It is true if the entity was inserted (either in a free slot or by ejecting an existing entity).
- ejectedValue: If an ejection occurred to free a slot, this value holds the entity that was ejected; otherwise, it is the zero value of type V.
- wasEjected: Indicates whether an ejection was performed (true if an entity was ejected, false if the insertion simply used an available free slot).
func (*Pool[K, V]) All ¶
func (p *Pool[K, V]) All() []PoolEntity[K, V]
All returns all stored values in this pool.
func (*Pool[K, V]) Get ¶
Get returns value corresponding to the value index from the underlying list.
func (*Pool[K, V]) Head ¶ added in v0.28.0
Head returns the head of used items. Assuming no ejection happened and pool never goes beyond limit, Head returns the first inserted key and value of the element.
func (*Pool[K, V]) Remove ¶ added in v0.27.0
Remove removes value corresponding to given getSliceIndex from the list.
func (*Pool[K, V]) Touch ¶ added in v0.43.0
Touch marks the entry at pool index as “recently used” by moving it from the head of the used list to its tail.
func (*Pool[K, V]) UpdateAtIndex ¶ added in v0.43.0
UpdateAtIndex replaces the value at the given pool index.
type PoolEntity ¶
type PoolEntity[K comparable, V any] struct { // contains filtered or unexported fields }
func (PoolEntity[K, V]) Entity ¶
func (p PoolEntity[K, V]) Entity() V
func (PoolEntity[K, V]) Id ¶
func (p PoolEntity[K, V]) Id() K
type StateIndex ¶ added in v0.32.0
type StateIndex uint
StateIndex is a type of state of a placeholder in a pool.