Documentation
¶
Index ¶
- type Set
- func (s Set[T]) Add(v ...T) Set[T]
- func (s Set[T]) Clear() Set[T]
- func (s Set[T]) Clone() Set[T]
- func (s Set[T]) Delete(v ...T) Set[T]
- func (s Set[T]) Equal(t Set[T]) bool
- func (s Set[T]) Has(v T) bool
- func (s Set[T]) Intersection(x, y Set[T]) Set[T]
- func (s Set[T]) IntersectionWith(t Set[T]) Set[T]
- func (s Set[T]) Intersects(t Set[T]) bool
- func (s Set[T]) Len() int
- func (s Set[T]) Slice() []T
- func (s Set[T]) Union(x, y Set[T]) Set[T]
- func (s Set[T]) UnionWith(t Set[T]) Set[T]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T constraints.Ordered] []T
Set represents a slice of unique items.
Example ¶
package main
import (
"fmt"
"github.com/bsm/sortedset"
)
func main() {
// Create a new set
set := sortedset.New[string]()
// Seed with data
set = set.Add("b")
set = set.Add("a")
set = set.Add("c", "a")
fmt.Println(set.Slice()) // [a b c]
// Check
fmt.Println(set.Has("a")) // true
fmt.Println(set.Has("d")) // false
// Delete items
set = set.Delete("a")
set = set.Delete("d")
fmt.Println(set.Slice()) // [b c]
}
Output: [a b c] true false [b c]
func (Set[T]) Intersection ¶
Intersection adds the intersection x ∩ y to s and returns the result.
func (Set[T]) IntersectionWith ¶
IntersectionWith sets s to the insersection of s ∪ t, and returns the result.
func (Set[T]) Intersects ¶
Intersects reports whether s ∩ t ≠ ∅.
Click to show internal directories.
Click to hide internal directories.