Documentation
¶
Index ¶
- type Table
- func (t *Table[Key, Item]) Delete(key Key)
- func (t *Table[Key, Item]) Grow(n int)
- func (t *Table[Key, Item]) Insert(item Item) (key Key)
- func (t *Table[Key, Item]) InsertAt(item Item, key Key)
- func (t *Table[Key, Item]) Len() (n int)
- func (t *Table[Key, Item]) Lookup(key Key) (item Item, found bool)
- func (t *Table[Key, Item]) Range(f func(Key, Item) bool)
- func (t *Table[Key, Item]) Reset()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Table ¶
Table is a data structure mapping 32 bit descriptor to items.
The data structure optimizes for memory density and lookup performance, trading off compute at insertion time. This is a useful compromise for the use cases we employ it with: items are usually accessed a lot more often than they are inserted, each operation requires a table lookup so we are better off spending extra compute to insert items in the table in order to get cheaper lookups. Memory efficiency is also crucial to support scaling with programs that maintain thousands of items: having a high or non-linear memory-to-item ratio could otherwise be used as an attack vector by malicous applications attempting to damage performance of the host.
func (*Table[Key, Item]) Delete ¶
func (t *Table[Key, Item]) Delete(key Key)
Delete deletes the item stored at the given key from the table.
func (*Table[Key, Item]) Grow ¶
Grow ensures that t has enough room for n items, potentially reallocating the internal buffers if their capacity was too small to hold this many items.
func (*Table[Key, Item]) Insert ¶
func (t *Table[Key, Item]) Insert(item Item) (key Key)
Insert inserts the given item to the table, returning the key that it is mapped to.
The method does not perform deduplication, it is possible for the same item to be inserted multiple times, each insertion will return a different key.
func (*Table[Key, Item]) InsertAt ¶
func (t *Table[Key, Item]) InsertAt(item Item, key Key)
InsertAt inserts the given `item` at the item descriptor `key`.
func (*Table[Key, Item]) Lookup ¶
Lookup returns the item associated with the given key (may be nil).