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
added in
v0.6.0
func NewOptions ¶ added in v1.5.0
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 ¶ added in v1.7.0
func (*BTree) AscendHintMut ¶ added in v1.7.0
func (*BTree) Copy ¶ added in v0.4.0
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 ¶ added in v0.5.0
DeleteAt deletes the item at index. Return nil if the tree is empty or the index is out of bounds.
func (*BTree) DeleteHint ¶ added in v0.2.0
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 ¶ added in v1.7.0
func (*BTree) DescendHintMut ¶ added in v1.7.0
func (*BTree) DescendMut ¶ added in v1.6.0
func (*BTree) GetAt ¶ added in v0.5.0
GetAt returns the value at index. Return nil if the tree is empty or the index is out of bounds.
func (*BTree) Height ¶ added in v0.2.0
Height returns the height of the tree. Returns zero if tree has no items.
func (*BTree) Iter ¶ added in v1.1.0
Iter returns a read-only iterator. The Release method must be called finished with iterator.
func (*BTree) Less ¶ added in v0.2.1
Less is a convenience function that performs a comparison of two items using the same "less" function provided to New.
func (*BTree) Load ¶ added in v0.2.0
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 ¶ added in v0.2.0
PopMax removes the maximum item in tree and returns it. Returns nil if the tree has no items.
func (*BTree) PopMin ¶ added in v0.2.0
PopMin removes the minimum item in tree and returns it. Returns nil if the tree has no items.
func (*BTree) Set ¶ added in v0.2.0
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 ¶ added in v0.2.0
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 ¶ added in v1.4.1
type BTreeG[T any] struct { // contains filtered or unexported fields }
func NewBTreeGOptions ¶ added in v1.4.1
func (*BTreeG[T]) Ascend ¶ added in v1.4.1
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 ¶ added in v1.7.0
func (*BTreeG[T]) AscendHintMut ¶ added in v1.7.0
func (*BTreeG[T]) Copy ¶ added in v1.4.1
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 ¶ added in v1.4.1
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 ¶ added in v1.4.1
DeleteAt deletes the item at index. Return nil if the tree is empty or the index is out of bounds.
func (*BTreeG[T]) DeleteHint ¶ added in v1.4.1
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 ¶ added in v1.4.1
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 ¶ added in v1.7.0
func (*BTreeG[T]) DescendHintMut ¶ added in v1.7.0
func (*BTreeG[T]) DescendMut ¶ added in v1.6.0
func (*BTreeG[T]) GetAt ¶ added in v1.4.1
GetAt returns the value at index. Return nil if the tree is empty or the index is out of bounds.
func (*BTreeG[T]) GetHintMut ¶ added in v1.6.0
func (*BTreeG[T]) Height ¶ added in v1.4.1
Height returns the height of the tree. Returns zero if tree has no items.
func (*BTreeG[T]) Items ¶ added in v1.4.1
func (tr *BTreeG[T]) Items() []T
Items returns all the items in order.
func (*BTreeG[T]) Iter ¶ added in v1.4.1
Iter returns a read-only iterator. The Release method must be called finished with iterator.
func (*BTreeG[T]) Less ¶ added in v1.4.1
Less is a convenience function that performs a comparison of two items using the same "less" function provided to New.
func (*BTreeG[T]) Max ¶ added in v1.4.1
Max returns the maximum item in tree. Returns nil if the tree has no items.
func (*BTreeG[T]) Min ¶ added in v1.4.1
Min returns the minimum item in tree. Returns nil if the treex has no items.
func (*BTreeG[T]) PopMax ¶ added in v1.4.1
PopMax removes the maximum item in tree and returns it. Returns nil if the tree has no items.
func (*BTreeG[T]) PopMin ¶ added in v1.4.1
PopMin removes the minimum item in tree and returns it. Returns nil if the tree has no items.
func (*BTreeG[T]) ReverseMut ¶ added in v1.6.0
func (*BTreeG[T]) SetHint ¶ added in v1.4.1
SetHint sets or replace a value for a key using a path hint
type Generic
deprecated
added in
v1.2.0
Generic BTree
Deprecated: use BTreeG
func NewGeneric
deprecated
added in
v1.2.0
func NewGenericOptions
deprecated
added in
v1.2.0
type Iter ¶ added in v1.1.0
type Iter struct {
// contains filtered or unexported fields
}
Iter is an iterator for
func (*Iter) First ¶ added in v1.1.0
First moves iterator to first item in tree. Returns false if the tree is empty.
func (*Iter) Last ¶ added in v1.1.0
Last moves iterator to last item in tree. Returns false if the tree is empty.
func (*Iter) Next ¶ added in v1.1.0
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 ¶ added in v1.1.0
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 ¶ added in v1.1.0
func (iter *Iter) Release()
First moves iterator to first item in tree. Returns false if the tree is empty.
type IterG ¶ added in v1.6.0
type IterG[T any] struct { // contains filtered or unexported fields }
Iter represents an iterator
func (*IterG[T]) First ¶ added in v1.6.0
First moves iterator to first item in tree. Returns false if the tree is empty.
func (*IterG[T]) Item ¶ added in v1.6.0
func (iter *IterG[T]) Item() T
Item returns the current iterator item.
func (*IterG[T]) Last ¶ added in v1.6.0
Last moves iterator to last item in tree. Returns false if the tree is empty.
func (*IterG[T]) Next ¶ added in v1.6.0
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 ¶ added in v1.6.0
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 ¶ added in v1.2.0
type Map[K ordered, V any] struct { // contains filtered or unexported fields }
func (*Map[K, V]) Ascend ¶ added in v1.2.0
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 ¶ added in v1.2.0
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 ¶ added in v1.2.0
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 ¶ added in v1.2.0
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 ¶ added in v1.6.0
func (*Map[K, V]) GetAt ¶ added in v1.2.0
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 ¶ added in v1.6.0
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 ¶ added in v1.2.0
Height returns the height of the tree. Returns zero if tree has no items.
func (*Map[K, V]) KeyValues ¶ added in v1.2.0
func (tr *Map[K, V]) KeyValues() ([]K, []V)
KeyValues returns all the keys and values in order.
func (*Map[K, V]) KeyValuesMut ¶ added in v1.6.0
func (tr *Map[K, V]) KeyValuesMut() ([]K, []V)
func (*Map[K, V]) Keys ¶ added in v1.2.0
func (tr *Map[K, V]) Keys() []K
Keys returns all the keys in order.
func (*Map[K, V]) Max ¶ added in v1.2.0
Max returns the maximum item in tree. Returns nil if the tree has no items.
func (*Map[K, V]) Min ¶ added in v1.2.0
Min returns the minimum item in tree. Returns nil if the treex has no items.
func (*Map[K, V]) PopMax ¶ added in v1.2.0
PopMax removes the maximum item in tree and returns it. Returns nil if the tree has no items.
func (*Map[K, V]) PopMin ¶ added in v1.2.0
PopMin removes the minimum item in tree and returns it. Returns nil if the tree has no items.
func (*Map[K, V]) ReverseMut ¶ added in v1.6.0
type MapIter ¶ added in v1.2.0
type MapIter[K ordered, V any] struct { // contains filtered or unexported fields }
MapIter represents an iterator for btree.Map
func (*MapIter[K, V]) First ¶ added in v1.2.0
First moves iterator to first item in tree. Returns false if the tree is empty.
func (*MapIter[K, V]) Key ¶ added in v1.2.0
func (iter *MapIter[K, V]) Key() K
Key returns the current iterator item key.
func (*MapIter[K, V]) Last ¶ added in v1.2.0
Last moves iterator to last item in tree. Returns false if the tree is empty.
func (*MapIter[K, V]) Next ¶ added in v1.2.0
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 ¶ added in v1.2.0
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 ¶ added in v1.2.0
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 ¶ added in v0.2.2
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 ¶ added in v1.2.0
type Set[K ordered] struct {
// contains filtered or unexported fields
}
func (*Set[K]) Ascend ¶ added in v1.2.0
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 ¶ added in v1.2.0
DeleteAt deletes the item at index. Return nil if the tree is empty or the index is out of bounds.
func (*Set[K]) Descend ¶ added in v1.2.0
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 ¶ added in v1.2.0
GetAt returns the value at index. Return nil if the tree is empty or the index is out of bounds.
func (*Set[K]) Height ¶ added in v1.2.0
Height returns the height of the tree. Returns zero if tree has no items.
func (*Set[K]) Keys ¶ added in v1.3.0
func (tr *Set[K]) Keys() []K
Keys returns all the keys in order.
func (*Set[K]) Load ¶ added in v1.2.0
func (tr *Set[K]) Load(key K)
Load is for bulk loading pre-sorted items
func (*Set[K]) Max ¶ added in v1.2.0
Max returns the maximum item in tree. Returns nil if the tree has no items.
func (*Set[K]) Min ¶ added in v1.2.0
Min returns the minimum item in tree. Returns nil if the treex has no items.
func (*Set[K]) PopMax ¶ added in v1.2.0
PopMax removes the maximum item in tree and returns it. Returns nil if the tree has no items.
type SetIter ¶ added in v1.2.0
type SetIter[K ordered] struct {
// contains filtered or unexported fields
}
SetIter represents an iterator for btree.Set
func (*SetIter[K]) First ¶ added in v1.2.0
First moves iterator to first item in tree. Returns false if the tree is empty.
func (*SetIter[K]) Key ¶ added in v1.2.0
func (iter *SetIter[K]) Key() K
Key returns the current iterator item key.
func (*SetIter[K]) Last ¶ added in v1.2.0
Last moves iterator to last item in tree. Returns false if the tree is empty.
func (*SetIter[K]) Next ¶ added in v1.2.0
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.