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 ¶
New returns an empty Slice that uses equal to confirm matches when two values share a hash.
func (*Slice[A]) Add ¶
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.