part

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: Apache-2.0 Imports: 14 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterKeyType

func RegisterKeyType[K any](bytesFromKey func(K) []byte)

RegisterKeyType registers a new key type to be used with the Map and Set types. Intended to be called from init() functions. For Set-only usage only the [bytesFromKey] function is needed.

func RootOnlyWatch

func RootOnlyWatch(o *options)

RootOnlyWatch sets the tree to only have a watch channel on the root node. This improves the speed at the cost of having a much more coarse grained notifications.

Types

type Iterator

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

Iterator for key and value pairs where value is of type T

func (*Iterator[T]) Clone added in v0.3.0

func (it *Iterator[T]) Clone() *Iterator[T]

Clone returns a copy of the iterator, allowing restarting the iterator from scratch.

func (*Iterator[T]) Next

func (it *Iterator[T]) Next() (key []byte, value T, ok bool)

Next returns the next key, value and true if the value exists, otherwise it returns false.

type Map

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

Map of key-value pairs. The zero value is ready for use, provided that the key type has been registered with RegisterKeyType.

Map is a typed wrapper around Tree[T] for working with keys that are not []byte.

func FromMap

func FromMap[K comparable, V any](m Map[K, V], hm map[K]V) Map[K, V]

FromMap copies values from the hash map into the given Map. This is not implemented as a method on Map[K,V] as hash maps require the comparable constraint and we do not need to limit Map[K, V] to that.

func (Map[K, V]) All

func (m Map[K, V]) All() iter.Seq2[K, V]

All iterates every key-value in the map in order. The order is in bytewise order of the byte slice returned by bytesFromKey.

func (Map[K, V]) Delete

func (m Map[K, V]) Delete(key K) Map[K, V]

Delete a value from the map. Returns a new map without the element pointed to by the key (if found).

func (Map[K, V]) EqualKeys

func (m Map[K, V]) EqualKeys(other Map[K, V]) bool

EqualKeys returns true if both maps contain the same keys.

func (Map[K, V]) Get

func (m Map[K, V]) Get(key K) (value V, found bool)

Get a value from the map by its key.

func (Map[K, V]) Len

func (m Map[K, V]) Len() int

Len returns the number of elements in the map.

func (Map[K, V]) LowerBound

func (m Map[K, V]) LowerBound(from K) iter.Seq2[K, V]

LowerBound iterates over all keys in order with value equal to or greater than [from].

func (Map[K, V]) MarshalJSON

func (m Map[K, V]) MarshalJSON() ([]byte, error)

func (Map[K, V]) MarshalYAML added in v0.3.1

func (m Map[K, V]) MarshalYAML() (any, error)

func (Map[K, V]) Prefix

func (m Map[K, V]) Prefix(prefix K) iter.Seq2[K, V]

Prefix iterates in order over all keys that start with the given prefix.

func (Map[K, V]) Set

func (m Map[K, V]) Set(key K, value V) Map[K, V]

Set a value. Returns a new map with the value set. Original map is unchanged.

func (Map[K, V]) SlowEqual

func (m Map[K, V]) SlowEqual(other