set

package
v0.0.0-...-a161123 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FrozenStringSet

type FrozenStringSet struct {
	// contains filtered or unexported fields
}

A FrozenStringSet is a frozen set of string elements, which cannot be modified after creation. This allows users to use it as if it were a "const" data structure, and also makes it slightly more optimal since we don't have to lock accesses to it.

func NewFrozenStringSet

func NewFrozenStringSet(elements ...string) FrozenStringSet

NewFrozenStringSet returns a new frozen set with the provided elements.

func NewFrozenStringSetFromMap

func NewFrozenStringSetFromMap(m map[string]struct{}) FrozenStringSet

NewFrozenStringSetFromMap returns a new frozen set from the set-style map.

func (FrozenStringSet) AsSlice

func (k FrozenStringSet) AsSlice() []string

AsSlice returns the elements of the set. The order is unspecified.

func (FrozenStringSet) AsSortedSlice

func (k FrozenStringSet) AsSortedSlice(less func(i, j string) bool) []string

AsSortedSlice returns the elements of the set as a sorted slice.

func (FrozenStringSet) Cardinality

func (k FrozenStringSet) Cardinality() int

Cardinality returns the cardinality of the set.

func (FrozenStringSet) Contains

func (k FrozenStringSet) Contains(elem string) bool

Contains returns whether the set contains the element.

func (FrozenStringSet) Difference

func (k FrozenStringSet) Difference(other FrozenStringSet) FrozenStringSet

Difference returns a frozen set that represents the set difference between this and other.

func (FrozenStringSet) ElementsString

func (k FrozenStringSet) ElementsString(sep string) string

ElementsString returns a string representation of all elements, with individual element strings separated by `sep`. The string representation of an individual element is obtained via `fmt.Fprint`.

func (FrozenStringSet) Intersect

func (k FrozenStringSet) Intersect(other FrozenStringSet) FrozenStringSet

Intersect returns a frozen set that represents the intersection between this and other.

func (FrozenStringSet) IsEmpty

func (k FrozenStringSet) IsEmpty() bool

IsEmpty returns whether the underlying set is empty (includes uninitialized).

func (FrozenStringSet) Unfreeze

func (k FrozenStringSet) Unfreeze() StringSet

Unfreeze returns a mutable set with the same contents as this frozen set. This set will not be affected by any subsequent modifications to the returned set.

func (FrozenStringSet) Union

Union returns a frozen set that represents the union between this and other.

type StringSet

type StringSet map[string]struct{}

StringSet will get translated to generic sets.

func NewStringSet

func NewStringSet(initial ...string) StringSet

NewStringSet returns a new thread unsafe set with the given key type.

func (*StringSet) Add

func (k *StringSet) Add(i string) bool

Add adds an element of type string.

func (*StringSet) AddAll

func (k *StringSet) AddAll(is ...string) bool

AddAll adds all elements of type string. The return value is true if any new element was added.

func (*StringSet) AddMatching

func (k *StringSet) AddMatching(matchFunc func(string) bool, elems ...string) bool

AddMatching is a utility function that adds all the elements that match the given function to the set.

func (StringSet) AsSlice

func (k StringSet) AsSlice() []string

AsSlice returns a slice of the elements in the set. The order is unspecified.

func (StringSet) AsSortedSlice

func (k StringSet) AsSortedSlice(less func(i, j string) bool) []string

AsSortedSlice returns a slice of the elements in the set, sorted using the passed less function.

func (StringSet) Cardinality

func (k StringSet) Cardinality() int

Cardinality returns the number of elements in the set.

func (*StringSet) Clear

func (k *StringSet) Clear()

Clear empties the set

func (StringSet) Clone

func (k StringSet) Clone() StringSet

Clone returns a copy of this set.

func (StringSet) Contains

func (k StringSet) Contains(i string) bool

Contains returns whether the set contains an element of type string.

func (StringSet) Difference

func (k StringSet) Difference(other StringSet) StringSet

Difference returns a new set with all elements of k not in other.

func (StringSet) ElementsString

func (k StringSet) ElementsString(sep string) string

ElementsString returns a string representation of all elements, with individual element strings separated by `sep`. The string representation of an individual element is obtained via `fmt.Fprint`.

func (StringSet) Equal

func (k StringSet) Equal(other StringSet) bool

Equal returns a bool if the sets are equal

func (StringSet) Freeze

func (k StringSet) Freeze() FrozenStringSet

Freeze returns a new, frozen version of the set.

func (StringSet) GetArbitraryElem

func (k StringSet) GetArbitraryElem() (arbitraryElem string)

GetArbitraryElem returns an arbitrary element from the set. This can be useful if, for example, you know the set has exactly one element, and you want to pull it out. If the set is empty, the zero value is returned.

func (StringSet) Intersect

func (k StringSet) Intersect(other StringSet) StringSet

Intersect returns a new set with the intersection of the members of both sets.

func (StringSet) Intersects

func (k StringSet) Intersects(other StringSet) bool

Intersects returns whether the set has a non-empty intersection with the other set.

func (StringSet) IsEmpty

func (k StringSet) IsEmpty() bool

IsEmpty returns whether the underlying set is empty (includes uninitialized).

func (*StringSet) Remove

func (k *StringSet) Remove(i string) bool

Remove removes an element of type string.

func (*StringSet) RemoveAll

func (k *StringSet) RemoveAll(is ...string) bool

RemoveAll removes the given elements.

func (*StringSet) RemoveMatching

func (k *StringSet) RemoveMatching(pred func(string) bool) bool

RemoveMatching removes all elements that match a given predicate.

func (StringSet) Union

func (k StringSet) Union(other StringSet) StringSet

Union returns a new set with the union of the members of both sets.

Jump to

Keyboard shortcuts

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