stringset

package
v0.0.0-...-427ddc2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2017 License: MIT Imports: 1 Imported by: 0

README

Custom Set

Create a custom set type.

Sometimes it is necessary to define a custom data structure of some type, like a set. In this exercise you will define your own set. How it works internally doesn't matter, as long as it behaves like a set of unique elements.

Running the tests

To run the tests run the command go test from within the exercise directory.

If the test suite contains benchmarks, you can run these with the -bench flag:

go test -bench .

Keep in mind that each reviewer will run benchmarks on a different machine, with different specs, so the results from these benchmark tests may vary.

Further information

For more detailed information about the Go track, including how to get help if you're having trouble, please visit the exercism.io Go language page.

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Disjoint

func Disjoint(s1, s2 Set) bool

Disjoint returns true if s1 and s2 have no elements in common.

func Equal

func Equal(s1, s2 Set) bool

Equal returns true if s1 and s2 contain the same elements.

func Subset

func Subset(s1, s2 Set) bool

Subset returns true if all elements of s1 are also in s2.

Types

type Set

type Set map[string]bool

Set represents some properties of a mathematical set. Sets are finite and all elements are unique string values.

func Difference

func Difference(s1, s2 Set) Set

Difference returns a new Set populated with elements that appear in s1 but not in s2.

func Intersection

func Intersection(s1, s2 Set) Set

Intersection constructs a new Set populated with the elements common to both s1 and s2

func New

func New() Set

New constructs a new Set representing an empty set.

func NewFromSlice

func NewFromSlice(l []string) Set

NewFromSlice constructs a new Set populated from elements of a slice.

func Union

func Union(s1, s2 Set) Set

Union constructs a new Set populated with elements that appear in s1, s2, or both.

func (Set) Add

func (s Set) Add(e string)

Add adds element e to Set s. If e is already in s, s is unchanged.

func (Set) Has

func (s Set) Has(e string) bool

Has returns true if e is an element of s.

func (Set) IsEmpty

func (s Set) IsEmpty() bool

IsEmpty returns true if s represents the empty set.

func (Set) String

func (s Set) String() string

String returns a printable representation of s.

Jump to

Keyboard shortcuts

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