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.
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.
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) Ascend(pivot any, iter func(item any) bool)
- func (tr *BTree) AscendHint(pivot any, iter func(item any) bool, hint *PathHint)
- func (tr *BTree) AscendHintMut(pivot any, iter func(item any) bool, hint *PathHint)
- func (tr *BTree) AscendMut(pivot any, iter func(item any) bool)
- func (tr *BTree) Clear()
- func (tr *BTree) Copy() *BTree
- func (tr *BTree) Delete(key any) (prev any)
- func (tr *BTree) DeleteAt(index int) any
- func (tr *BTree) DeleteHint(key any, hint *PathHint) (prev any)
- func (tr *BTree) Descend(pivot any, iter func(item any) bool)
- func (tr *BTree) DescendHint(pivot any, iter func(item any) bool, hint *PathHint)
- func (tr *BTree) DescendHintMut(pivot any, iter func(item any) bool, hint *PathHint)
- func (tr *BTree) DescendMut(pivot any, iter func(item any) bool)
- func (tr *BTree) Get(key any) any
- func (tr *BTree) GetAt(index int) any
- func (tr *BTree) GetAtMut(index int) any
- func (tr *BTree) GetHint(key any, hint *PathHint) any
- func (tr *BTree) GetHintMut(key any, hint *PathHint) any
- func (tr *BTree) GetMut(key any) any
- func (tr *BTree) Height() int
- func (tr *BTree) IsoCopy() *BTree
- func (tr *BTree) Iter() Iter
- func (tr *BTree) IterMut() Iter
- func (tr *BTree) Len() int
- func (tr *BTree) Less(a, b any) bool
- func (tr *BTree) Load(item any) (prev any)
- func (tr *BTree) Max() any
- func (tr *BTree) MaxMut() any
- func (tr *BTree) Min() any
- func (tr *BTree) MinMut() any
- func (tr *BTree) PopMax() any
- func (tr *BTree) PopMin() any
- func (tr *BTree) Set(item any) (prev any)
- func (tr *BTree) SetHint(item any, hint *PathHint) (prev any)
- func (tr *BTree) Walk(iter func(items []any))
- func (tr *BTree) WalkMut(iter func(items []any))
- type BTreeG
- func (tr *BTreeG[T]) Ascend(pivot T, iter func(item T) bool)
- func (tr *BTreeG[T]) AscendHint(pivot T, iter func(item T) bool, hint *PathHint)
- func (tr *BTreeG[T]) AscendHintMut(pivot T, iter func(item T) bool, hint *PathHint)
- func (tr *BTreeG[T]) AscendMut(pivot T, iter func(item T) bool)
- func (tr *BTreeG[T]) Clear()
- func (tr *BTreeG[T]) Copy() *BTreeG[T]
- func (tr *BTreeG[T]) Delete(key T) (T, bool)
- func (tr *BTreeG[T]) DeleteAt(index int) (T, bool)
- func (tr *BTreeG[T]) DeleteHint(key T, hint *PathHint) (T, bool)
- func (tr *BTreeG[T]) Descend(pivot T, iter func(item T) bool)
- func (tr *BTreeG[T]) DescendHint(pivot T, iter func(item T) bool, hint *PathHint)
- func (tr *BTreeG[T]) DescendHintMut(pivot T, iter func(item T) bool, hint *PathHint)
- func (tr *BTreeG[T]) DescendMut(pivot T, iter func(item T) bool)
- func (tr *BTreeG[T]) Get(key T) (T, bool)
- func (tr *BTreeG[T]) GetAt(index int) (T, bool)
- func (tr *BTreeG[T]) GetAtMut(index int) (T, bool)
- func (tr *BTreeG[T]) GetHint(key T, hint *PathHint) (value T, ok bool)
- func (tr *BTreeG[T]) GetHintMut(key T, hint *PathHint) (value T, ok bool)
- func (tr *BTreeG[T]) GetMut(key T) (T, bool)
- func (tr *BTreeG[T]) Height() int
- func (tr *BTreeG[T]) IsoCopy() *BTreeG[T]
- func (tr *BTreeG[T]) Items() []T
- func (tr *BTreeG[T]) ItemsMut() []T
- func (tr *BTreeG[T]) Iter() IterG[T]
- func (tr *BTreeG[T]) IterMut() IterG[T]
- func (tr *BTreeG[T]) Len() int
- func (tr *BTreeG[T]) Less(a, b T) bool
- func (tr *BTreeG[T]) Load(item T) (T, bool)
- func (tr *BTreeG[T]) Max() (T, bool)
- func (tr *BTreeG[T]) MaxMut() (T, bool)
- func (tr *BTreeG[T]) Min() (T, bool)
- func (tr *BTreeG[T]) MinMut() (T, bool)
- func (tr *BTreeG[T]) PopMax() (T, bool)
- func (tr *BTreeG[T]) PopMin() (T, bool)
- func (tr *BTreeG[T]) Reverse(iter func(item T) bool)
- func (tr *BTreeG[T]) ReverseMut(iter func(item T) bool)
- func (tr *BTreeG[T]) Scan(iter func(item T) bool)
- func (tr *BTreeG[T]) ScanMut(iter func(item T) bool)
- func (tr *BTreeG[T]) Set(item T) (T, bool)
- func (tr *BTreeG[T]) SetHint(item T, hint *PathHint) (prev T, replaced bool)
- func (tr *BTreeG[T]) Walk(iter func(item []T) bool)
- func (tr *BTreeG[T]) WalkMut(iter func(item []T) bool)
- type Genericdeprecated
- type Iter
- type IterG
- 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]) Iter() MapIter[K, V]
- func (tr *Map[K, V]) IterMut() MapIter[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 MapIter
- 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]) Contains(key K) bool
- 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]) Descend(pivot K, iter func(key K) bool)
- func (tr *Set[K]) GetAt(index int) (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]) Iter() SetIter[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]) PopMax() (K, bool)
- func (tr *Set[K]) PopMin() (K, bool)
- func (tr *Set[K]) Reverse(iter func(key K) bool)
- func (tr *Set[K]) Scan(iter func(key K) bool)
- type SetIter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BTree ¶
type BTree struct {
// contains filtered or unexported fields
}
func NewNonConcurrent
deprecated
func NewOptions ¶
NewOptions returns a new BTree
func (*BTree) 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) AscendHint ¶
func (*BTree) AscendHintMut ¶
func (*BTree) Copy ¶
Copy the tree. This is a copy-on-write operation and is very fast because it only performs a shadowed copy.
func (*BTree) Delete ¶
Delete an item for a key. Returns the deleted value or nil if the key was not found.
func (*BTree) DeleteAt ¶
DeleteAt deletes the item at index. Return nil if the tree is empty or the index is out of bounds.
func (*BTree) DeleteHint ¶
DeleteHint deletes a value for a key using a path hint Returns the deleted value or nil if the key was not found.
func (*BTree) 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) DescendHint ¶
func (*BTree) DescendHintMut ¶
func (*BTree) GetAt ¶
GetAt returns the value at index. Return nil if the tree is empty or the index is out of bounds.
func (*BTree) Iter ¶
Iter returns a read-only iterator. The Release method must be called finished with iterator.
func (*BTree) Less ¶
Less is a convenience function that performs a comparison of two items using the same "less" function provided to New.
func (*BTree) Load ¶
Load is for bulk loading pre-sorted items If the load replaces and existing item then the value for the replaced item is returned.
func (*BTree) PopMax ¶
PopMax removes the maximum item in tree and returns it. Returns nil if the tree has no items.
func (*BTree) PopMin ¶
PopMin removes the minimum item in tree and returns it. Returns nil if the tree has no items.
func (*BTree) Set ¶
Set or replace a value for a key Returns the value for the replaced item or nil if the key was not found.
func (*BTree) SetHint ¶
SetHint sets or replace a value for a key using a path hint Returns the value for the replaced item or nil if the key was not found.
type BTreeG ¶
type BTreeG[T any] struct { // contains filtered or unexported fields }
func NewBTreeGOptions ¶
func (*BTreeG[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 (*BTreeG[T]) AscendHint ¶
func (*BTreeG[T]) AscendHintMut ¶
func (*BTreeG[T]) Copy ¶
Copy the tree. This is a copy-on-write operation and is very fast because it only performs a shadowed copy.
func (*BTreeG[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 (*BTreeG[T]) DeleteAt ¶
DeleteAt deletes the item at index. Return nil if the tree is empty or the index is out of bounds.
func (*BTreeG[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 (*BTreeG[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 (*BTreeG[T]) DescendHint ¶
func (*BTreeG[T]) DescendHintMut ¶
func (*BTreeG[T]) DescendMut ¶
func (*BTreeG[T]) GetAt ¶
GetAt returns the value at index. Return nil if the tree is empty or the index is out of bounds.
func (*BTreeG[T]) GetHintMut ¶
func (*BTreeG[T]) Height ¶
Height returns the height of the tree. Returns zero if tree has no items.
func (*BTreeG[T]) Iter ¶
Iter returns a read-only iterator. The Release method must be called finished with iterator.
func (*BTreeG[T]) Less ¶
Less is a convenience function that performs a comparison of two items using the same "less" function provided to New.
func (*BTreeG[T]) Min ¶
Min returns the minimum item in tree. Returns nil if the treex has no items.
func (*BTreeG[T]) PopMax ¶
PopMax removes the maximum item in tree and returns it. Returns nil if the tree has no items.
func (*BTreeG[T]) PopMin ¶
PopMin removes the minimum item in tree and returns it. Returns nil if the tree has no items.
func (*BTreeG[T]) ReverseMut ¶
type Generic
deprecated
type Iter ¶
type Iter struct {
// contains filtered or unexported fields
}
Iter is an iterator for
func (*Iter) First ¶
First moves iterator to first item in tree. Returns false if the tree is empty.
func (*Iter) Next ¶
Next moves iterator to the next item in iterator. Returns false if the tree is empty or the iterator is at the end of the tree.
func (*Iter) Prev ¶
Prev moves iterator to the previous item in iterator. Returns false if the tree is empty or the iterator is at the beginning of the tree.
func (*Iter) Release ¶
func (iter *Iter) Release()
First moves iterator to first item in tree. Returns false if the tree is empty.
type IterG ¶
type IterG[T any] struct { // contains filtered or unexported fields }
Iter represents an iterator
func (*IterG[T]) First ¶
First moves iterator to first item in tree. Returns false if the tree is empty.
func (*IterG[T]) Last ¶
Last moves iterator to last item in tree. Returns false if the tree is empty.
func (*IterG[T]) Next ¶
Next moves iterator to the next item in iterator. Returns false if the tree is empty or the iterator is at the end of the tree.
func (*IterG[T]) Prev ¶
Prev moves iterator to the previous item in iterator. Returns false if the tree is empty or the iterator is at the beginning of the tree.
type Map ¶
type Map[K ordered, V any] struct { // contains filtered or unexported fields }
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 MapIter ¶
type MapIter[K ordered, V any] struct { // contains filtered or unexported fields }
MapIter represents an iterator for btree.Map
func (*MapIter[K, V]) First ¶
First moves iterator to first item in tree. Returns false if the tree is empty.
func (*MapIter[K, V]) Key ¶
func (iter *MapIter[K, V]) Key() K
Key returns the current iterator item key.
func (*MapIter[K, V]) Last ¶
Last moves iterator to last item in tree. Returns false if the tree is empty.
func (*MapIter[K, V]) Next ¶
Next moves iterator to the next item in iterator. Returns false if the tree is empty or the iterator is at the end of the tree.
func (*MapIter[K, V]) Prev ¶
Prev moves iterator to the previous item in iterator. Returns false if the tree is empty or the iterator is at the beginning of the tree.
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 // NoLocks will disable locking. Otherwide a sync.RWMutex is used to // ensure all operations are safe across multiple goroutines. NoLocks bool }
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 ¶
type Set[K ordered] struct {
// contains filtered or unexported fields
}
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]) 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.
func (*Set[K]) PopMax ¶
PopMax removes the maximum item in tree and returns it. Returns nil if the tree has no items.
type SetIter ¶
type SetIter[K ordered] struct {
// contains filtered or unexported fields
}
SetIter represents an iterator for btree.Set
func (*SetIter[K]) First ¶
First moves iterator to first item in tree. Returns false if the tree is empty.
func (*SetIter[K]) Last ¶
Last moves iterator to last item in tree. Returns false if the tree is empty.
func (*SetIter[K]) Next ¶
Next moves iterator to the next item in iterator. Returns false if the tree is empty or the iterator is at the end of the tree.