idtable

package
v0.8.20 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// UninitializedEntryID provides an invalid value for EntryID (since
	// its default value is valid). Entries removed from the table will be
	// set to this ID.
	UninitializedEntryID = EntryID{-1}
)

Functions

This section is empty.

Types

type Entry

type Entry interface {
	// SetID will set the id of an entry on a table when AddEntry() is
	// called. The id can be used in the GetEntry() and RemoveEntry() calls.
	SetID(id EntryID)
}

Entry is an interface for table entries

type EntryID

type EntryID struct {
	ID int
}

EntryID is a table entry identifier NB: we wrap this to get some type safety for the SetID() methof of the Entry interface

type Table

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

Table is the id table

func New

func New() *Table

New allocates a new id table

func (*Table) AddEntry

func (t *Table) AddEntry(entry Entry)

AddEntry will add an entry to the table. The SetID() method will be called with the id for the entry.

func (*Table) GetEntry

func (t *Table) GetEntry(id EntryID) (Entry, error)

GetEntry returns an entry or an error

func (*Table) Len

func (t *Table) Len() int

Len returns the number of entries

func (*Table) RemoveEntry

func (t *Table) RemoveEntry(id EntryID) (Entry, error)

RemoveEntry removes an entry and returns it (or an error if entry does not exist) before returned, SetID(UninitializedEntryID) is called

Jump to

Keyboard shortcuts

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