Documentation
¶
Index ¶
- type TreeSet
- func (ts *TreeSet[T]) Add(v T)
- func (ts *TreeSet[T]) AddAll(vs ...T)
- func (ts *TreeSet[T]) AddCol(ac cog.Collection[T])
- func (ts *TreeSet[T]) Ceiling(v T) *T
- func (ts *TreeSet[T]) Clear()
- func (ts *TreeSet[T]) Contains(v T) bool
- func (ts *TreeSet[T]) ContainsAll(vs ...T) bool
- func (ts *TreeSet[T]) ContainsAny(vs ...T) bool
- func (ts *TreeSet[T]) ContainsCol(ac cog.Collection[T]) bool
- func (ts *TreeSet[T]) ContainsIter(it cog.Iterator[T]) bool
- func (ts *TreeSet[T]) Each(f func(int, T) bool)
- func (ts *TreeSet[T]) Floor(v T) *T
- func (ts *TreeSet[T]) Graph() string
- func (ts *TreeSet[T]) Head() (v T)
- func (ts *TreeSet[T]) IsEmpty() bool
- func (ts *TreeSet[T]) Iterator() cog.Iterator[T]
- func (ts *TreeSet[T]) Len() int
- func (ts *TreeSet[T]) MarshalJSON() ([]byte, error)
- func (ts *TreeSet[T]) PeekHead() (v T, ok bool)
- func (ts *TreeSet[T]) PeekTail() (v T, ok bool)
- func (ts *TreeSet[T]) PollHead() (v T, ok bool)
- func (ts *TreeSet[T]) PollTail() (v T, ok bool)
- func (ts *TreeSet[T]) Remove(v T)
- func (ts *TreeSet[T]) RemoveAll(vs ...T)
- func (ts *TreeSet[T]) RemoveCol(ac cog.Collection[T])
- func (ts *TreeSet[T]) RemoveFunc(f func(T) bool)
- func (ts *TreeSet[T]) RemoveIter(it cog.Iterator[T])
- func (ts *TreeSet[T]) RetainAll(vs ...T)
- func (ts *TreeSet[T]) RetainCol(ac cog.Collection[T])
- func (ts *TreeSet[T]) RetainFunc(f func(T) bool)
- func (ts *TreeSet[T]) ReverseEach(f func(int, T) bool)
- func (ts *TreeSet[T]) Seq() iter.Seq[T]
- func (ts *TreeSet[T]) String() string
- func (ts *TreeSet[T]) Tail() (v T)
- func (ts *TreeSet[T]) UnmarshalJSON(data []byte) error
- func (ts *TreeSet[T]) Values() []T
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TreeSet ¶
type TreeSet[T any] struct { // contains filtered or unexported fields }
TreeSet implements an tree set that keeps the compare order of keys. The zero value for TreeSet is an empty set ready to use.
https://en.wikipedia.org/wiki/Red%E2%80%93black_tree
To iterate over a tree set (where ts is a *TreeSet):
for it := ts.Iterator(); it.Next(); {
// do something with it.Value()
}
func NewTreeSet ¶
NewTreeSet creates a new TreeSet. Example: cog.NewTreeSet(cog.CompareString, "v1", "v2")
Example ¶
set := NewTreeSet(cmp.Compare[int])
set.Add(1) // 1
set.AddAll(2, 2, 3, 4, 5) // 1, 2, 3, 4, 5 (in order, duplicates ignored)
set.Remove(4) // 1, 2, 3, 5 (in order)
set.RemoveAll(2, 3) // 1, 5 (in order)
set.Contains(1) // true
set.ContainsAll(1, 5) // true
set.ContainsAll(1, 6) // false
_ = set.Values() // []int{1,5} (in order)
set.Clear() // empty
set.IsEmpty() // true
set.Len() // 0
func (*TreeSet[T]) AddAll ¶ added in v1.0.27
func (ts *TreeSet[T]) AddAll(vs ...T)
AddAll adds all items of vs.
func (*TreeSet[T]) AddCol ¶
func (ts *TreeSet[T]) AddCol(ac cog.Collection[T])
AddCol adds all items of another collection
func (*TreeSet[T]) Ceiling ¶
func (ts *TreeSet[T]) Ceiling(v T) *T
Ceiling finds ceiling node of the input key, return the ceiling node's value or nil if no ceiling is found.
Ceiling node is defined as the smallest node that is larger than or equal to the given node. A ceiling node may not be found, either because the tree is empty, or because all nodes in the tree are smaller than the given node.
key should adhere to the comparator's type assertion, otherwise method panics.
func (*TreeSet[T]) ContainsAll ¶ added in v1.0.27
ContainsAll Test to see if the collection contains all items of vs
func (*TreeSet[T]) ContainsAny ¶ added in v1.2.9
ContainsAny Test to see if the collection contains any item of vs
func (*TreeSet[T]) ContainsCol ¶ added in v1.0.27
func (ts *TreeSet[T]) ContainsCol(ac cog.Collection[T]) bool
ContainsCol Test to see if the collection contains all items of another collection
func (*TreeSet[T]) ContainsIter ¶ added in v1.0.27
ContainsIter Test to see if the collection contains all items of iterator 'it'
func (*TreeSet[T]) Floor ¶
func (ts *TreeSet[T]) Floor(v T) *T
Floor Finds floor node of the input key, return the floor node's value or nil if no floor is found.
Floor node is defined as the largest node that is smaller than or equal to the given node. A floor node may not be found, either because the tree is empty, or because all nodes in the tree are larger than the given node.
key should adhere to the comparator's type assertion, otherwise method panics.
func (*TreeSet[T]) Head ¶
func (ts *TreeSet[T]) Head() (v T)
Head returns the first item of set ts or nil if the set is empty.
func (*TreeSet[T]) MarshalJSON ¶
MarshalJSON implements type json.Marshaler interface, so can be called in json.Marshal(ts)
func (*TreeSet[T]) Remove ¶
func (ts *TreeSet[T]) Remove(v T)
Remove remove all items with associated value v
func (*TreeSet[T]) RemoveAll ¶ added in v1.0.27
func (ts *TreeSet[T]) RemoveAll(vs ...T)
RemoveAll remove all items in the array vs
func (*TreeSet[T]) RemoveCol ¶
func (ts *TreeSet[T]) RemoveCol(ac cog.Collection[T])
RemoveCol remove all of this collection's elements that are also contained in the specified collection
func (*TreeSet[T]) RemoveFunc ¶
RemoveFunc remove all items that function f returns true
func (*TreeSet[T]) RemoveIter ¶
RemoveIter remove all items in the iterator it
func (*TreeSet[T]) RetainAll ¶ added in v1.0.27
func (ts *TreeSet[T]) RetainAll(vs ...T)
RetainAll Retains only the elements in this collection that are contained in the argument array vs.
func (*TreeSet[T]) RetainCol ¶
func (ts *TreeSet[T]) RetainCol(ac cog.Collection[T])
RetainCol Retains only the elements in this collection that are contained in the specified collection.
func (*TreeSet[T]) RetainFunc ¶
RetainFunc Retains all items that function f returns true
func (*TreeSet[T]) ReverseEach ¶
ReverseEach call f for each item in the set with reverse order
func (*TreeSet[T]) Tail ¶
func (ts *TreeSet[T]) Tail() (v T)
Tail returns the last item of set ts or nil if the set is empty.
func (*TreeSet[T]) UnmarshalJSON ¶
UnmarshalJSON implements type json.Unmarshaler interface, so can be called in json.Unmarshal(data, ts)