Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"alon.kr/x/set"
)
func main() {
s := set.New[int]()
s.Add(1)
s.Add(2)
s.Add(3)
s.Remove(2)
if !s.Contains(2) {
fmt.Println("does not contains 2")
}
if s.Contains(3) {
fmt.Println("contains 3")
}
if len(s) == 2 {
fmt.Println("length is 2")
}
}
Output: does not contains 2 contains 3 length is 2
Index ¶
- type Set
- func (s Set[T]) Add(value T)
- func (s Set[T]) Contains(value T) bool
- func (s Set[T]) Copy() Set[T]
- func (s Set[T]) Difference(other Set[T]) Set[T]
- func (s Set[T]) Equals(other Set[T]) bool
- func (s Set[T]) Intersection(other Set[T]) Set[T]
- func (s Set[T]) Remove(value T)
- func (s Set[T]) ToSlice() []T
- func (s Set[T]) Union(other 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 comparable] map[T]struct{}
func FromSlice ¶
func FromSlice[T comparable](slice []T) Set[T]
func New ¶
func New[T comparable]() Set[T]
func (Set[T]) Difference ¶
func (Set[T]) Intersection ¶
Click to show internal directories.
Click to hide internal directories.