set

package
v1.1.0-beta.0...-c0b86a3 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateMapSize

func EstimateMapSize(length int, bucketSize uint64) uint64

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) Count

func (s Float64Set) Count() int

Count returns the number in Set s.

func (Float64Set) Exist

func (s Float64Set) Exist(val float64) bool

Exist checks whether `val` exists in `s`.

func (Float64Set) Insert

func (s Float64Set) Insert(val float64)

Insert inserts `val` into `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.

func NewInt64Set

func NewInt64Set(xs ...int64) Int64Set

NewInt64Set builds a Int64Set.

func (Int64Set) Count

func (s Int64Set) Count() int

Count returns the number in Set s.

func (Int64Set) Exist

func (s Int64Set) Exist(val int64) bool

Exist checks whether `val` exists in `s`.

func (Int64Set) Insert

func (s Int64Set) Insert(val int64)

Insert inserts `val` into `s`.

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 IntSet

type IntSet map[int]struct{}

IntSet is a int set.

func NewIntSet

func NewIntSet(is ...int) IntSet

NewIntSet builds a IntSet.

func (IntSet) Count

func (s IntSet) Count() int

Count returns the number in Set s.

func (IntSet) Exist

func (s IntSet) Exist(val int) bool

Exist checks whether `val` exists in `s`.

func (IntSet) Insert

func (s IntSet) Insert(val int)

Insert inserts `val` into `s`.

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 NewStringSet

func NewStringSet(ss ...string) StringSet

NewStringSet builds a string set.

func (StringSet) Clear

func (s StringSet) Clear()

Clear clears the set.

func (StringSet) Count

func (s StringSet) Count() int

Count returns the number in Set s.

func (StringSet) Empty

func (s StringSet) Empty() bool

Empty returns whether s is empty.

func (StringSet) Exist

func (s StringSet) Exist(val string) bool

Exist checks whether `val` exists in `s`.

func (StringSet) Insert

func (s StringSet) Insert(val string)

Insert inserts `val` into `s`.

func (StringSet) Intersection

func (s StringSet) Intersection(rhs StringSet) StringSet

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

Jump to

Keyboard shortcuts

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