Documentation
¶
Index ¶
- type Set
- func (s *Set) Add(v string) bool
- func (s *Set) Clear()
- func (s *Set) Copy(x *Set)
- func (s *Set) Equals(t *Set) bool
- func (s *Set) Has(v string) bool
- func (s *Set) Intersection(x, y *Set)
- func (s *Set) IntersectionWith(x *Set)
- func (s *Set) Intersects(x *Set) bool
- func (s *Set) Len() int
- func (s *Set) MarshalJSON() ([]byte, error)
- func (s *Set) Remove(v string) bool
- func (s *Set) Slice() []string
- func (s *Set) Union(x, y *Set)
- func (s *Set) UnionWith(x *Set) bool
- func (s *Set) UnmarshalJSON(data []byte) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set represents a set of unique strings.
Example ¶
package main
import (
"fmt"
"github.com/bsm/strset"
)
func main() {
// Create a new set
set := strset.New(3)
set.Add("b") // true
set.Add("a") // true
set.Add("c") // true
set.Add("a") // false
fmt.Println(set.Slice()) // [a b c]
set.Has("a") // true
set.Has("d") // false
set.Remove("a") // true
set.Remove("d") // false
fmt.Println(set.Slice()) // [b c]
}
Output: [a b c] [b c]
func Use ¶
Use turns a slice into a set, re-using the underlying slice. WARNING: this function is destructive and will mutate the passed slice.
func (*Set) Intersection ¶
Intersection sets s to the intersection x ∩ y.
func (*Set) IntersectionWith ¶
IntersectionWith sets s to the intersection s ∩ x.
func (*Set) Intersects ¶
Intersects reports whether s ∩ x ≠ ∅.
func (*Set) MarshalJSON ¶
MarshalJSON encodes the set as JSON
func (*Set) UnmarshalJSON ¶
UnmarshalJSON decodes JSON into a set
Click to show internal directories.
Click to hide internal directories.

