stringset

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: Apache-2.0 Imports: 1 Imported by: 24

Documentation

Overview

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(s1 Set, s2 Set) bool

Equal returns whether s1 and s2 contain the same elements.

Types

type Set

type Set map[string]struct{}

Set is a nifty little wrapper for common set operations on a map. Because it is equivalent to a map, make/range/len will still work with Set.

func FromSlice

func FromSlice(xs []string) Set

FromSlice converts a slice of strings into a Set.

func New

func New(xs ...string) Set

New creates a new Set with xs.

func (Set) Add

func (s Set) Add(x string)

Add adds x to s.

func (Set) Copy

func (s Set) Copy() Set

Copy returns a copy of s.

func (Set) Has

func (s Set) Has(x string) bool

Has returns true if x is in s.

func (Set) Random

func (s Set) Random() (string, error)

Random returns a random element in s. Returns error if s is empty.

func (Set) Remove

func (s Set) Remove(x string)

Remove removes x from s.

func (Set) Sample

func (s Set) Sample(n int) Set

Sample samples n random elements from s. If there are <= n elements in s, returns the whole set.

func (Set) Sub

func (s Set) Sub(s2 Set) Set

Sub returns a new set which is the result of s minus s2.

func (Set) ToSlice

func (s Set) ToSlice() []string

ToSlice converts s to a slice.

Jump to

Keyboard shortcuts

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