Documentation ¶
Index ¶
Constants ¶
const ( GenerationShiftBits = 64 - 8 FlagsShiftBits = 64 - 16 IndexBitMask = 0x00_00_FFFF_FFFF_FFFF )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handle ¶
type Handle uint64
Byte 1: Generation; Byte 2: Flags; Bytes 3-8: Index
func (Handle) Flags ¶
func (h Handle) Flags() HandleFlag
func (Handle) Generation ¶
func (Handle) HasFlag ¶
func (h Handle) HasFlag(ef HandleFlag) bool
type HandleFlag ¶
type HandleFlag byte
const ( HandleFlag_None HandleFlag = 0 HandleFlag_Alive HandleFlag = 1 << (iota - 1) )
type Iterator ¶ added in v0.18.1
type Iterator[T any] struct { // contains filtered or unexported fields }
Iterator goes through the entire registry it was created from and returns all alive items, and nil after its done.
The iterator will still work if items are added/removed to the registry after it was created, but the following conditions apply:
- If items are removed, iterator will not show the removed items (assuming it didn't return them before their removal)
- If items are added, the iterator will either only return older items (i.e. is not affected), or only return newer items (i.e. items that were going to be returned before will now not get returned in favor of newly inserted items), or a mix of old and new items. However, in all cases the iterator will *never* returns more items than were alive at the time of the iterator's creation.
- If items were both added and removed, the iterator might follow either of the previous 2 cases or a combination of them
To summarize: The iterator will *never* return more items than were alive at the time of its creation, and will *never* return freed items
Example usage:
for item, handle := it.Next(); !it.IsDone(); item, handle = it.Next() { // Do stuff }
type Registry ¶
type Registry[T any] struct { ItemCount uint Handles []Handle Items []T FreeList *freeListitem FreeListSize uint32 // The number of slots required to be in the free list before the free list // is used for creating new entries FreeListUsageThreshold uint32 }
Registry is a storage data structure that can efficiently create/get/free items using generational indices. Each item stored in the registry is associated with a 'handle' object that is used to get and free objects
The registry 'owns' all items it stores and returns pointers to items in its array. All items are allocated upfront.
It is NOT safe to concurrently create or free items. However, it is SAFE to concurrently get items