Documentation ¶
Index ¶
- type Cmp
- type Enumerator
- type Tree
- func (t *Tree) Clear()
- func (t *Tree) Delete(k key) (ok bool)
- func (t *Tree) First() (k key, v value)
- func (t *Tree) Get(k key) (v value, ok bool)
- func (t *Tree) Last() (k key, v value)
- func (t *Tree) Len() int
- func (t *Tree) Put(k key, upd func(oldV value, exists bool) (newV value, write bool)) (oldV value, written bool)
- func (t *Tree) Seek(k key) (e *Enumerator, ok bool)
- func (t *Tree) SeekFirst() (e *Enumerator, err error)
- func (t *Tree) SeekLast() (e *Enumerator, err error)
- func (t *Tree) Set(k key, v value)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cmp ¶
type Cmp func(a, b key) int
Cmp compares a and b. Return value is:
< 0 if a < b 0 if a == b > 0 if a > b
type Enumerator ¶
type Enumerator struct {
// contains filtered or unexported fields
}
Enumerator captures the state of enumerating a tree. It is returned from the Seek* methods. The enumerator is aware of any mutations made to the tree in the process of enumerating it and automatically resumes the enumeration at the proper key, if possible.
However, once an Enumerator returns io.EOF to signal "no more items", it does no more attempt to "resync" on tree mutation(s). In other words, io.EOF from an Enumaretor is "sticky" (idempotent).
func (*Enumerator) Next ¶
func (e *Enumerator) Next() (k key, v value, err error)
Next returns the currently enumerated item, if it exists and moves to the next item in the key collation order. If there is no item to return, err == io.EOF is returned.
func (*Enumerator) Prev ¶
func (e *Enumerator) Prev() (k key, v value, err error)
Prev returns the currently enumerated item, if it exists and moves to the previous item in the key collation order. If there is no item to return, err == io.EOF is returned.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is a B+tree.
func TreeNew ¶
TreeNew returns a newly created, empty Tree. The compare function is used for key collation.
func (*Tree) Delete ¶
Delete removes the k's KV pair, if it exists, in which case Delete returns true.
func (*Tree) First ¶
func (t *Tree) First() (k key, v value)
First returns the first item of the tree in the key collating order, or (zero-value, zero-value) if the tree is empty.
func (*Tree) Get ¶
Get returns the value associated with k and true if it exists. Otherwise Get returns (zero-value, false).
func (*Tree) Last ¶
func (t *Tree) Last() (k key, v value)
Last returns the last item of the tree in the key collating order, or (zero-value, zero-value) if the tree is empty.
func (*Tree) Put ¶
func (t *Tree) Put(k key, upd func(oldV value, exists bool) (newV value, write bool)) (oldV value, written bool)
Put combines Get and Set in a more efficient way where the tree is walked only once. The upd(ater) receives (old-value, true) if a KV pair for k exists or (zero-value, false) otherwise. It can then return a (new-value, true) to create or overwrite the existing value in the KV pair, or (whatever, false) if it decides not to create or not to update the value of the KV pair.
tree.Set(k, v) conceptually equals tree.Put(k, func(k, v []byte){ return v, true }([]byte, bool))
modulo the differing return values.
func (*Tree) Seek ¶
func (t *Tree) Seek(k key) (e *Enumerator, ok bool)
Seek returns an Enumerator positioned on a an item such that k >= item's key. ok reports if k == item.key The Enumerator's position is possibly after the last item in the tree.
func (*Tree) SeekFirst ¶
func (t *Tree) SeekFirst() (e *Enumerator, err error)
SeekFirst returns an enumerator positioned on the first KV pair in the tree, if any. For an empty tree, err == io.EOF is returned and e will be nil.
func (*Tree) SeekLast ¶
func (t *Tree) SeekLast() (e *Enumerator, err error)
SeekLast returns an enumerator positioned on the last KV pair in the tree, if any. For an empty tree, err == io.EOF is returned and e will be nil.