Documentation
¶
Index ¶
- func IsATTY(fd int) bool
- type Table
- func (t *Table[Descriptor, Object]) Access(desc Descriptor) *Object
- func (t *Table[Descriptor, Object]) Assign(desc Descriptor, object Object) (prev Object, replaced bool)
- func (t *Table[Descriptor, Object]) Delete(desc Descriptor)
- func (t *Table[Descriptor, Object]) Grow(n int)
- func (t *Table[Descriptor, Object]) Insert(object Object) (desc Descriptor)
- func (t *Table[Descriptor, Object]) Len() (n int)
- func (t *Table[Descriptor, Object]) Lookup(desc Descriptor) (object Object, found bool)
- func (t *Table[Descriptor, Object]) Range(f func(Descriptor, Object) bool)
- func (t *Table[Descriptor, Object]) Reset()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Table ¶
type Table[Descriptor ~int32 | ~uint32, Object any] struct { // contains filtered or unexported fields }
Table is a data structure mapping 32 bit descriptor to objects.
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: objects 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 objects in the table in order to get cheaper lookups. Memory efficiency is also crucial to support scaling with programs that open thousands of objects: 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[Descriptor, Object]) Access ¶
func (t *Table[Descriptor, Object]) Access(desc Descriptor) *Object
Access returns a pointer to the object associated with the given descriptor, which may be nil if it was not found in the table.
func (*Table[Descriptor, Object]) Assign ¶
func (t *Table[Descriptor, Object]) Assign(desc Descriptor, object Object) (prev Object, replaced bool)
Assign is similar to Insert but it inserts the object at a specific descriptor number. If another object was already associated with that number, it is returned and the boolean is set to true to indicate that a object was replaced.
func (*Table[Descriptor, Object]) Delete ¶
func (t *Table[Descriptor, Object]) Delete(desc Descriptor)
Delete deletes the object stored at the given descriptor from the table.
func (*Table[Descriptor, Object]) Grow ¶
Grow ensures that t has enough room for n objects, potentially reallocating the internal buffers if their capacity was too small to hold this many objects.
func (*Table[Descriptor, Object]) Insert ¶
func (t *Table[Descriptor, Object]) Insert(object Object) (desc Descriptor)
Insert inserts the given object to the table, returning the descriptor that it is mapped to.
The method does not perform deduplication, it is possible for the same object to be inserted multiple times, each insertion will return a different descriptor.
func (*Table[Descriptor, Object]) Lookup ¶
Lookup returns the object associated with the given descriptor.