stringset

package
v0.0.0-...-1643519 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: Apache-2.0 Imports: 0 Imported by: 46

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) 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) 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`).

`other` must have the same underlying type as the current set, or this will panic.

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

func (s Set) Intersect(other Set) Set

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

`other` must have the same underlying type as the current set, or this will panic.

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)

Peek removes and returns an arbitrary element 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) 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.

`other` must have the same underlying type as the current set, or this will panic.

Jump to

Keyboard shortcuts

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