tree

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tree

type Tree[K, V any] struct {
	// contains filtered or unexported fields
}

func NewTree

func NewTree[K, V any](hasher utils.Hasher[K]) Tree[K, V]

Constructs a new persistent key-value map with the specified hasher.

func (Tree[K, V]) Equal

func (tree Tree[K, V]) Equal(other Tree[K, V], f cmpFunc[V]) bool

Returns whether two maps are equal. Values are compared with the provided function. This operation also skips processing of shared subtrees.

func (Tree[K, V]) ForEach

func (tree Tree[K, V]) ForEach(f eachFunc[K, V])

Call the given function once for each key-value pair in the map.

func (Tree[K, V]) Insert

func (tree Tree[K, V]) Insert(key K, value V) Tree[K, V]

Inserts the given key-value pair into the map. Replaces previous value with the same key if it exists.

func (Tree[K, V]) InsertOrMerge

func (tree Tree[K, V]) InsertOrMerge(key K, value V, f mergeFunc[V]) Tree[K, V]

Inserts the given key-value pair into the map. If a previous mapping (prevValue) exists for the key, the inserted value will be `f(value, prevValue)`.

func (Tree[K, V]) Lookup

func (tree Tree[K, V]) Lookup(key K) (V, bool)

func (Tree[K, V]) Merge

func (tree Tree[K, V]) Merge(other Tree[K, V], f mergeFunc[V]) Tree[K, V]

Merges two maps. If both maps contain a value for a key, the resulting map will map the key to the result of `f` on the two values. `f` must be commutative and idempotent! This operation is made fast by skipping processing of shared subtrees. Merging a tree with itself after r updates should have complexity equivalent to `O(r * (keysize + f))`.

func (Tree[K, V]) Remove

func (tree Tree[K, V]) Remove(key K) Tree[K, V]

Remove a mapping for the given key if it exists.

func (Tree[K, V]) Size

func (tree Tree[K, V]) Size() (res int)

Returns the number of key-value pairs in the map. NOTE: Runs in linear time in the size of the map.

func (Tree[K, V]) String

func (tree Tree[K, V]) String() string

func (Tree[K, V]) StringFiltered

func (tree Tree[K, V]) StringFiltered(pred func(k K, v V) bool) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL