heropool

package
v0.43.1-rc.1.access-me... Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RandomEjection = EjectionMode("random-ejection")
	LRUEjection    = EjectionMode("lru-ejection")
	NoEjection     = EjectionMode("no-ejection")
)

Variables

This section is empty.

Functions

func NewStates added in v0.32.0

func NewStates(numberOfStates int) []state

NewStates constructs an array of a doubly linked-lists.

Types

type EIndex

type EIndex uint32

EIndex is data type representing an value index in Pool.

const InvalidIndex EIndex = math.MaxUint32

InvalidIndex is used when a link doesn't point anywhere, in other words it is an equivalent of a nil address.

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

func (p *Pool[K, V]) Get(valueIndex EIndex) (K, V, uint64)

Get returns value corresponding to the value index from the underlying list.

func (*Pool[K, V]) Head added in v0.28.0

func (p *Pool[K, V]) Head() (key K, value V, ok bool)

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

func (p *Pool[K, V]) Remove(sliceIndex EIndex) V

Remove removes value corresponding to given getSliceIndex from the list.

func (*Pool[K, V]) Size

func (p *Pool[K, V]) Size() uint32

Size returns total number of values that this list maintains.

func (*Pool[K, V]) Touch added in v0.43.0

func (p *Pool[K, V]) Touch(idx EIndex)

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

func (p *Pool[K, V]) UpdateAtIndex(idx EIndex, newValue V)

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.

Jump to

Keyboard shortcuts

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