Documentation
¶
Overview ¶
Package sorted provides data structures that maintain the elements in a sorted order.
Index ¶
- type Set
- func (s *Set[T]) All() iter.Seq[T]
- func (s *Set[T]) Backward() iter.Seq[T]
- func (s *Set[T]) Delete(x T) (deleted bool)
- func (s *Set[T]) FindGreaterThanOrEqual(x T) (*SetItem[T], bool)
- func (s *Set[T]) First() (*SetItem[T], bool)
- func (s *Set[T]) Has(x T) bool
- func (s *Set[T]) Insert(x T) (added bool)
- func (s *Set[T]) Last() (*SetItem[T], bool)
- func (s *Set[T]) Len() int
- func (s *Set[T]) Max() (T, bool)
- func (s *Set[T]) Min() (T, bool)
- type SetItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T any] struct { // contains filtered or unexported fields }
Set is a sorted (ordered) set of T.
func NewSetFunc ¶
NewSetFunc creates a new set of T which is ordered according to cmp.
If T is or contains a pointer, the values referenced by it must not be changed in a way that affects the order for as long as it is in the Set.
func (*Set[T]) Backward ¶
Backward returns an iterator over all elements in the set in reverse order.
func (*Set[T]) Delete ¶
Delete removes x from the set if it exists. The return value indicates whether the removal happened.
func (*Set[T]) FindGreaterThanOrEqual ¶
FindGreaterThanOrEqual returns the first SetItem that is greater than or equal to x, and true. If there is no such element, returns false.
func (*Set[T]) First ¶
First returns the smallest SetItem and true, or nil and false if the set is empty.
func (*Set[T]) Insert ¶
Insert adds x to the set. Returns whether the insertion happened, i.e. returns false if an element that compares as equal to x was already in the set, otherwise returns true.
func (*Set[T]) Last ¶
Last returns the largest SetItem and true, or nil and false if the set is empty.
type SetItem ¶
type SetItem[T any] struct { // contains filtered or unexported fields }
SetItem refers to an element in the Set.
func (*SetItem[T]) InsertNearby ¶
InsertNearby inserts x to the same set as si. It is more efficient than calling Set.Insert if x would end up right before or after si.
Returns the SetItem whose value is x, and a bool indicating whether this is a newly added item.
func (*SetItem[T]) Next ¶
Next returns the next larger item in the set and true, or nil and false if si is already the largest element.