core

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BiIndex

type BiIndex struct {
	// contains filtered or unexported fields
}

BiIndex maps between integer ids and string names with stable ids. Deleted ids are pushed onto a free list for reuse.

func NewBiIndex

func NewBiIndex(cap int) *BiIndex

NewBiIndex create a new BiIndex with optional capacity hint.

func (*BiIndex) Assign

func (s *BiIndex) Assign(name string) (int, bool)

Assign assigns a new id for name if it doesn't exist, reusing freed ids if any. Returns (id, true) if newly assigned, or (existingID, false) if name existed.

func (*BiIndex) Clear

func (s *BiIndex) Clear()

Clear removes all mappings and resets free list and counters.

func (*BiIndex) Clone

func (s *BiIndex) Clone() *BiIndex

Clone creates a deep copy of the BiIndex including reuse metadata.

func (*BiIndex) DeleteAndShift

func (s *BiIndex) DeleteAndShift(id int) (string, map[int]int, bool)

DeleteAndShift deletes the mapping at id and shifts all mappings with ids greater than id down by 1. It returns the deleted name, a mapping of oldID->newID for all shifted ids, and true on success. This operation is O(n) and will change many ids; mapping helps callers update references.

func (*BiIndex) DeleteByID

func (s *BiIndex) DeleteByID(id int) (string, bool)

DeleteByID removes the mapping at id and returns the deleted name. The id is pushed to free list for reuse.

func (*BiIndex) DeleteByName

func (s *BiIndex) DeleteByName(name string) bool

DeleteByName removes the mapping for name.

func (*BiIndex) Get

func (s *BiIndex) Get(id int) (string, bool)

Get returns the name for the given id.

func (*BiIndex) Has

func (s *BiIndex) Has(name string) bool

Has reports whether the given name exists.

func (*BiIndex) IDs

func (s *BiIndex) IDs() []int

IDs returns a slice of active ids.

func (*BiIndex) Index

func (s *BiIndex) Index(name string) (int, bool)

Index returns the id for the given name.

func (*BiIndex) Len

func (s *BiIndex) Len() int

Len returns number of active mappings.

func (*BiIndex) Set

func (s *BiIndex) Set(id int, name string) (string, bool)

Set assigns name to a specific id. Returns previous name at that id ("" if none) and true on success. If the name previously existed at a different id, that old mapping is removed.

Jump to

Keyboard shortcuts

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