stringset

package
v0.0.0-...-51f9457 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package stringset is an exceedingly simple 'set' implementation for strings.

It's not threadsafe, but can be used in place of a simple `map[string]struct{}`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set map[string]struct{}

Set is the base type. make(Set) can be used too.

func New

func New(sizeHint int) Set

New returns a new string Set implementation.

func NewFromSlice

func NewFromSlice(vals ...string) Set

NewFromSlice returns a new string Set implementation, initialized with the values in the provided slice.

func (Set) Add

func (s Set) Add(value string) bool

Add ensures that Set contains value, and returns true if it was added (i.e. it returns false if the Set already contained the value).

func (Set) AddAll

func (s Set) AddAll(values []string)

AddAll ensures that Set contains all values.

func (Set) Contains

func (s Set) Contains(other Set) bool

Contains returns true iff the given set contains all elements from the other set.

func (Set) Del

func (s Set) Del(value string) bool

Del removes value from the set, and returns true if it was deleted (i.e. it returns false if the Set did not already contain the value).

func (Set) DelAll

func (s Set) DelAll(values []string)

DelAll ensures that Set contains none of values.

func (Set) Difference

func (s Set) Difference(other Set) Set

Difference returns a new Set which is this set with all elements from other removed (i.e. `self - other`).

func (Set) Dup

func (s Set) Dup() Set

Dup returns a duplicate set.

func (Set) Has

func (s Set) Has(value string) bool

Has returns true iff the Set contains value.

func (Set) HasAll

func (s Set) HasAll(values ...string) bool

HasAll returns true iff the Set contains all the given values.

func (Set) Intersect

func (s Set) Intersect(other Set) Set

Intersect returns a new Set which is the intersection of this set with the other set.

func (Set) Iter

func (s Set) Iter(cb func(string) bool)

Iter calls `cb` for each item in the set. If `cb` returns false, the iteration stops.

func (Set) Len

func (s Set) Len() int

Len returns the number of items in this set.

func (Set) Peek

func (s Set) Peek() (string, bool)

Peek returns an arbitrary element from the set. If the set was empty, this returns ("", false).

func (Set) Pop

func (s Set) Pop() (string, bool)

Pop removes and returns an arbitrary element from the set and removes it from the set. If the set was empty, this returns ("", false).

func (Set) ToSlice

func (s Set) ToSlice() []string

ToSlice renders this set to a slice of all values.

func (Set) ToSortedSlice

func (s Set) ToSortedSlice() []string

ToSortedSlice renders this set to a sorted slice of all values, ascending.

func (Set) Union

func (s Set) Union(other Set) Set

Union returns a new Set which contains all element from this set, as well as all elements from the other set.

Jump to

Keyboard shortcuts

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