descriptor

package
v0.3.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsATTY

func IsATTY(fd int) bool

IsATTY is true if the file descriptor fd refers to a valid terminal type device.

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

func (t *Table[Descriptor, Object]) Grow(n int)

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]) Len

func (t *Table[Descriptor, Object]) Len() (n int)

Len returns the number of objects stored in the table.

func (*Table[Descriptor, Object]) Lookup

func (t *Table[Descriptor, Object]) Lookup(desc Descriptor) (object Object, found bool)

Lookup returns the object associated with the given descriptor.

func (*Table[Descriptor, Object]) Range

func (t *Table[Descriptor, Object]) Range(f func(Descriptor, Object) bool)

Range calls f for each object and its associated descriptor in the table. The function f might return false to interupt the iteration.

func (*Table[Descriptor, Object]) Reset

func (t *Table[Descriptor, Object]) Reset()

Reset clears the content of the table.

Jump to

Keyboard shortcuts

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