strset

package module
Version: v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2018 License: MIT Imports: 0 Imported by: 0

README

strset

Go library providing methods for string sets

GoDoc

	set := New()
        // add elements to the set
	set.Add("foo", "bar", "baz")
        // check if the set contains the string
	if set.Contains("bar") {
		fmt.Println("bar is here")
	}
        // remove string from the set
	set.Del("baz")
        // get all elements of the set as string slice
	elements := set.AsSlice()
	sort.Strings(elements)
	fmt.Println(elements)

Documentation

Overview

Package strset implements set functionality on top of map. It only supports sets of strings. Sets are not safe for concurrent use, just as maps on which they are based.

Example
set := New()
set.Add("foo", "bar", "baz")
if set.Contains("bar") {
	fmt.Println("bar is here")
}
set.Del("baz")
elements := set.AsSlice()
sort.Strings(elements)
fmt.Println(elements)
Output:

bar is here
[bar foo]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set map[string]struct{}

Set represents a set of string values

func New

func New(elem ...string) Set

New returns a new set, if arguments given, they are added to the set

func (Set) Add

func (s Set) Add(elem ...string)

Add adds new values to the set

func (Set) AsSlice

func (s Set) AsSlice() []string

AsSlice returns slice with all the values from the set. The order of values is not defined.

func (Set) Contains

func (s Set) Contains(elem string) bool

Contains returns true if the set contains the argument

func (Set) Del

func (s Set) Del(elem ...string)

Del removes specified values from the set

func (Set) Intersect

func (s Set) Intersect(t Set) Set

Intersect returns a new set that only contains values that are contained in both sets

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL