Documentation
¶
Overview ¶
Package treeset implements a tree backed by a red-black tree.
Structure is not thread safe.
Reference: http://en.wikipedia.org/wiki/Set_%28abstract_data_type%29
Index ¶
- type Set
- func (s *Set[T]) Add(items ...T)
- func (m *Set[T]) Ceiling(element T) (foundElement T, ok bool)
- func (set *Set[T]) Clear()
- func (set *Set[T]) Contains(items ...T) bool
- func (s *Set[T]) Difference(another *Set[T]) *Set[T]
- func (set *Set[T]) Empty() bool
- func (m *Set[T]) Floor(element T) (foundElement T, ok bool)
- func (s *Set[T]) Inorder(handler func(key T))
- func (s *Set[T]) Intersection(another *Set[T]) *Set[T]
- func (set *Set[T]) Len() int
- func (m *Set[T]) Max() (element T, ok bool)
- func (m *Set[T]) Min() (element T, ok bool)
- func (set *Set[T]) Remove(items ...T)
- func (set *Set[T]) String() string
- func (s *Set[T]) Union(another *Set[T]) *Set[T]
- func (set *Set[T]) Values() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set holds elements in a red-black tree
func NewWith ¶
func NewWith[T comparable](comparator dsgo.Comparator[T], values ...T) *Set[T]
NewWith instantiates a new empty set with the custom comparator.
func (*Set[T]) Ceiling ¶
Ceiling finds the ceiling element for the input element. In case that no ceiling is found, then 0-value, false will be returned.
Ceiling element is defined as the smallest element that is larger than or equal to the given element. A ceiling element may not be found, either because the set is empty, or because all elements in the set are smaller than the given element.
Element should adhere to the comparator's type assertion, otherwise method panics.
func (*Set[T]) Contains ¶
Contains checks weather items (one or more) are present in the set. All items have to be present in the set for the method to return true. Returns true if no arguments are passed at all, i.e. set is always superset of empty set.
func (*Set[T]) Difference ¶
Difference returns the difference between two sets. The two sets should have the same comparators, otherwise the result is empty set. The new set consists of all elements that are in "set" but not in "another". Ref: https://proofwiki.org/wiki/Definition:Set_Difference
func (*Set[T]) Floor ¶
Floor finds the floor element for the input element. In case that no floor is found, then o-value, false will be returned.
Floor element is defined as the largest element that is smaller than or equal to the given element. A floor element may not be found, either because the set is empty, or because all elements in the set are larger than the given element.
Element should adhere to the comparator's type assertion, otherwise method panics.
func (*Set[T]) Inorder ¶
func (s *Set[T]) Inorder(handler func(key T))
Inorer travels the tree in-order with a handler.
func (*Set[T]) Intersection ¶
Intersection returns the intersection between two sets. The new set consists of all elements that are both in "set" and "another". The two sets should have the same comparators, otherwise the result is empty set. Ref: https://en.wikipedia.org/wiki/Intersection_(set_theory)
func (*Set[T]) Max ¶
Max returns the maximum element from the tree set. Returns 0-value, false if set is empty.
func (*Set[T]) Min ¶
Min returns the minimum element from the tree set. Returns 0-value, false if set is empty.
func (*Set[T]) Remove ¶
func (set *Set[T]) Remove(items ...T)
Remove removes the items (one or more) from the set.
func (*Set[T]) Union ¶
Union returns the union of two sets. The new set consists of all elements that are in "set" or "another" (possibly both). The two sets should have the same comparators, otherwise the result is empty set. Ref: https://en.wikipedia.org/wiki/Union_(set_theory)