Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EstimateMapSize ¶
EstimateMapSize returns the estimated size of the map. It doesn't include the dynamic part, e.g. objects pointed to by pointers in the map. len(map) <= load_factor * 2^bInMap. bInMap = ceil(log2(len(map)/load_factor)). memory = bucketSize * 2^bInMap
Types ¶
type Float64Set ¶
type Float64Set map[float64]struct{}
Float64Set is a float64 set.
func NewFloat64Set ¶
func NewFloat64Set(fs ...float64) Float64Set
NewFloat64Set builds a float64 set.
func (Float64Set) Exist ¶
func (s Float64Set) Exist(val float64) bool
Exist checks whether `val` exists in `s`.
type Float64SetWithMemoryUsage ¶
type Float64SetWithMemoryUsage struct { Float64Set // contains filtered or unexported fields }
Float64SetWithMemoryUsage is a float64 set with memory usage.
func NewFloat64SetWithMemoryUsage ¶
func NewFloat64SetWithMemoryUsage(ss ...float64) (setWithMemoryUsage Float64SetWithMemoryUsage, memDelta int64)
NewFloat64SetWithMemoryUsage builds a float64 set.
func (*Float64SetWithMemoryUsage) Insert ¶
func (s *Float64SetWithMemoryUsage) Insert(val float64) (memDelta int64)
Insert inserts `val` into `s` and return memDelta.
type Int64Set ¶
type Int64Set map[int64]struct{}
Int64Set is a int64 set.
type Int64SetWithMemoryUsage ¶
type Int64SetWithMemoryUsage struct { Int64Set // contains filtered or unexported fields }
Int64SetWithMemoryUsage is a int set with memory usage.
func NewInt64SetWithMemoryUsage ¶
func NewInt64SetWithMemoryUsage(ss ...int64) (setWithMemoryUsage Int64SetWithMemoryUsage, memDelta int64)
NewInt64SetWithMemoryUsage builds an int64 set.
func (*Int64SetWithMemoryUsage) Insert ¶
func (s *Int64SetWithMemoryUsage) Insert(val int64) (memDelta int64)
Insert inserts `val` into `s` and return memDelta.
type MemAwareMap ¶
type MemAwareMap[K comparable, V any] struct { M map[K]V // it's public, when callers want to directly access it, e.g. use in a for-range-loop // contains filtered or unexported fields }
MemAwareMap is a map which is aware of its memory usage. It's adapted from SetWithMemoryUsage. It doesn't support delete. The estimate usage of memory is usually smaller than the real usage. According to experiments with SetWithMemoryUsage, 2/3 * estimated usage <= real usage <= estimated usage.
func NewMemAwareMap ¶
func NewMemAwareMap[K comparable, V any]() MemAwareMap[K, V]
NewMemAwareMap creates a new MemAwareMap.
func (*MemAwareMap[K, V]) Get ¶
func (m *MemAwareMap[K, V]) Get(k K) (v V, ok bool)
Get the value of the key.
func (*MemAwareMap[K, V]) Len ¶
func (m *MemAwareMap[K, V]) Len() int
Len returns the number of elements in the map.
func (*MemAwareMap[K, V]) Set ¶
func (m *MemAwareMap[K, V]) Set(k K, v V) (memDelta int64)
Set the value of the key.
type StringSet ¶
type StringSet map[string]struct{}
StringSet is a string set.
func (StringSet) Intersection ¶
Intersection returns the intersection of two sets
type StringSetWithMemoryUsage ¶
type StringSetWithMemoryUsage struct { StringSet // contains filtered or unexported fields }
StringSetWithMemoryUsage is a string set with memory usage.
func NewStringSetWithMemoryUsage ¶
func NewStringSetWithMemoryUsage(ss ...string) (setWithMemoryUsage StringSetWithMemoryUsage, memDelta int64)
NewStringSetWithMemoryUsage builds a string set.
func (*StringSetWithMemoryUsage) Insert ¶
func (s *StringSetWithMemoryUsage) Insert(val string) (memDelta int64)
Insert inserts `val` into `s` and return memDelta.
func (*StringSetWithMemoryUsage) SetTracker ¶
func (s *StringSetWithMemoryUsage) SetTracker(t *memory.Tracker)
SetTracker sets memory tracker for StringSetWithMemoryUsage