set

package
v1.1.0-beta.0...-d13e52e 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: 7 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 Key

type Key interface {
	Key() string
}

Key is the interface for the key of a set item.

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 Set

type Set[T Key] interface {
	Add(items ...T)
	Contains(item T) bool
	Remove(item T)
	ToList() []T
	Size() int
	Clone() Set[T]
	String() string
}

Set is the interface for a set.

func AndSet

func AndSet[T Key](ss ...Set[T]) Set[T]

AndSet returns the intersection set of the given sets.

func CombSet

func CombSet[T Key](s Set[T], numberOfItems int) []Set[T]

CombSet returns all combinations of `numberOfItems` items in the given set. For example ({a, b, c}, 2) returns {ab, ac, bc}.

func DiffSet

func DiffSet[T Key](s1, s2 Set[T]) Set[T]

DiffSet returns a set of items that are in s1 but not in s2. DiffSet({1, 2, 3, 4}, {2, 3}) = {1, 4}

func ListToSet

func ListToSet[T Key](items ...T) Set[T]

ListToSet converts a list to a set.

func NewSet

func NewSet[T Key]() Set[T]

NewSet creates a new set.

func UnionSet

func UnionSet[T Key](ss ...Set[T]) Set[T]

UnionSet returns the union set of the given sets.

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

func (StringSet) IntersectionWithLower

func (s StringSet) IntersectionWithLower(rhs StringSet, toLower bool) StringSet

IntersectionWithLower returns the intersection of two sets with different case of string.

func (StringSet) IterateWith

func (s StringSet) IterateWith(fn func(string))

IterateWith iterate items in StringSet and pass it to `fn`.

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