Documentation
¶
Overview ¶
Package sets contains set operations like union, intersection, and difference.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶ added in v0.2.0
type Map[T comparable] map[T]struct{}
Map implements sets.Set for map[T]struct{}.
func (Map[T]) IterateInternal ¶ added in v0.5.1
type Set ¶
type Set[T any] interface { Add(item T) Remove(item T) Contains(item T) bool Len() int Iterate() iterator.Iterator[T] }
Set is a minimal interface to a set. It is implemented by sets.Map and container/tree.Set, among others.
func Difference ¶
func Difference[T comparable](out, a, b Set[T]) Set[T]
Difference adds to out all items that appear in a but not in b and returns out.
Example ¶
package main
import (
"fmt"
"github.com/bradenaw/juniper/sets"
)
func main() {
a := sets.Map[int]{
1: {},
4: {},
5: {},
}
b := sets.Map[int]{
3: {},
4: {},
}
out := make(sets.Map[int])
difference := sets.Difference[int](out, a, b)
fmt.Println(difference)
}
Output: map[1:{} 5:{}]
func Intersection ¶
func Intersection[T comparable](out Set[T], sets ...Set[T]) Set[T]
Intersection adds to out all items that appear in all sets and returns out.
Example ¶
package main
import (
"fmt"
"github.com/bradenaw/juniper/sets"
)
func main() {
a := sets.Map[int]{
1: {},
2: {},
4: {},
}
b := sets.Map[int]{
1: {},
3: {},
4: {},
}
c := sets.Map[int]{
1: {},
4: {},
5: {},
}
out := make(sets.Map[int])
intersection := sets.Intersection[int](out, a, b, c)
fmt.Println(intersection)
}
Output: map[1:{} 4:{}]
func Union ¶
Union adds to out out all items from sets and returns out.
Example ¶
package main
import (
"fmt"
"github.com/bradenaw/juniper/sets"
)
func main() {
a := sets.Map[int]{
1: {},
4: {},
}
b := sets.Map[int]{
3: {},
4: {},
}
c := sets.Map[int]{
1: {},
5: {},
}
out := make(sets.Map[int])
union := sets.Union[int](out, a, b, c)
fmt.Println(union)
}
Output: map[1:{} 3:{} 4:{} 5:{}]
Click to show internal directories.
Click to hide internal directories.