hashedslice

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package hashedslice provides a content-addressed, append-only slice: adding a value equal to one added before returns the existing index instead of appending, so a value's index is stable for the life of the slice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Slice

type Slice[A any] struct {

	// Values holds the distinct values in insertion order; indices returned
	// by Add point into it. Hashes is parallel to Values and records each
	// value's original hash. Both are exported for read access and must not
	// be modified.
	Values []A
	Hashes []uint64
	// contains filtered or unexported fields
}

Slice is a content-addressed, append-only slice. Callers supply each value's hash; collisions are resolved by probing successive hash slots and confirming with the equality function, so hash quality affects performance, not correctness. Not safe for concurrent use.

func New

func New[A any](equal func(A, A) bool) *Slice[A]

New returns an empty Slice that uses equal to confirm matches when two values share a hash.

func (*Slice[A]) Add

func (h *Slice[A]) Add(hash uint64, v A) int32

Add returns the index of v, appending it if no equal value was added before. hash must be deterministic for v: equal values must supply equal hashes.

func (*Slice[A]) Grow

func (h *Slice[A]) Grow(size int)

Grow ensures capacity for size additional values.

func (*Slice[A]) Len

func (h *Slice[A]) Len() int

Len returns the number of distinct values added.

Jump to

Keyboard shortcuts

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