Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTableFull = errors.New("table is full, compaction required")
Functions ¶
func CapacityFromSize ¶
func CapacityFromSize[K comparable, V any](size uintptr) int
Estimates capacity (number of slots) from the given memory size in bytes.
func NextPowerOf2 ¶
Returns the next power of 2 for the given value `v`.
Types ¶
type HashFunc ¶
type HashFunc[K comparable] func(K) uint64
func MakeDefaultHashFunc ¶
func MakeDefaultHashFunc[K comparable](seed maphash.Seed) HashFunc[K]
type Option ¶
type Option[K comparable, V any] func(t *table[K, V])
func WithCompactionThresholdFactor ¶
func WithCompactionThresholdFactor[K comparable, V any](factor int) Option[K, V]
WithCompactionThresholdFactor sets the factor used to determine when compaction is needed. NeedsCompaction returns true when tombstones >= effectiveCapacity/factor. Default is 3 (compaction needed when tombstones reach 1/3 of effective capacity).
func WithHashFunc ¶
func WithHashFunc[K comparable, V any](f HashFunc[K]) Option[K, V]
WithHashFunc overrides the default hash function.
type StableMap ¶
type StableMap[K comparable, V any] struct { // contains filtered or unexported fields }
StableMap is a map-like data structure, which uses swiss-tables under the hood. It's stable, because it's designed to never grow up - it retains the capacity it was initialized with. This is especially helpful for a large sets in memory. Since we're going to use swiss table rehashing, it's not safe to iter over the set, and the iteration API is not provided.
StableMap is NOT safe for concurrent use. If multiple goroutines access a StableMap concurrently, and at least one of them modifies it, external synchronization is required.
func New ¶
func New[K comparable, V any](capacity int, opts ...Option[K, V]) *StableMap[K, V]
Returns a new instance of the stable map.
func (*StableMap) NeedsCompaction ¶
func (t *StableMap) NeedsCompaction() bool
NeedsCompaction returns true if the table has accumulated enough tombstones to warrant compaction. The threshold is when tombstones reach at least effectiveCapacity/factor, where factor defaults to 3 and can be configured via WithCompactionThresholdFactor.
type StableSet ¶
type StableSet[K comparable] struct { // contains filtered or unexported fields }
StableSet is a set-like data structure, which uses swiss-tables under the hood. It's stable, because it's designed to never grow up - it retains the capacity it was initialized with. This is especially helpful for a large sets in memory. StableSet is not designed as a fully compatible set structure, it's just doesn't store values, only keys. Since we're going to use swiss table rehashing, it's not safe to iter over the set, and the iteration API is not provided.
StableSet is NOT safe for concurrent use. If multiple goroutines access a StableSet concurrently, and at least one of them modifies it, external synchronization is required.
func NewSet ¶
func NewSet[K comparable](capacity int, opts ...Option[K, struct{}]) *StableSet[K]
Returns a new instance of the stable set.
func (*StableSet) NeedsCompaction ¶
func (t *StableSet) NeedsCompaction() bool
NeedsCompaction returns true if the table has accumulated enough tombstones to warrant compaction. The threshold is when tombstones reach at least effectiveCapacity/factor, where factor defaults to 3 and can be configured via WithCompactionThresholdFactor.