pool

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package pool provides cross-cutting sync.Pool helpers, capacity-bucketed byte pools, and arena allocation for same-lifetime batches (DESIGN.md §10). Not yet implemented.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteIntMap

type ByteIntMap struct {
	// contains filtered or unexported fields
}

ByteIntMap is an open-addressing hash map from []byte keys to int values, using xxh3 for hashing and linear probing. It is designed for the dictionary-encoding hot path ([chunk.EncodeBytes]) where Go's built-in map[string]int is bottlenecked by string-key overhead and a slower hash function.

The zero value is not usable; create one with NewByteIntMap. [Reset] clears it for reuse without freeing the backing arrays (so a pooled instance amortizes allocation). Not safe for concurrent use; callers own synchronization or pool per-goroutine.

Capacity is rounded up to a power of two; the load factor is ≤ 0.75 (probed slots) before [grow] is triggered. Keys are compared with bytes.Equal (no string conversion).

func NewByteIntMap

func NewByteIntMap() *ByteIntMap

NewByteIntMap returns a pooled, ready-to-use map. A reused instance is cleared via ByteIntMap.Reset so its backing arrays are retained; a fresh one allocates at the initial capacity.

func (*ByteIntMap) Delete

func (m *ByteIntMap) Delete(b []byte) bool

Delete removes key b. Returns true if it was present.

func (*ByteIntMap) ForEach

func (m *ByteIntMap) ForEach(fn func(key []byte, value int))

ForEach calls fn for each (key, value) pair. Iteration order is unspecified.

func (*ByteIntMap) Get

func (m *ByteIntMap) Get(b []byte) (int, bool)

Get returns the value for key b and true if present.

func (*ByteIntMap) Len

func (m *ByteIntMap) Len() int

Len returns the number of live entries in the map.

func (*ByteIntMap) Put

func (m *ByteIntMap) Put(b []byte, v int) (int, bool)

Put inserts or updates key b → v. Returns the old value and true if the key existed, or (v, false) for a new insertion.

func (*ByteIntMap) PutBack

func (m *ByteIntMap) PutBack()

PutBack returns m to the pool for reuse. After this, m must not be used.

func (*ByteIntMap) PutOrGet

func (m *ByteIntMap) PutOrGet(b []byte, v int) (int, bool)

PutOrGet inserts b → v if b is absent; otherwise returns the existing value and false. This is the single-lookup dedup path for dictionary building: one probe chain either finds the existing id or inserts a new one.

func (*ByteIntMap) PutRaw

func (m *ByteIntMap) PutRaw(b []byte, v int, h uint64)

PutRaw inserts with a precomputed hash (internal, for re-insertion after Delete).

func (*ByteIntMap) Reset

func (m *ByteIntMap) Reset()

Reset clears the map for reuse without freeing the backing arrays.

Jump to

Keyboard shortcuts

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