Documentation
¶
Overview ¶
This package provides a generic red-black tree implementation. It is in effect a < ordered key-value map.
Index ¶
- type Comparable
- type SortedMap
- func (me *SortedMap[K, V]) All() iter.Seq2[K, V]
- func (me *SortedMap[K, V]) Clear()
- func (me *SortedMap[K, V]) Contains(key K) bool
- func (me *SortedMap[K, V]) Delete(key K) bool
- func (me *SortedMap[K, V]) Find(key K) (V, bool)
- func (me *SortedMap[K, V]) Insert(key K, value V) bool
- func (me *SortedMap[K, V]) Keys() iter.Seq[K]
- func (me *SortedMap[K, V]) Len() int
- func (me *SortedMap[K, V]) Values() iter.Seq[V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comparable ¶
type Comparable interface {
~string | ~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
Comparable allows only string or integer keys.
type SortedMap ¶
type SortedMap[K Comparable, V any] struct { // contains filtered or unexported fields }
An SortedMap zero value is usable. Create it with statements like these:
var tree SortedMap[string, int]
tree := SortedMap[int, int]{}
func (*SortedMap[K, V]) All ¶
All is a range function for use as an iterable in a for … range loop that returns all of the tree’s keys and values, e.g.,
for key, value := range tree.All()
See also [Keys] and [Values]
func (*SortedMap[K, V]) Clear ¶
func (me *SortedMap[K, V]) Clear()
Clear deletes all the tree’s key-value items. See also [Delete]
func (*SortedMap[K, V]) Contains ¶
Contains returns true if the key is in the tree and false otherwise.
func (*SortedMap[K, V]) Delete ¶
Delete deletes the key-value item with the given key from the tree and returns true, or does nothing and returns false if there is no key-value with the given key. For example:
ok := tree.Delete(key).
See also [Clear]
func (*SortedMap[K, V]) Find ¶
Find returns the value and true if the key is in the tree or V’s zero value and false otherwise. For example:
value, ok := tree.Find(key)
func (*SortedMap[K, V]) Insert ¶
Insert inserts a new key-value item into the tree and returns true; or replaces an existing key-value pair’s value if the keys are equal and returns false. For example:
ok := tree.Insert(key, value).
func (*SortedMap[K, V]) Keys ¶
Keys is a range function for use as an iterable in a for … range loop that returns all of the tree’s keys:
for key := range tree.Keys()
See also [All] and [Values]