Documentation ¶
Index ¶
- Variables
- func RootOnlyWatch(o *options)
- type Iterator
- type Map
- func (m Map[K, V]) All() MapIterator[K, V]
- func (m Map[K, V]) Delete(key K) Map[K, V]
- func (m Map[K, V]) Get(key K) (value V, found bool)
- func (m Map[K, V]) Len() int
- func (m Map[K, V]) LowerBound(from K) MapIterator[K, V]
- func (m Map[K, V]) Prefix(prefix K) MapIterator[K, V]
- func (m Map[K, V]) Set(key K, value V) Map[K, V]
- type MapIterator
- type Ops
- type Option
- type Set
- func (s Set[T]) All() SetIterator[T]
- func (s Set[T]) Delete(v T) Set[T]
- func (s Set[T]) Difference(s2 Set[T]) Set[T]
- func (s Set[T]) Has(v T) bool
- func (s Set[T]) Len() int
- func (s Set[T]) Set(v T) Set[T]
- func (s Set[T]) Slice() []T
- func (s Set[T]) ToBytesFunc() func(T) []byte
- func (s Set[T]) Union(s2 Set[T]) Set[T]
- type SetIterator
- type Tree
- func (t *Tree[T]) Delete(key []byte) (old T, hadOld bool, tree *Tree[T])
- func (t *Tree[T]) Get(key []byte) (T, <-chan struct{}, bool)
- func (t *Tree[T]) Insert(key []byte, value T) (old T, hadOld bool, tree *Tree[T])
- func (t *Tree[T]) Iterator() *Iterator[T]
- func (t *Tree[T]) Len() int
- func (t *Tree[T]) LowerBound(key []byte) *Iterator[T]
- func (t *Tree[T]) Prefix(prefix []byte) (*Iterator[T], <-chan struct{})
- func (t *Tree[T]) PrintTree()
- func (t *Tree[T]) RootWatch() <-chan struct{}
- func (t *Tree[T]) Txn() *Txn[T]
- type Txn
- func (txn *Txn[T]) Clone() *Txn[T]
- func (txn *Txn[T]) Commit() *Tree[T]
- func (txn *Txn[T]) CommitOnly() *Tree[T]
- func (txn *Txn[T]) Delete(key []byte) (old T, hadOld bool)
- func (txn *Txn[T]) Get(key []byte) (T, <-chan struct{}, bool)
- func (txn *Txn[T]) Insert(key []byte, value T) (old T, hadOld bool)
- func (txn *Txn[T]) Iterator() *Iterator[T]
- func (txn *Txn[T]) Len() int
- func (txn *Txn[T]) LowerBound(key []byte) *Iterator[T]
- func (txn *Txn[T]) Notify()
- func (txn *Txn[T]) Prefix(key []byte) (*Iterator[T], <-chan struct{})
- func (txn *Txn[T]) PrintTree()
- func (txn *Txn[T]) RootWatch() <-chan struct{}
Constants ¶
This section is empty.
Variables ¶
var BytesSet = NewBytesSet()
BytesSet is an empty set of byte slices. Short form for "part.NewBytesSet()"
var StringSet = NewStringSet()
StringSet is an empty set of strings. Short form for "part.NewStringSet()"
Functions ¶
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
type Map ¶
type Map[K, V any] struct { // contains filtered or unexported fields }
Map of key-value pairs.
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 NewBytesMap ¶
func NewMap ¶
NewMap creates a new persistent map. The toBytes function maps the key into bytes, and fromBytes does the reverse.
func NewStringMap ¶
func NewUint64Map ¶
func (Map[K, V]) All ¶
func (m Map[K, V]) All() MapIterator[K, V]
All iterates every key-value in the map in order. The order is in bytewise order of the byte slice returned by toBytes.
func (Map[K, V]) Delete ¶
Delete a value from the map. Returns a new map without the element pointed to by the key (if found).
func (Map[K, V]) LowerBound ¶
func (m Map[K, V]) LowerBound(from K) MapIterator[K, V]
LowerBound iterates over all keys in order with value equal to or greater than [from].
func (Map[K, V]) Prefix ¶
func (m Map[K, V]) Prefix(prefix K) MapIterator[K, V]
Prefix iterates in order over all keys that start with the given prefix.
type MapIterator ¶
type MapIterator[K, V any] struct { // contains filtered or unexported fields }
MapIterator iterates over key and value pairs.
func (MapIterator[K, V]) Next ¶
func (it MapIterator[K, V]) Next() (k K, v V, ok bool)
Next returns the next key and value. If the iterator is exhausted it returns false.
type Ops ¶
type Ops[T any] interface { // Len returns the number of objects in the tree. Len() int // Get fetches the value associated with the given key. // Returns the value, a watch channel (which is closed on // modification to the key) and boolean which is true if // value was found. Get(key []byte) (T, <-chan struct{}, bool) // Prefix returns an iterator for all objects that starts with the // given prefix, and a channel that closes when any objects matching // the given prefix are upserted or deleted. Prefix(key []byte) (*Iterator[T], <-chan struct{}) // LowerBound returns an iterator for all objects that have a // key equal or higher than the given 'key'. LowerBound(key []byte) *Iterator[T] // RootWatch returns a watch channel for the root of the tree. // Since this is the channel associated with the root, this closes // when there are any changes to the tree. RootWatch() <-chan struct{} // Iterator returns an iterator for all objects. Iterator() *Iterator[T] // PrintTree to the standard output. For debugging. PrintTree() }
Ops is the common operations that can be performed with a Tree or Txn.
type Set ¶
type Set[T any] struct { // contains filtered or unexported fields }
Set is a persistent (immutable) set of values. A Set can be defined for any type for which a byte slice key can be derived.
func NewBytesSet ¶
NewBytesSet creates a new set of byte slices.
func NewSet ¶
NewSet creates a new set of T when given a function to convert T into a byte slice key.
func NewStringSet ¶
NewStringSet creates a new set of strings.
func (Set[T]) Difference ¶
Difference removes the values in the second set from the first set. Returns a new set, the original sets are unchanged.
func (Set[T]) Slice ¶
func (s Set[T]) Slice() []T
Slice converts the set into a slice. Note that this allocates a new slice and appends all values into it. If you just want to iterate over the set use All() instead.
func (Set[T]) ToBytesFunc ¶
ToBytesFunc returns the function to extract the key from the element type. Useful for utilities that are interested in the key.
type SetIterator ¶
type SetIterator[T any] struct { // contains filtered or unexported fields }
SetIterator iterates over values in a set.
func (SetIterator[T]) Next ¶
func (it SetIterator[T]) Next() (v T, ok bool)
Next returns the next value or false if all have been iterated over.
type Tree ¶
type Tree[T any] struct { // contains filtered or unexported fields }
Tree is a persistent (immutable) adaptive radix tree. It supports map-like operations on values keyed by []byte and additionally prefix searching and lower bound searching. Each node in the tree has an associated channel that is closed when that node is mutated. This allows watching any part of the tree (any prefix) for changes.
func (*Tree[T]) Delete ¶
Delete the given key from the tree. Returns the old value if it exists and the new tree.
func (*Tree[T]) Get ¶
Get fetches the value associated with the given key. Returns the value, a watch channel (which is closed on modification to the key) and boolean which is true if value was found.
func (*Tree[T]) Insert ¶
Insert inserts the key into the tree with the given value. Returns the old value if it exists and a new tree.
func (*Tree[T]) LowerBound ¶
LowerBound returns an iterator for all keys that have a value equal to or higher than 'key'.
func (*Tree[T]) Prefix ¶
Prefix returns an iterator for all objects that starts with the given prefix, and a channel that closes when any objects matching the given prefix are upserted or deleted.
func (*Tree[T]) PrintTree ¶
func (t *Tree[T]) PrintTree()
PrintTree to the standard output. For debugging.
type Txn ¶
type Txn[T any] struct { // tree is the tree being modified Tree[T] // contains filtered or unexported fields }
Txn is a transaction against a tree. It allows doing efficient modifications to a tree by caching and reusing cloned nodes.
func (*Txn[T]) Clone ¶
Clone returns a clone of the transaction. The clone is unaffected by any future changes done with the original transaction.
func (*Txn[T]) CommitOnly ¶
CommitOnly the transaction, but do not close the watch channels. Returns the new tree. To close the watch channels call Notify().
func (*Txn[T]) Get ¶
Get fetches the value associated with the given key. Returns the value, a watch channel (which is closed on modification to the key) and boolean which is true if value was found.
func (*Txn[T]) Insert ¶
Insert or update the tree with the given key and value. Returns the old value if it exists.
func (*Txn[T]) LowerBound ¶
LowerBound returns an iterator for all objects that have a key equal or higher than the given 'key'.
func (*Txn[T]) Notify ¶
func (txn *Txn[T]) Notify()
Notify closes the watch channels of nodes that were mutated as part of this transaction.
func (*Txn[T]) Prefix ¶
Prefix returns an iterator for all objects that starts with the given prefix, and a channel that closes when any objects matching the given prefix are upserted or deleted.