Documentation
¶
Overview ¶
Copyright 2020 Joshua J Baker. All rights reserved. Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.
Package btree implements a B-Tree, Map, Set It's copied from https://github.com/tidwall/btree
Copyright 2020 Joshua J Baker. All rights reserved. Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.
Index ¶
- type BTree
- func (tr *BTree[T]) Ascend(pivot T, iter func(item T) bool)
- func (tr *BTree[T]) AscendMut(pivot T, iter func(item T) bool)
- func (tr *BTree[T]) Clear()
- func (tr *BTree[T]) Copy() *BTree[T]
- func (tr *BTree[T]) Delete(key T) (T, bool)
- func (tr *BTree[T]) DeleteAt(index int) (T, bool)
- func (tr *BTree[T]) DeleteHint(key T, hint *PathHint) (T, bool)
- func (tr *BTree[T]) DeleteMax() (T, bool)
- func (tr *BTree[T]) DeleteMin() (T, bool)
- func (tr *BTree[T]) Descend(pivot T, iter func(item T) bool)
- func (tr *BTree[T]) DescendMut(pivot T, iter func(item T) bool)
- func (tr *BTree[T]) Get(key T) (T, bool)
- func (tr *BTree[T]) GetAt(index int) (T, bool)
- func (tr *BTree[T]) GetAtMut(index int) (T, bool)
- func (tr *BTree[T]) GetHint(key T, hint *PathHint) (value T, ok bool)
- func (tr *BTree[T]) GetHintMut(key T, hint *PathHint) (value T, ok bool)
- func (tr *BTree[T]) GetMut(key T) (T, bool)
- func (tr *BTree[T]) Height() int
- func (tr *BTree[T]) IsoCopy() *BTree[T]
- func (tr *BTree[T]) ItemsMut() []T
- func (tr *BTree[T]) Len() int
- func (tr *BTree[T]) Load(item T) (T, bool)
- func (tr *BTree[T]) Max() (T, bool)
- func (tr *BTree[T]) MaxMut() (T, bool)
- func (tr *BTree[T]) Min() (T, bool)
- func (tr *BTree[T]) MinMut() (T, bool)
- func (tr *BTree[T]) ReverseScan(iter func(item T) bool)
- func (tr *BTree[T]) ReverseScanMut(iter func(item T) bool)
- func (tr *BTree[T]) Scan(iter func(item T) bool)
- func (tr *BTree[T]) ScanMut(iter func(item T) bool)
- func (tr *BTree[T]) SetHint(item T, hint *PathHint) (prev T, replaced bool)
- func (tr *BTree[T]) Upsert(item T) (T, bool)
- func (tr *BTree[T]) Values() []T
- func (tr *BTree[T]) Walk(iter func(item []T) bool)
- func (tr *BTree[T]) WalkMut(iter func(item []T) bool)
- type Map
- func (tr *Map[K, V]) Ascend(pivot K, iter func(key K, value V) bool)
- func (tr *Map[K, V]) AscendMut(pivot K, iter func(key K, value V) bool)
- func (tr *Map[K, V]) Clear()
- func (tr *Map[K, V]) Copy() *Map[K, V]
- func (tr *Map[K, V]) Delete(key K) (V, bool)
- func (tr *Map[K, V]) DeleteAt(index int) (K, V, bool)
- func (tr *Map[K, V]) Descend(pivot K, iter func(key K, value V) bool)
- func (tr *Map[K, V]) DescendMut(pivot K, iter func(key K, value V) bool)
- func (tr *Map[K, V]) Get(key K) (V, bool)
- func (tr *Map[K, V]) GetAt(index int) (K, V, bool)
- func (tr *Map[K, V]) GetAtMut(index int) (K, V, bool)
- func (tr *Map[K, V]) GetMut(key K) (V, bool)
- func (tr *Map[K, V]) Height() int
- func (tr *Map[K, V]) IsoCopy() *Map[K, V]
- func (tr *Map[K, V]) KeyValues() ([]K, []V)
- func (tr *Map[K, V]) KeyValuesMut() ([]K, []V)
- func (tr *Map[K, V]) Keys() []K
- func (tr *Map[K, V]) Len() int
- func (tr *Map[K, V]) Load(key K, value V) (V, bool)
- func (tr *Map[K, V]) Max() (K, V, bool)
- func (tr *Map[K, V]) MaxMut() (K, V, bool)
- func (tr *Map[K, V]) Min() (K, V, bool)
- func (tr *Map[K, V]) MinMut() (K, V, bool)
- func (tr *Map[K, V]) PopMax() (K, V, bool)
- func (tr *Map[K, V]) PopMin() (K, V, bool)
- func (tr *Map[K, V]) Reverse(iter func(key K, value V) bool)
- func (tr *Map[K, V]) ReverseMut(iter func(key K, value V) bool)
- func (tr *Map[K, V]) Scan(iter func(key K, value V) bool)
- func (tr *Map[K, V]) ScanMut(iter func(key K, value V) bool)
- func (tr *Map[K, V]) Set(key K, value V) (V, bool)
- func (tr *Map[K, V]) Values() []V
- func (tr *Map[K, V]) ValuesMut() []V
- type Options
- type PathHint
- type Set
- func (tr *Set[K]) Ascend(pivot K, iter func(key K) bool)
- func (tr *Set[K]) Clear()
- func (tr *Set[K]) Copy() *Set[K]
- func (tr *Set[K]) Delete(key K)
- func (tr *Set[K]) DeleteAt(index int) (K, bool)
- func (tr *Set[K]) DeleteMax() (K, bool)
- func (tr *Set[K]) DeleteMin() (K, bool)
- func (tr *Set[K]) Descend(pivot K, iter func(key K) bool)
- func (tr *Set[K]) GetAt(index int) (K, bool)
- func (tr *Set[K]) Has(key K) bool
- func (tr *Set[K]) Height() int
- func (tr *Set[K]) Insert(key K)
- func (tr *Set[K]) IsoCopy() *Set[K]
- func (tr *Set[K]) Keys() []K
- func (tr *Set[K]) Len() int
- func (tr *Set[K]) Load(key K)
- func (tr *Set[K]) Max() (K, bool)
- func (tr *Set[K]) Min() (K, bool)
- func (tr *Set[K]) Reverse(iter func(key K) bool)
- func (tr *Set[K]) Scan(iter func(key K) bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BTree ¶
type BTree[T any] struct { // contains filtered or unexported fields }
func NewBTreeFunc ¶
func (*BTree[T]) Ascend ¶
Ascend the tree within the range [pivot, last] Pass nil for pivot to scan all item in ascending order Return false to stop iterating
func (*BTree[T]) Copy ¶
Copy the tree. This is a copy-on-write operation and is very fast because it only performs a shadowed copy.
func (*BTree[T]) Delete ¶
Delete a value for a key and returns the deleted value. Returns false if there was no value by that key found.
func (*BTree[T]) DeleteAt ¶
DeleteAt deletes the item at index. Return nil if the tree is empty or the index is out of bounds.
func (*BTree[T]) DeleteHint ¶
DeleteHint deletes a value for a key using a path hint and returns the deleted value. Returns false if there was no value by that key found.
func (*BTree[T]) DeleteMax ¶
DeleteMax removes the maximum item in tree and returns it. Returns nil if the tree has no items.
func (*BTree[T]) DeleteMin ¶
DeleteMin removes the minimum item in tree and returns it. Returns nil if the tree has no items.
func (*BTree[T]) Descend ¶
Descend the tree within the range [pivot, first] Pass nil for pivot to scan all item in descending order Return false to stop iterating
func (*BTree[T]) DescendMut ¶
func (*BTree[T]) GetAt ¶
GetAt returns the value at index. Return nil if the tree is empty or the index is out of bounds.
func (*BTree[T]) GetHintMut ¶
func (*BTree[T]) ReverseScan ¶
func (*BTree[T]) ReverseScanMut ¶
func (*BTree[T]) Upsert ¶
Upsert replaces or inserts if the item doesn't exist. It returns the replaced item and whether it's replaced or not.
type Map ¶
func (*Map[K, V]) Ascend ¶
Ascend the tree within the range [pivot, last] Pass nil for pivot to scan all item in ascending order Return false to stop iterating
func (*Map[K, V]) Delete ¶
Delete a value for a key and returns the deleted value. Returns false if there was no value by that key found.
func (*Map[K, V]) DeleteAt ¶
DeleteAt deletes the item at index. Return nil if the tree is empty or the index is out of bounds.
func (*Map[K, V]) Descend ¶
Descend the tree within the range [pivot, first] Pass nil for pivot to scan all item in descending order Return false to stop iterating
func (*Map[K, V]) DescendMut ¶
func (*Map[K, V]) GetAt ¶
GetAt returns the value at index. Return nil if the tree is empty or the index is out of bounds.
func (*Map[K, V]) GetMut ¶
GetMut gets a value for key. If needed, this may perform a copy the resulting value before returning.
Mut methods are only useful when all of the following are true:
- The interior data of the value requires changes.
- The value is a pointer type.
- The BTree has been copied using `Copy()` or `IsoCopy()`.
- The value itself has a `Copy()` or `IsoCopy()` method.
Mut methods may modify the tree structure and should have the same considerations as other mutable operations like Set, Delete, Clear, etc.
func (*Map[K, V]) Height ¶
Height returns the height of the tree. Returns zero if tree has no items.
func (*Map[K, V]) KeyValues ¶
func (tr *Map[K, V]) KeyValues() ([]K, []V)
KeyValues returns all the keys and values in order.
func (*Map[K, V]) KeyValuesMut ¶
func (tr *Map[K, V]) KeyValuesMut() ([]K, []V)
func (*Map[K, V]) Min ¶
Min returns the minimum item in tree. Returns nil if the treex has no items.
func (*Map[K, V]) PopMax ¶
PopMax removes the maximum item in tree and returns it. Returns nil if the tree has no items.
func (*Map[K, V]) PopMin ¶
PopMin removes the minimum item in tree and returns it. Returns nil if the tree has no items.
func (*Map[K, V]) ReverseMut ¶
type Options ¶
type Options struct { // Degree is used to define how many items and children each internal node // can contain before it must branch. For example, a degree of 2 will // create a 2-3-4 tree, where each node may contains 1-3 items and // 2-4 children. See https://en.wikipedia.org/wiki/2–3–4_tree. // Default is 32 Degree int }
Options for passing to New when creating a new BTree.
type PathHint ¶
type PathHint struct {
// contains filtered or unexported fields
}
PathHint is a utility type used with the *Hint() functions. Hints provide faster operations for clustered keys.
type Set ¶
func (*Set[K]) Ascend ¶
Ascend the tree within the range [pivot, last] Pass nil for pivot to scan all item in ascending order Return false to stop iterating
func (*Set[K]) DeleteAt ¶
DeleteAt deletes the item at index. Return nil if the tree is empty or the index is out of bounds.
func (*Set[K]) DeleteMax ¶
PopMax removes the maximum item in tree and returns it. Returns nil if the tree has no items.
func (*Set[K]) DeleteMin ¶
DeleteMin removes the minimum item in tree and returns it. Returns nil if the tree has no items.
func (*Set[K]) Descend ¶
Descend the tree within the range [pivot, first] Pass nil for pivot to scan all item in descending order Return false to stop iterating
func (*Set[K]) GetAt ¶
GetAt returns the value at index. Return nil if the tree is empty or the index is out of bounds.