bag

package
v1.10.15-rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: BSD-3-Clause Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bag

type Bag[T comparable] struct {
	// contains filtered or unexported fields
}

Bag is a multiset.

func Of added in v1.10.10

func Of[T comparable](elts ...T) Bag[T]

Of returns a Bag initialized with [elts]

func (*Bag[T]) Add

func (b *Bag[T]) Add(elts ...T)

Add increases the number of times each element has been seen by one.

func (*Bag[T]) AddCount

func (b *Bag[T]) AddCount(elt T, count int)

AddCount increases the number of times the element has been seen by [count]. If [count] <= 0 this is a no-op.

func (*Bag[T]) Count

func (b *Bag[T]) Count(elt T) int

Count returns the number of [elt] in the bag.

func (*Bag[T]) Equals

func (b *Bag[T]) Equals(other Bag[T]) bool

Equals returns true if the bags contain the same elements

func (*Bag[T]) Filter

func (b *Bag[T]) Filter(filterFunc func(T) bool) Bag[T]

Returns a bag with the elements of this bag that return true for [filterFunc], along with their counts. For example, if X is in this bag with count 5, and filterFunc(X) returns true, then the returned bag contains X with count 5.

func (*Bag[_]) Len

func (b *Bag[_]) Len() int

Len returns the number of elements in the bag.

func (*Bag[T]) List

func (b *Bag[T]) List() []T

List returns a list of unique elements that have been added. The returned list doesn't have duplicates.

func (*Bag[T]) Mode

func (b *Bag[T]) Mode() (T, int)

Mode returns the most common element in the bag and the count of that element. If there's a tie, any of the tied element may be returned.

func (*Bag[T]) PrefixedString

func (b *Bag[T]) PrefixedString(prefix string) string

func (*Bag[T]) Remove

func (b *Bag[T]) Remove(elt T)

Remove all instances of [elt] from the bag.

func (*Bag[_]) SetThreshold

func (b *Bag[_]) SetThreshold(threshold int)

SetThreshold sets the number of times an element must be added to be contained in the threshold set.

func (*Bag[T]) Split

func (b *Bag[T]) Split(splitFunc func(T) bool) [2]Bag[T]

Returns: 1. A bag containing the elements of this bag that return false for [splitFunc]. 2. A bag containing the elements of this bag that return true for [splitFunc]. Counts are preserved in the returned bags. For example, if X is in this bag with count 5, and splitFunc(X) is false, then the first returned bag has X in it with count 5.

func (*Bag[_]) String

func (b *Bag[_]) String() string

func (*Bag[T]) Threshold

func (b *Bag[T]) Threshold() set.Set[T]

Threshold returns the elements that have been seen at least threshold times.

type UniqueBag

type UniqueBag[T comparable] map[T]set.Bits64

Maps a key to a bitset.

func (*UniqueBag[T]) Add

func (b *UniqueBag[T]) Add(n uint, keys ...T)

Adds [n] to the bitset associated with each key in [keys].

func (*UniqueBag[T]) Bag

func (b *UniqueBag[T]) Bag(threshold int) Bag[T]

Returns a bag with the given [threshold] where each key is in the bag once for each element in the key's bitset.

func (*UniqueBag[_]) Clear

func (b *UniqueBag[_]) Clear()

Removes all key --> bitset pairs.

func (*UniqueBag[T]) Difference

func (b *UniqueBag[T]) Difference(diff *UniqueBag[T])

For each key/bitset pair in [diff], removes each element of the bitset from the bitset associated with the key in [b]. Keys in [diff] that are not in [b] are ignored. Bitset elements in [diff] that are not in the bitset associated with the key in [b] are ignored.

func (*UniqueBag[T]) DifferenceSet

func (b *UniqueBag[T]) DifferenceSet(key T, set set.Bits64)

Removes each element of set from the bitset associated with [key].

func (*UniqueBag[T]) GetSet

func (b *UniqueBag[T]) GetSet(key T) set.Bits64

Returns the bitset associated with [key].

func (*UniqueBag[T]) List

func (b *UniqueBag[T]) List() []T

Returns the keys.

func (*UniqueBag[T]) PrefixedString

func (b *UniqueBag[T]) PrefixedString(prefix string) string

func (*UniqueBag[T]) RemoveSet

func (b *UniqueBag[T]) RemoveSet(key T)

Removes the bitset associated with [key].

func (*UniqueBag[_]) String

func (b *UniqueBag[_]) String() string

func (*UniqueBag[T]) UnionSet

func (b *UniqueBag[T]) UnionSet(key T, set set.Bits64)

Unions set with the bitset associated with [key].

Jump to

Keyboard shortcuts

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