Documentation ¶
Overview ¶
Package sets provides set types.
Index ¶
- type Bit
- func (s *Bit) Add(elem ...uint)
- func (s *Bit) AddSeq(seq iter.Seq[uint])
- func (s *Bit) All() iter.Seq[uint]
- func (s *Bit) Clear()
- func (s *Bit) Clone() *Bit
- func (s *Bit) Delete(x uint)
- func (s *Bit) Equal(s2 *Bit) bool
- func (s *Bit) Format(f fmt.State, verb rune)
- func (s *Bit) Has(x uint) bool
- func (s *Bit) Len() int
- func (s *Bit) Max() (_ uint, nonEmpty bool)
- func (s *Bit) Min() (_ uint, nonEmpty bool)
- func (s *Bit) Reversed() iter.Seq[uint]
- type Set
- type Sorted
- func (s *Sorted[T]) Add(elem ...T)
- func (s *Sorted[T]) AddSeq(seq iter.Seq[T])
- func (s *Sorted[T]) AddSet(other *Sorted[T])
- func (s *Sorted[T]) All() iter.Seq2[int, T]
- func (s *Sorted[T]) At(i int) T
- func (s *Sorted[T]) Clear()
- func (s *Sorted[T]) Clone() *Sorted[T]
- func (s *Sorted[T]) Delete(x T)
- func (s *Sorted[T]) Format(f fmt.State, verb rune)
- func (s *Sorted[T]) Grow(n int)
- func (s *Sorted[T]) Has(x T) bool
- func (s *Sorted[T]) Len() int
- func (s *Sorted[T]) Values() iter.Seq[T]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bit ¶
type Bit struct {
// contains filtered or unexported fields
}
Bit is a bitmap with O(1) lookup, insertion, and deletion. The zero value is an empty set.
func CollectBit ¶
Collect returns a new set that contains the elements of the given iterator.
func (*Bit) Clear ¶
func (s *Bit) Clear()
Clear removes all elements from the set, but retains the space allocated for the set.
func (*Bit) Format ¶
Format implements fmt.Formatter by formatting its elements according to the printer state and verb surrounded by braces.
type Set ¶
type Set[T comparable] map[T]struct{}
Set is an unordered set with O(1) lookup, insertion, and deletion. The zero value is an empty set.
func Collect ¶
func Collect[T comparable](seq iter.Seq[T]) Set[T]
Collect returns a new set that contains the elements of the given iterator.
func New ¶
func New[T comparable](elem ...T) Set[T]
New returns a new set that contains the arguments passed to it.
func (Set[T]) Clear ¶
func (s Set[T]) Clear()
Clear removes all elements from the set, but retains the space allocated for the set.
func (Set[T]) Format ¶
Format implements fmt.Formatter by formatting its elements according to the printer state and verb surrounded by braces.
Example ¶
package main import ( "fmt" "zb.256lights.llc/pkg/sets" ) func main() { s := sets.New(3.14159) fmt.Printf("%.2f\n", s) }
Output: {3.14}
type Sorted ¶
Sorted is a sorted list of unique items. The zero value is an empty set. nil is treated like an empty set, but any attempts to add to it will panic.
func CollectSorted ¶
Collect returns a new set that contains the elements of the given iterator. Equivalent to calling Sorted.AddSeq on a zero set.
func NewSorted ¶
NewSorted returns a new set with the given elements. Equivalent to calling Sorted.Add on a zero set.
func (*Sorted[T]) Clear ¶
func (s *Sorted[T]) Clear()
Clear removes all elements from the set, but retains the space allocated for the set.
func (*Sorted[T]) Delete ¶
func (s *Sorted[T]) Delete(x T)
Delete removes x from the set if present.
func (*Sorted[T]) Format ¶
Format implements fmt.Formatter by formatting its elements according to the printer state and verb surrounded by braces.
Example ¶
package main import ( "fmt" "zb.256lights.llc/pkg/sets" ) func main() { s := sets.NewSorted(3.14159, -1.234) fmt.Printf("%.2f\n", s) }
Output: {-1.23 3.14}
func (*Sorted[T]) Grow ¶
Grow ensures that the set can add n more unique elements without allocating.