set

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2022 License: Unlicense Imports: 0 Imported by: 0

README

golang sets

Implementing sets in golang...

Sets are useful when implementing filtering. This is usually done by the intersection of a selection set and a target object. The intersection only returns the attributes of the target object specified in the selection set.

Using the sets clas from python3 as an example:

# Filter a list
object = ["a1", "a3"]
selected = set("a1", "a2").intersection(object)

returns 
    {"a1"}

# Filter a map:
object = {"a1":"value1", "a3":"value3"}
for f in selected = set("a1", "a2").intersection(object):
    m[f] = object[f]

The opposite case is redact all fields that are not selected:

selector = {"a1", "a2"}
object = {"a1":"value1", "a3":"value3"}
for f in deselected = set(object).difference(selector):
    object[f] = "redacted"

See sets.py for full list of examples.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StringSet

type StringSet map[string]struct{}

func NewStringSet

func NewStringSet(values ...string) StringSet

NewStringSet creates a new string set with optional input values.

func NewStringSetFromMap

func NewStringSetFromMap(values map[string]string) StringSet

NewStringSetFromMap creates a new string set from a map.

func (StringSet) Add

func (s StringSet) Add(values ...string)

Add adds one or more values to string set.

func (StringSet) Contains

func (s StringSet) Contains(value string) bool

Contains returns true if item is present in the string set.

func (StringSet) Difference

func (s StringSet) Difference(other StringSet) StringSet

Difference returns string set that consists of items that are in set and and not in second set.

func (StringSet) DifferenceList

func (s StringSet) DifferenceList(values ...string) StringSet

DifferenceList returns string set that consists of items that are in set and and not in list.

func (StringSet) DifferenceMap

func (s StringSet) DifferenceMap(values map[string]string) StringSet

DifferenceMap returns string set that consists of items that are in set and and not in map.

func (StringSet) Intersection

func (s StringSet) Intersection(other StringSet) StringSet

Intersection returns string set that consists of items that are in both sets.

func (StringSet) IntersectionList

func (s StringSet) IntersectionList(values ...string) StringSet

IntersectonList returns string set that consists of items that are in both set and list.

func (StringSet) IntersectionMap

func (s StringSet) IntersectionMap(values map[string]string) StringSet

IntersectonMap returns string set that consists of items that are in both set and map.

func (StringSet) List

func (s StringSet) List() []string

List returns the string set as the original array.

func (StringSet) Remove

func (s StringSet) Remove(values ...string)

Remove removes items from a strng set.

func (StringSet) SymmetricDifference

func (s StringSet) SymmetricDifference(other StringSet) StringSet

SymmetricDifference returns string set that consists of items that are not in both sets.

func (StringSet) SymmetricDifferenceList

func (s StringSet) SymmetricDifferenceList(values ...string) StringSet

SymmetricDifferenceList returns string set that consists of items that are not in set and list.

func (StringSet) SymmetricDifferenceMap

func (s StringSet) SymmetricDifferenceMap(values map[string]string) StringSet

SymmetricDifferenceMap returns string set that consists of items that are not in set and map.

func (StringSet) Union

func (s StringSet) Union(other StringSet) StringSet

Union returns string set that consists of items that are in either of the 2 sets.

func (StringSet) UnionList

func (s StringSet) UnionList(values ...string) StringSet

UnionList returns string set that consists of items that are in either the set or the list.

func (StringSet) UnionMap

func (s StringSet) UnionMap(values map[string]string) StringSet

UnionMap returns string set that consists of items that are in either the set or the map.

Jump to

Keyboard shortcuts

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