idtable

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package idtable gives things small ids, which the C engine passes back to the host on every callback, and finds a thing by its id with two atomic reads and no lock: callbacks of VMs on many goroutines do not wait for each other, and do not write to memory they share.

Index

Constants

View Source
const Max = chunks * chunkSize

Max is one more than the largest id a Table hands out.

Variables

This section is empty.

Functions

This section is empty.

Types

type Table

type Table[T any] struct {
	// contains filtered or unexported fields
}

A Table holds things by id. The zero Table is empty and ready to use. Add and Remove take a lock, Get takes none. A table hands out its own ids by Add and Remove, or holds things under the ids of another table by Put and Delete, never both.

func (*Table[T]) Add

func (t *Table[T]) Add(x *T) (uint32, error)

Add gives x an id: never 0, and not the id of another thing in the table. An id that Remove took back is handed out again.

func (*Table[T]) Delete

func (t *Table[T]) Delete(id uint32)

Delete takes out what Put put under id. It panics when id holds nothing.

func (*Table[T]) Get

func (t *Table[T]) Get(id uint32) *T

Get returns what id holds, or nil.

func (*Table[T]) Put

func (t *Table[T]) Put(id uint32, x *T)

Put holds x under id, which another table handed out: never 0, below Max and not holding anything. It panics otherwise.

func (*Table[T]) Remove

func (t *Table[T]) Remove(id uint32)

Remove takes id back. It panics when id holds nothing.

Jump to

Keyboard shortcuts

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