Documentation ¶
Index ¶
- type None
- type Set
- func (s Set[Elem]) Clear()
- func (s Set[Elem]) Clone() Set[Elem]
- func (s Set[Elem]) Delete(elems ...Elem)
- func (s Set[Elem]) Difference(s2 Set[Elem]) Set[Elem]
- func (s Set[Elem]) Equal(s2 Set[Elem]) (equal bool)
- func (s Set[Elem]) Has(elem Elem) (has bool)
- func (s Set[Elem]) Intersection(s2 Set[Elem]) Set[Elem]
- func (s Set[Elem]) IsSubset(s2 Set[Elem]) (isSubset bool)
- func (s Set[Elem]) Len() (length int)
- func (s Set[Elem]) Range(f func(elem Elem) bool)
- func (s Set[Elem]) Slice() []Elem
- func (s Set[Elem]) Store(elems ...Elem)
- func (s Set[Elem]) Union(s2 Set[Elem]) Set[Elem]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[Elem comparable] map[Elem]None
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s := make(set.Set[int]) s.Store(1, 2, 3) fmt.Println(s.Has(1)) s.Delete(1) fmt.Println(s.Has(1)) }
Output: true false
Example (String) ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s := make(set.Set[string]) s.Store("a") s.Store("b", "c") s.Range(func(elem string) bool { fmt.Println(elem) return true }) }
Output: a b c
func (Set[Elem]) Clear ¶
func (s Set[Elem]) Clear()
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s := make(set.Set[int]) s.Store(1, 2, 3) s.Clear() fmt.Println(s.Len()) }
Output: 0
func (Set[Elem]) Clone ¶
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s1 := make(set.Set[int]) s1.Store(1, 2, 3) s2 := s1.Clone() s1.Store(4, 5) s2.Range(func(elem int) bool { fmt.Println(elem) return true }) }
Output: 1 2 3
func (Set[Elem]) Delete ¶
func (s Set[Elem]) Delete(elems ...Elem)
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s := make(set.Set[int]) s.Store(1, 2, 3) s.Delete(2) s.Range(func(elem int) bool { fmt.Println(elem) return true }) }
Output: 1 3
func (Set[Elem]) Difference ¶
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s1 := make(set.Set[int]) s1.Store(1, 2) s2 := make(set.Set[int]) s2.Store(2, 3) s3 := s1.Difference(s2) s3.Range(func(elem int) bool { fmt.Println(elem) return true }) }
Output: 1
func (Set[Elem]) Equal ¶
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s1 := make(set.Set[int]) s1.Store(1, 2, 3) s2 := make(set.Set[int]) s2.Store(1, 2, 3) s3 := make(set.Set[int]) s3.Store(1, 2) fmt.Println(s1.Equal(s2)) fmt.Println(s1.Equal(s3)) }
Output: true false
func (Set[Elem]) Has ¶
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s := make(set.Set[int]) s.Store(1, 2) fmt.Println(s.Has(1)) fmt.Println(s.Has(2)) fmt.Println(s.Has(3)) fmt.Println(s.Has(4)) }
Output: true true false false
func (Set[Elem]) Intersection ¶
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s1 := make(set.Set[int]) s1.Store(1, 2) s2 := make(set.Set[int]) s2.Store(2, 3) s3 := s1.Intersection(s2) s3.Range(func(elem int) bool { fmt.Println(elem) return true }) }
Output: 2
func (Set[Elem]) IsSubset ¶
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s1 := make(set.Set[int]) s1.Store(1, 2) s2 := make(set.Set[int]) s2.Store(1) s3 := make(set.Set[int]) s3.Store(3) s4 := make(set.Set[int]) s4.Store(1, 2, 3) fmt.Println(s1.IsSubset(s1)) fmt.Println(s1.IsSubset(s2)) fmt.Println(s1.IsSubset(s3)) fmt.Println(s1.IsSubset(s4)) }
Output: true true false false
func (Set[Elem]) Len ¶
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s := make(set.Set[int]) fmt.Println(s.Len()) s.Store(1, 2) fmt.Println(s.Len()) s.Delete(2) fmt.Println(s.Len()) }
Output: 0 2 1
func (Set[Elem]) Range ¶
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s := make(set.Set[int]) s.Store(1, 2, 3) s.Range(func(elem int) bool { fmt.Println(elem) return true }) }
Output: 1 2 3
Example (Break) ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s := make(set.Set[string]) s.Store("a", "b", "c") var cnt int s.Range(func(elem string) bool { cnt++ return false }) fmt.Println(cnt) }
Output: 1
func (Set[Elem]) Slice ¶
func (s Set[Elem]) Slice() []Elem
Example ¶
package main import ( "fmt" "github.com/min0625/set" ) func main() { s := make(set.Set[int]) s.Store(1, 2, 3) for _, e := range s.Slice() { fmt.Println(e) } }
Output: 1 2 3
Click to show internal directories.
Click to hide internal directories.