set

package
v0.0.3-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2021 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

package set implements a Set using a golang map. This implies that only the types that are accepted as valid map keys can be used as set elements. For instance, do not try to Add a slice, or the program will panic.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set interface {
	// Add: adds new element to the set
	Add(item interface{})
	// Delete: deletes the passed element from the set if present
	Delete(item interface{})
	// Len: gives the length of the set (total no. of elements in set)
	Len() int
	// GetItems: gives the array( []interface{} ) of elements of the set.
	GetItems() []interface{}
	// In: checks whether item is present in set or not.
	In(item interface{}) bool
	// IsSubsetOf: checks whether set is subset of set2 or not.
	IsSubsetOf(set2 Set) bool
	// IsSupersetOf: checks whether set is superset of set2 or not.
	IsSupersetOf(set2 Set) bool
	// Union: gives new union set of both sets.
	// ex: [1,2,3] union [3,4,5] -> [1,2,3,4,5]
	Union(set2 Set) Set
	// Intersection: gives new intersection set of both sets.
	// ex: [1,2,3] Intersection [3,4,5] -> [3]
	Intersection(set2 Set) Set
	// Difference: gives new difference set of both sets.
	// ex: [1,2,3] Difference [3,4,5] -> [1,2]
	Difference(set2 Set) Set
	// SymmetricDifference: gives new symmetric difference set of both sets.
	// ex: [1,2,3] SymmetricDifference [3,4,5] -> [1,2,4,5]
	SymmetricDifference(set2 Set) Set
}

Set is an interface of possible methods on 'set'.

Example
set := New(1, 2, 3)
fmt.Println(set.Len()) // 3
set.Add(3)
fmt.Println(set.Len()) // 3
set.Add(4)
fmt.Println(set.Len()) // 4
Output:

3
3
4

func New

func New(items ...interface{}) Set

New gives new set.

Jump to

Keyboard shortcuts

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