package flatset
Import Path
github.com/freeeve/gochickpeas/flatset (on go.dev)
Dependency Relation
imports one package, and imported by 2 packages
Involved Source Files
Package flatset provides flat open-addressing sets and maps for the
dedup/membership/grouping structures that dominate allocation-heavy
inner loops. Go's built-in map allocates a bucket array per doubling
plus overflow buckets as it fills, and map[K]struct{} insert forces
per-key work the flat probe tables avoid: every structure here costs
exactly one slice allocation per doubling. Shared by the gql executor's
aggregation path and the native benchmark kernels.
Byte-keyed flat structures: a dedup set and a value-carrying map over
[]byte keys that intern into one growable arena probed by an
open-addressing (offset, length) table -- N distinct keys cost O(log N)
arena and table growths rather than N heap strings (the per-insert
string allocation of map[string]... that these replace). Split from
flatset.go, which holds the integer-keyed twins.
Package-Level Type Names (total 6)
ByteMap is the value-carrying twin of ByteSet: a byte key maps to an
int through the same interned arena, so a group-by over a string key
pays O(log N) growths across N distinct groups instead of one heap
string per new group.
Get returns the int mapped to b; ok is false when absent.
GetOrCreate returns the int mapped to b, calling create to mint it on
first sight (create must not touch this map). b's backing may be reused
immediately after (the bytes are copied).
Len is the number of distinct keys mapped.
ByteSet is a dedup set over byte keys that avoids the per-insert string
allocation of map[string]struct{}: keys append into one growable arena
probed through an open-addressing table keyed on (offset, length), so N
distinct keys cost O(log N) arena and table growths rather than N heap
strings. The first few short keys store inline (a per-group DISTINCT
set usually holds a handful), spilling into the table form on overflow
with identical semantics.
Add reports whether b is newly seen, copying it into the inline store or
the arena on first sight. The caller may reuse b's backing immediately
after (the bytes are copied, never aliased).
Len is the number of distinct keys added.
Recycle is a slot-array free list keyed by size class, shared by many
U32Sets within ONE single-threaded execution (no locking). Arrays are
zeroed on reuse (the same memclr a fresh make pays), so the saving is
purely the allocation and its GC/scavenger shadow.
U32Set is an open-addressing set of uint32 ids. Slots store id+1 so
zero marks empty -- an id of ^uint32(0) cannot occur for array-indexed
ids (node ids, CSR positions).
Rec, when set, recycles slot arrays across the sets sharing it:
grow returns the outgrown array to the pool and draws replacements
from it. Many same-shaped sets climbing the growth ladder together
(one DISTINCT set per aggregation group) then churn roughly one
array per rung instead of one per set per rung -- the discarded
doublings otherwise dominate the aggregation's allocation profile.
Add reports whether id is newly seen (and records it).
Built reports whether the probe table has been materialized (any Add
ran) -- callers layering their own inline fast path ahead of the set
key their spill decision on it.
Has reports whether id was added.
Len is the number of distinct ids added.
Reset empties the set keeping its slot backing, so a reused set's next
fill allocates nothing until it outgrows its high-water size.
U64Map maps uint64 keys to an int index through an open-addressing
probe table. Slots carry an explicit used flag, so every key value is
valid.
ForEach visits every (key, index) pair in table order. The visit
function must not mutate the map.
Get returns the index mapped to key; ok is false when absent.
GetOrCreate returns the index mapped to key, calling create to mint it
on first sight (create must not touch this map).
Len is the number of distinct keys mapped.
Reset empties the map keeping its table backing, so a reused map's
next fill allocates nothing until it outgrows its high-water size.
U64Set is an open-addressing set of uint64 keys -- the packed-pair
membership set (e.g. person<<32|forum). Slots store key+1 so zero marks
empty; the all-ones key cannot occur for packed array-indexed ids.
Add reports whether key is newly seen (and records it).
Has reports whether key was added.
Len is the number of distinct keys added.
Reset empties the set keeping its slot backing, so a reused set's next
fill allocates nothing until it outgrows its high-water size.
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |