package iradix
import "github.com/hashicorp/go-immutable-radix"
Index ¶
- type Iterator
- func (i *Iterator) Next() ([]byte, interface{}, bool)
- func (i *Iterator) SeekLowerBound(key []byte)
- func (i *Iterator) SeekPrefix(prefix []byte)
- func (i *Iterator) SeekPrefixWatch(prefix []byte) (watch <-chan struct{})
- type Node
- func (n *Node) Get(k []byte) (interface{}, bool)
- func (n *Node) GetWatch(k []byte) (<-chan struct{}, interface{}, bool)
- func (n *Node) Iterator() *Iterator
- func (n *Node) LongestPrefix(k []byte) ([]byte, interface{}, bool)
- func (n *Node) Maximum() ([]byte, interface{}, bool)
- func (n *Node) Minimum() ([]byte, interface{}, bool)
- func (n *Node) ReverseIterator() *ReverseIterator
- func (n *Node) Walk(fn WalkFn)
- func (n *Node) WalkBackwards(fn WalkFn)
- func (n *Node) WalkPath(path []byte, fn WalkFn)
- func (n *Node) WalkPrefix(prefix []byte, fn WalkFn)
- type ReverseIterator
- func NewReverseIterator(n *Node) *ReverseIterator
- func (ri *ReverseIterator) Previous() ([]byte, interface{}, bool)
- func (ri *ReverseIterator) SeekPrefix(prefix []byte)
- func (ri *ReverseIterator) SeekPrefixWatch(prefix []byte) (watch <-chan struct{})
- func (ri *ReverseIterator) SeekReverseLowerBound(key []byte)
- type Tree
- func New() *Tree
- func (t *Tree) Delete(k []byte) (*Tree, interface{}, bool)
- func (t *Tree) DeletePrefix(k []byte) (*Tree, bool)
- func (t *Tree) Get(k []byte) (interface{}, bool)
- func (t *Tree) Insert(k []byte, v interface{}) (*Tree, interface{}, bool)
- func (t *Tree) Len() int
- func (t *Tree) Root() *Node
- func (t *Tree) Txn() *Txn
- type Txn
- func (t *Txn) Clone() *Txn
- func (t *Txn) Commit() *Tree
- func (t *Txn) CommitOnly() *Tree
- func (t *Txn) Delete(k []byte) (interface{}, bool)
- func (t *Txn) DeletePrefix(prefix []byte) bool
- func (t *Txn) Get(k []byte) (interface{}, bool)
- func (t *Txn) GetWatch(k []byte) (<-chan struct{}, interface{}, bool)
- func (t *Txn) Insert(k []byte, v interface{}) (interface{}, bool)
- func (t *Txn) Notify()
- func (t *Txn) Root() *Node
- func (t *Txn) TrackMutate(track bool)
- type WalkFn
Types ¶
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator is used to iterate over a set of nodes in pre-order
func (*Iterator) Next ¶
Next returns the next node in order
func (*Iterator) SeekLowerBound ¶
SeekLowerBound is used to seek the iterator to the smallest key that is greater or equal to the given key. There is no watch variant as it's hard to predict based on the radix structure which node(s) changes might affect the result.
func (*Iterator) SeekPrefix ¶
SeekPrefix is used to seek the iterator to a given prefix
func (*Iterator) SeekPrefixWatch ¶
SeekPrefixWatch is used to seek the iterator to a given prefix and returns the watch channel of the finest granularity
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is an immutable node in the radix tree
func (*Node) Get ¶
func (*Node) GetWatch ¶
func (*Node) Iterator ¶
Iterator is used to return an iterator at the given node to walk the tree
func (*Node) LongestPrefix ¶
LongestPrefix is like Get, but instead of an exact match, it will return the longest prefix match.
func (*Node) Maximum ¶
Maximum is used to return the maximum value in the tree
func (*Node) Minimum ¶
Minimum is used to return the minimum value in the tree
func (*Node) ReverseIterator ¶
func (n *Node) ReverseIterator() *ReverseIterator
ReverseIterator is used to return an iterator at the given node to walk the tree backwards
func (*Node) Walk ¶
Walk is used to walk the tree
func (*Node) WalkBackwards ¶
WalkBackwards is used to walk the tree in reverse order
func (*Node) WalkPath ¶
WalkPath is used to walk the tree, but only visiting nodes from the root down to a given leaf. Where WalkPrefix walks all the entries *under* the given prefix, this walks the entries *above* the given prefix.
func (*Node) WalkPrefix ¶
WalkPrefix is used to walk the tree under a prefix
type ReverseIterator ¶
type ReverseIterator struct {
// contains filtered or unexported fields
}
ReverseIterator is used to iterate over a set of nodes in reverse in-order
func NewReverseIterator ¶
func NewReverseIterator(n *Node) *ReverseIterator
NewReverseIterator returns a new ReverseIterator at a node
func (*ReverseIterator) Previous ¶
func (ri *ReverseIterator) Previous() ([]byte, interface{}, bool)
Previous returns the previous node in reverse order
func (*ReverseIterator) SeekPrefix ¶
func (ri *ReverseIterator) SeekPrefix(prefix []byte)
SeekPrefix is used to seek the iterator to a given prefix
func (*ReverseIterator) SeekPrefixWatch ¶
func (ri *ReverseIterator) SeekPrefixWatch(prefix []byte) (watch <-chan struct{})
SeekPrefixWatch is used to seek the iterator to a given prefix and returns the watch channel of the finest granularity
func (*ReverseIterator) SeekReverseLowerBound ¶
func (ri *ReverseIterator) SeekReverseLowerBound(key []byte)
SeekReverseLowerBound is used to seek the iterator to the largest key that is lower or equal to the given key. There is no watch variant as it's hard to predict based on the radix structure which node(s) changes might affect the result.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree implements an immutable radix tree. This can be treated as a Dictionary abstract data type. The main advantage over a standard hash map is prefix-based lookups and ordered iteration. The immutability means that it is safe to concurrently read from a Tree without any coordination.
func New ¶
func New() *Tree
New returns an empty Tree
func (*Tree) Delete ¶
Delete is used to delete a given key. Returns the new tree, old value if any, and a bool indicating if the key was set.
func (*Tree) DeletePrefix ¶
DeletePrefix is used to delete all nodes starting with a given prefix. Returns the new tree, and a bool indicating if the prefix matched any nodes
func (*Tree) Get ¶
Get is used to lookup a specific key, returning the value and if it was found
func (*Tree) Insert ¶
Insert is used to add or update a given key. The return provides the new tree, previous value and a bool indicating if any was set.
func (*Tree) Len ¶
Len is used to return the number of elements in the tree
func (*Tree) Root ¶
Root returns the root node of the tree which can be used for richer query operations.
func (*Tree) Txn ¶
Txn starts a new transaction that can be used to mutate the tree
type Txn ¶
type Txn struct {
// contains filtered or unexported fields
}
Txn is a transaction on the tree. This transaction is applied atomically and returns a new tree when committed. A transaction is not thread safe, and should only be used by a single goroutine.
func (*Txn) Clone ¶
Clone makes an independent copy of the transaction. The new transaction does not track any nodes and has TrackMutate turned off. The cloned transaction will contain any uncommitted writes in the original transaction but further mutations to either will be independent and result in different radix trees on Commit. A cloned transaction may be passed to another goroutine and mutated there independently however each transaction may only be mutated in a single thread.
func (*Txn) Commit ¶
Commit is used to finalize the transaction and return a new tree. If mutation tracking is turned on then notifications will also be issued.
func (*Txn) CommitOnly ¶
CommitOnly is used to finalize the transaction and return a new tree, but does not issue any notifications until Notify is called.
func (*Txn) Delete ¶
Delete is used to delete a given key. Returns the old value if any, and a bool indicating if the key was set.
func (*Txn) DeletePrefix ¶
DeletePrefix is used to delete an entire subtree that matches the prefix This will delete all nodes under that prefix
func (*Txn) Get ¶
Get is used to lookup a specific key, returning the value and if it was found
func (*Txn) GetWatch ¶
GetWatch is used to lookup a specific key, returning the watch channel, value and if it was found
func (*Txn) Insert ¶
Insert is used to add or update a given key. The return provides the previous value and a bool indicating if any was set.
func (*Txn) Notify ¶
func (t *Txn) Notify()
Notify is used along with TrackMutate to trigger notifications. This must only be done once a transaction is committed via CommitOnly, and it is called automatically by Commit.
func (*Txn) Root ¶
Root returns the current root of the radix tree within this transaction. The root is not safe across insert and delete operations, but can be used to read the current state during a transaction.
func (*Txn) TrackMutate ¶
TrackMutate can be used to toggle if mutations are tracked. If this is enabled then notifications will be issued for affected internal nodes and leaves when the transaction is committed.
type WalkFn ¶
WalkFn is used when walking the tree. Takes a key and value, returning if iteration should be terminated.
Source Files ¶
edges.go iradix.go iter.go node.go raw_iter.go reverse_iter.go
- Version
- v1.3.1 (latest)
- Published
- Jun 28, 2021
- Platform
- js/wasm
- Imports
- 4 packages
- Last checked
- now –
Tools for package owners.