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 Iterator
- func (iterator *Iterator) Begin()
- func (iterator *Iterator) End()
- func (iterator *Iterator) First() bool
- func (iterator *Iterator) Index() int
- func (iterator *Iterator) Last() bool
- func (iterator *Iterator) Next() bool
- func (iterator *Iterator) NextTo(f func(index int, value interface{}) bool) bool
- func (iterator *Iterator) Prev() bool
- func (iterator *Iterator) PrevTo(f func(index int, value interface{}) bool) bool
- func (iterator *Iterator) Value() interface{}
- type Set
- func (set *Set[T]) Add(items ...T)
- func (set *Set[T]) Clear()
- func (set *Set[T]) Contains(items ...T) bool
- func (set *Set[T]) FromJSON(data []byte) error
- func (set *Set[T]) GetValues() []T
- func (set *Set[T]) IsEmpty() bool
- func (set *Set) Iterator() Iterator
- func (set *Set[T]) MakeDifferenceWith(other sets.Set[T]) sets.Set[T]
- func (set *Set[T]) MakeIntersectionWith(other sets.Set[T]) sets.Set[T]
- func (set *Set[T]) MakeUnionWith(other sets.Set[T]) sets.Set[T]
- func (set *Set[T]) MarshalJSON() ([]byte, error)
- func (set *Set[T]) Remove(_ utils.Comparator[T], items ...T)
- func (set *Set[T]) Size() int
- func (set *Set[T]) ToJSON() ([]byte, error)
- func (set *Set[T]) ToString() string
- func (set *Set[T]) UnmarshalJSON(bytes []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator returns a stateful iterator whose values can be fetched by an index.
func (*Iterator) Begin ¶
func (iterator *Iterator) Begin()
Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.
func (*Iterator) End ¶
func (iterator *Iterator) End()
End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last element if any.
func (*Iterator) First ¶
First moves the iterator to the first element and returns true if there was a first element in the container. If First() returns true, then first element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) Index ¶
Index returns the current element's index. Does not modify the state of the iterator.
func (*Iterator) Last ¶
Last moves the iterator to the last element and returns true if there was a last element in the container. If Last() returns true, then last element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) Next ¶
Next moves the iterator to the next element and returns true if there was a next element in the container. If Next() returns true, then next element's index and value can be retrieved by Index() and Value(). If Next() was called for the first time, then it will point the iterator to the first element if it exists. Modifies the state of the iterator.
func (*Iterator) NextTo ¶
NextTo moves the iterator to the next element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) Prev ¶
Prev moves the iterator to the previous element and returns true if there was a previous element in the container. If Prev() returns true, then previous element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) PrevTo ¶
PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If PrevTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
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 utils.Comparator[T], values ...T) *Set[T]
NewWith instantiates a new empty set with the custom comparator.
func (*Set[T]) Add ¶
func (set *Set[T]) Add(items ...T)
Add adds the items (one or more) to the set.
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]) GetValues ¶ added in v0.3.0
func (set *Set[T]) GetValues() []T
Values returns all items in the set.
func (*Set[T]) MakeDifferenceWith ¶ added in v0.3.0
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 "other". Ref: https://proofwiki.org/wiki/Definition:Set_Difference
func (*Set[T]) MakeIntersectionWith ¶ added in v0.3.0
Intersection returns the intersection between two sets. The new set consists of all elements that are both in "set" and "other". 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]) MakeUnionWith ¶ added in v0.3.0
Union returns the union of two sets. The new set consists of all elements that are in "set" or "other" (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)
func (*Set[T]) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
func (*Set[T]) Remove ¶
func (set *Set[T]) Remove(_ utils.Comparator[T], items ...T)
Remove removes the items (one or more) from the set.
func (*Set[T]) UnmarshalJSON ¶
UnmarshalJSON @implements json.Unmarshaler