Documentation
¶
Overview ¶
Package hashset holds the compact hash sets that the rules compiler uses for the long lists of an "in" term.
Both sets use open addressing with linear probing over a power of two table holding uint32 element indexes (index+1, so 0 means empty). The table is sized to between 1.5 and 3 slots per element (load factor 1/3 to 2/3), which keeps probe chains short while costing only 4-8 bytes per element.
uint32 offsets and indexes are safe because the constructors refuse to build a set when the element count or the total string bytes would not fit in a uint32; the caller then keeps the plain linear-scan list.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IntSet ¶
type IntSet struct {
// contains filtered or unexported fields
}
IntSet is a hash index over a long []int, which the caller keeps anyway. Slots come from Fibonacci hashing (multiply by 2^64/phi, keep the top bits).
type StrBuilder ¶
type StrBuilder struct {
// contains filtered or unexported fields
}
StrBuilder collects the elements of a StrSet. The zero value is not usable: start it with StrBuilder.Init.
func (*StrBuilder) Add ¶
func (builder *StrBuilder) Add(s string)
Add appends the next element. The elements must not be more than the count, nor longer in all than the total, that the builder was started with.
func (*StrBuilder) Build ¶
func (builder *StrBuilder) Build() *StrSet
Build returns the set of the elements added. The builder must not be used afterwards.
func (*StrBuilder) Init ¶
func (builder *StrBuilder) Init(count, total int) bool
Init starts the build of a set of count strings with total bytes in all. It returns false when the set would not fit 32 bit offsets: the caller keeps the plain list then. The builder must not be copied after Init.
type StrSet ¶
type StrSet struct {
// contains filtered or unexported fields
}
StrSet is a long string list stored in one allocation, plus an open addressing hash index over it. Compared with a []string and a map[string]struct{} it has no per-string allocation or header, and no map buckets: about 18 bytes per element for 8 byte strings instead of 75.
The string hash is maphash, a fast, well mixed hash. Every set draws its own random seed, so lookups cannot be steered into long probe chains by crafted keys; the seed is state of the set, not of the package.