swiss

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 4 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 swiss is the open-addressed table behind the module's hash maps: groups of eight slots, each with one control byte holding seven bits of the hash, probed a group at a time with word-at-a-time comparisons. It needs no stored hash and reaches a 7/8 load, so it costs one byte per slot.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Table

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

Table is an open-addressed table of slots. It is not safe for concurrent use. Pointers into it are valid until the next call that may grow or shrink it.

func New

func New[S any](a memory.Allocator, capacity int, hash func(*S) uint64) (*Table[S], error)

New returns an empty Table with room for capacity entries. hash must return the hash the slot was inserted under.

func (*Table[S]) All

func (t *Table[S]) All(who string, yield func(*S) bool)

All calls yield with every slot until it returns false. A change to the set of entries during the loop panics, reporting who as the modified container.

func (*Table[S]) Clip

func (t *Table[S]) Clip() error

Clip shrinks the table to the smallest size that holds the current entries.

func (*Table[S]) Find

func (t *Table[S]) Find(h uint64, eq func(*S) bool) *S

Find returns the slot under hash h for which eq reports true, or nil.

func (*Table[S]) Free

func (t *Table[S]) Free() error

Free releases the table. t must not be used afterwards.

func (*Table[S]) Insert

func (t *Table[S]) Insert(h uint64) (*S, error)

Insert returns a slot to fill for hash h, whose key must be absent.

func (*Table[S]) Len

func (t *Table[S]) Len() int

Len returns the number of entries.

func (*Table[S]) Remove

func (t *Table[S]) Remove(h uint64, eq func(*S) bool) (S, bool)

Remove deletes the slot under hash h for which eq reports true and returns it, or reports false.

func (*Table[S]) Touch

func (t *Table[S]) Touch(h uint64) uint64

Touch loads the group hash h probes first and returns its control word. Loads from several Touch calls run in parallel on an out-of-order core, so touching a batch before searching it turns serial cache misses into overlapping ones.

Jump to

Keyboard shortcuts

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