set

package module
Version: v0.0.0-...-5a86b41 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2016 License: MIT Imports: 2 Imported by: 0

README

Set

Go interface and implementations of a set data structure

Install

go get github.com/nikovacevic/set.go

Import

import "github.com/nikovacevic/set.go"

Interface

Add(e interface{}) bool

Remove(e interface{}) bool

Size() int

Clear() bool

Contains(e interface{}) bool

Equals(s Set) bool

IsSubsetOf(s Set) bool

Union(s Set) Set

Intersection(s Set) Set

Difference(s Set) Set

Implementations

MapSet

Leverages built in map type with interface{} keys and struct{} zero-width values.

SliceSet

Coming soon!

Acknowlegments

This package draws ideas from the following community writing and examples:

NOTE Currently, the implemented MapSet is not threadsafe. Once again, see other community implementations for examples.

License

The MIT License (MIT)
Copyright (c) 2016 Niko Kovacevic

Documentation

Overview

Package set provides an interface and implementations for the set data structure

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapSet

type MapSet map[interface{}]struct{}

MapSet implements Set. Elements of the set are represented as keys of the map. Hence, the key is of type interface{} to allow any type to be added to the set. The value of the map is type struct{} because it has zero width.

func NewMapSet

func NewMapSet() *MapSet

NewMapSet creates and returns a pointer to a new MapSet instance

func (*MapSet) Add

func (ms *MapSet) Add(e interface{}) bool

Add adds e elements to the Set returns true if the element was added to the set returns false if the set already contained the element e

func (*MapSet) Channel

func (ms *MapSet) Channel() <-chan interface{}

Channel communicates each element of the set exactly once on the given channel, then closes the channel

func (*MapSet) Clear

func (ms *MapSet) Clear() bool

Clear removes all elements from the set returns true if all elements were removed returns false if the set was empty

func (*MapSet) Contains

func (ms *MapSet) Contains(e interface{}) bool

Contains returns true if the set contains the element e

func (*MapSet) Difference

func (ms *MapSet) Difference(s Set) Set

Difference returns the set of elements in either the set or the set s, but not in both

func (*MapSet) Equals

func (ms *MapSet) Equals(s Set) bool

Equals returns true if the set contains all elements in set s and the two sets are of equal size

func (*MapSet) Intersection

func (ms *MapSet) Intersection(s Set) Set

Intersection returns the set of elements in both the set and the set s

func (*MapSet) IsSubsetOf

func (ms *MapSet) IsSubsetOf(s Set) bool

IsSubsetOf returns true if the set s contains all elements in the set

func (*MapSet) Remove

func (ms *MapSet) Remove(e interface{}) bool

Remove removes element e from the Set returns true if the element was removed from the set returns false if the set did not contain the element e

func (*MapSet) Size

func (ms *MapSet) Size() int

Size returns the number of elements in the set

func (*MapSet) Slice

func (ms *MapSet) Slice() []interface{}

Slice returns a slice containing each element of the set exactly once

func (*MapSet) String

func (ms *MapSet) String() string

String returns a string representation of the set

func (*MapSet) Union

func (ms *MapSet) Union(s Set) Set

Union returns the set of elements in either or both of the set and set s

type Set

type Set interface {
	// Adds element e to the Set
	// returns true if the element was added to the set
	// returns false if the set already contained the element e
	Add(e interface{}) bool
	// Removes element e from the Set
	// returns true if the element was removed from the set
	// returns false if the set did not contain the element e
	Remove(e interface{}) bool
	// Returns the number of elements in the set
	Size() int
	// Removes all elements from the set
	// returns true if all elements were removed
	// returns false if the set was empty
	Clear() bool
	// Returns true if the set contains the element e
	Contains(e interface{}) bool
	// Returns true if the set contains all elements in set s and the two
	// sets are of equal size
	Equals(s Set) bool
	// Returns true if the set s contains all elements in the set
	IsSubsetOf(s Set) bool
	// Returns the set of elements in either or both of the set and set s
	Union(s Set) Set
	// Returns the set of elements in both the set and the set s
	Intersection(s Set) Set
	// Returns the set of elements in either the set or the set s, but not in both
	Difference(s Set) Set
}

Set describes a collection of distinct elements

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