- BTree`1
- #ctor(degree,comparer)
- #ctor(degree,f)
- Length
- Ascend(iterator)
- AscendGreaterOrEqual(pivot,iterator)
- AscendLessThan(pivot,iterator)
- AscendRange(greaterOrEqual,lessThan,iterator)
- Clear(addNodesToFreeList)
- Clone()
- Delete(item)
- DeleteMax()
- DeleteMin()
- Descend(iterator)
- DescendGreaterThan(pivot,iterator)
- DescendLessOrEqual(pivot,iterator)
- DescendRange(lessOrEqual,greaterThan,iterator)
- Get(key)
- Has(key)
- Max()
- MaxItems()
- Min()
- MinItems()
- ReplaceOrInsert(item)
- FreeList`1
- Int
- IntComparer
- ItemIterator`1
CodeExMachina
BTree is an implementation of a B-Tree.
BTree stores Item instances in an ordered structure, allowing easy insertion, removal, and iteration.
Write operations are not safe for concurrent mutation by multiple tasks, but Read operations are.
| Name | Description |
|---|---|
| T | The type of elements in the tree. |
Creates a new B-Tree with the given degree.
BTree(2), for example, will create a 2-3-4 tree (each node contains 1-3 items and 2-4 children).
| Name | Type | Description |
|---|---|---|
| degree | System.Int32 | |
| comparer | System.Collections.Generic.Comparer{`0} |
Creates a new B-Tree that uses the given node free list.
| Name | Type | Description |
|---|---|---|
| degree | System.Int32 | |
| f | CodeExMachina.FreeList{`0} |
Returns the number of items currently in the tree.
Calls the iterator for every value in the tree within the range [first, last], until iterator returns false.
| Name | Type | Description |
|---|---|---|
| iterator | CodeExMachina.ItemIterator{`0} |
Calls the iterator for every value in the tree within the range [pivot, last], until iterator returns false.
| Name | Type | Description |
|---|---|---|
| pivot | `0 | |
| iterator | CodeExMachina.ItemIterator{`0} |
Calls the iterator for every value in the tree within the range [first, pivot), until iterator returns false.
| Name | Type | Description |
|---|---|---|
| pivot | `0 | |
| iterator | CodeExMachina.ItemIterator{`0} |
Calls the iterator for every value in the tree within the range [greaterOrEqual, lessThan), until iterator returns false.
| Name | Type | Description |
|---|---|---|
| greaterOrEqual | `0 | |
| lessThan | `0 | |
| iterator | CodeExMachina.ItemIterator{`0} |
Removes all items from the btree. If addNodesToFreelist is true, t's nodes are added to its freelist as part of this call, until the freelist is full. Otherwise, the root node is simply dereferenced and the subtree left to Go's normal GC processes.
This can be much faster than calling Delete on all elements, because that requires finding/removing each element in the tree and updating the tree accordingly. It also is somewhat faster than creating a new tree to replace the old one, because nodes from the old tree are reclaimed into the freelist for use by the new one, instead of being lost to the garbage collector.
This call takes: O(1): when addNodesToFreelist is false, this is a single operation. O(1): when the freelist is already full, it breaks out immediately O(freelist size): when the freelist is empty and the nodes are all owned by this tree, nodes are added to the freelist until full. O(tree size): when all nodes are owned by another tree, all nodes are iterated over looking for nodes to add to the freelist, and due to ownership, none are.
| Name | Type | Description |
|---|---|---|
| addNodesToFreeList | System.Boolean |
Clone clones the btree, lazily. Clone should not be called concurrently, but the original tree (t) and the new tree (t2) can be used concurrently once the Clone call completes.
The internal tree structure of b is marked read-only and shared between t and t2. Writes to both t and t2 use copy-on-write logic, creating new nodes whenever one of b's original nodes would have been modified. Read operations should have no performance degredation. Write operations for both t and t2 will initially experience minor slow-downs caused by additional allocs and copies due to the aforementioned copy-on-write logic, but should converge to the original performance characteristics of the original tree.
This method has no parameters.
Removes an item equal to the passed in item from the tree, returning it. If no such item exists, returns nil.
| Name | Type | Description |
|---|---|---|
| item | `0 |
Removes the largest item in the tree and returns it. If no such item exists, returns nil.
This method has no parameters.
Removes the smallest item in the tree and returns it. If no such item exists, returns nil.
This method has no parameters.
Calls the iterator for every value in the tree within the range [last, first], until iterator returns false.
| Name | Type | Description |
|---|---|---|
| iterator | CodeExMachina.ItemIterator{`0} |
Calls the iterator for every value in the tree within the range [last, pivot), until iterator returns false.
| Name | Type | Description |
|---|---|---|
| pivot | `0 | |
| iterator | CodeExMachina.ItemIterator{`0} |
Calls the iterator for every value in the tree within the range [pivot, first], until iterator returns false.
| Name | Type | Description |
|---|---|---|
| pivot | `0 | |
| iterator | CodeExMachina.ItemIterator{`0} |
Calls the iterator for every value in the tree within the range [lessOrEqual, greaterThan), until iterator returns false.
| Name | Type | Description |
|---|---|---|
| lessOrEqual | `0 | |
| greaterThan | `0 | |
| iterator | CodeExMachina.ItemIterator{`0} |
Looks for the key item in the tree, returning it. It returns nil if unable to find that item.
| Name | Type | Description |
|---|---|---|
| key | `0 |
Returns true if the given key is in the tree.
| Name | Type | Description |
|---|---|---|
| key | `0 |
Returns the largest item in the tree, or nil if the tree is empty.
This method has no parameters.
Returns the max number of items to allow per node.
This method has no parameters.
Returns the smallest item in the tree, or nil if the tree is empty.
This method has no parameters.
Returns the min number of items to allow per node (ignored for the root node).
This method has no parameters.
Adds the given item to the tree. If an item in the tree already equals the given one, it is removed from the tree and returned. Otherwise, nil is returned.
nil cannot be added to the tree (will panic).
| Name | Type | Description |
|---|---|---|
| item | `0 |
CodeExMachina
FreeList represents a free list of btree nodes. By default each BTree has its own FreeList, but multiple BTrees can share the same FreeList. Two Btrees using the same freelist are safe for concurrent write access.
| Name | Description |
|---|---|
| T | The type of elements in the list. |
Creates a new free list with default size.
| Name | Type | Description |
|---|---|---|
| comparer | System.Collections.Generic.Comparer{`0} |
Creates a new free list.
| Name | Type | Description |
|---|---|---|
| size | System.Int32 | |
| comparer | System.Collections.Generic.Comparer{`0} |
CodeExMachina
Int implements the Item interface for integers.
CodeExMachina
Compare two Ints.
This must provide a strict weak ordering. If !(a < b) && !(b < a), we treat this to mean a == b (i.e. we can only hold one of either a or b in the tree).
CodeExMachina
ItemIterator allows callers of Ascend* to iterate in-order over portions of the tree. When this function returns false, iteration will stop and the associated Ascend* function will immediately return.
| Name | Type | Description |
|---|---|---|
| i | T:CodeExMachina.ItemIterator`1 |