Initializes an empty B+ tree.
Optional
entries: Iterable<[K, V]>The initial key value pairs.
Optional
compareFn: Comparer<any>Custom function to compare pairs of elements in the tree. If not specified, defaultComparator will be used which is valid as long as K extends DefaultComparable.
Optional
maxNodeSize: number = 64Branching factor (maximum items or children per node) Must be in range 4..256. If undefined or <4 then default is used; if >256 then 256.
provides a total order over keys (and a strict partial order over the type K)
a negative value if a < b, 0 if a === b and a positive value if a > b
Gets the height of the tree: the number of internal nodes between the BTree object and its leaf nodes (zero if there are no internal nodes).
Returns the maximum number of children/values before nodes will split.
Gets the number of key-value pairs in the tree.
Returns the key-value pair associated with the supplied key if it exists or the pair associated with the next lower pair otherwise. If there is no next lower pair, undefined is returned.
The key to search for.
Optional
reusedArray: [K, V]Optional array used repeatedly to store key-value pairs, to avoid creating a new array each time you call this method.
Returns an iterator that provides items in order (ascending order if the collection's comparator uses ascending order, as is the default.)
Optional
lowestKey: KFirst key to be iterated, or undefined to start at minKey(). If the specified key doesn't exist then iteration starts at the next higher key (according to the comparator).
Optional
reusedArray: (K | V)[]Optional array used repeatedly to store key-value pairs, to avoid creating a new array on every iteration.
Adds all pairs from a list of key-value pairs.
The number of pairs added to the collection.
Computational complexity: O(pairs.length * log(size + pairs.length))
Pairs to add to this tree. If there are duplicate keys, later pairs currently overwrite earlier ones (e.g. [[0,1],[0,7]] associates 0 with 7.)
Returns the key-value pair associated with the supplied key if it exists or the pair associated with the next lower pair otherwise. If there is no next lower pair, undefined is returned.
The key to search for.
Optional
reusedArray: [K, V]Optional array used repeatedly to store key-value pairs, to avoid creating a new array each time you call this method.
Makes the object read-only to ensure it is not accidentally modified. Freezing does not have to be permanent; unfreeze() reverses the effect. This is accomplished by replacing mutator functions with a function that throws an Error. Compared to using a property (e.g. this.isFrozen) this implementation gives better performance in non-frozen BTrees.
Builds an array of pairs from the specified range of keys, sorted by key. Each returned pair is also an array: pair[0] is the key, pair[1] is the value.
Computational complexity: O(result.length + log size)
The first key in the array will be greater than or equal to low
.
This method returns when a key larger than this is reached.
Optional
includeHigh: booleanIf the high
key is present, its pair will be included
in the output if and only if this parameter is true. Note: if the
low
key is present, it is always included in the output.
Length limit. getRange will stop scanning the tree when the array reaches this size.
Returns the next pair whose key is larger than the specified key (or undefined if there is none). If key === undefined, this function returns the lowest pair.
The key to search for.
Optional
reusedArray: [K, V]Optional array used repeatedly to store key-value pairs, to avoid creating a new array on every iteration.
Scans the specified range of keys, in ascending order by key.
Note: the callback onFound
must not insert or remove items in the
collection. Doing so may cause incorrect data to be sent to the
callback afterward.
The number of values found, or R if the callback returned
{done:R}
to stop early.
Computational complexity: O(number of items scanned + log size)
The first key scanned will be greater than or equal to low
.
Scanning stops when a key larger than this is reached.
If the high
key is present, onFound
is called for
that final pair if and only if this parameter is true.
Optional
onFound: Iteratee<K, V, any>A function that is called for each key-value pair. This function can return {done:R} to stop early with result R.
Optional
initialCounter: numberInitial third argument of onFound. This value
increases by one each time onFound
is called. Default: 0
Scans and potentially modifies values for a subsequence of keys.
Note: the callback onFound
should ideally be a pure function.
Specifically, it must not insert items, call clone(), or change
the collection except via return value; out-of-band editing may
cause an exception or may cause incorrect data to be sent to
the callback (duplicate or missed items). It must not cause a
clone() of the collection, otherwise the clone could be modified
by changes requested by the callback.
The number of values scanned, or R if the callback returned
{done:R}
to stop early.
Computational complexity: O(number of items scanned + log size)
Note: if the tree has been cloned with clone(), any shared
nodes are copied before onFound
is called. This takes O(n) time
where n is proportional to the amount of shared data scanned.
The first key scanned will be greater than or equal to low
.
Scanning stops when a key larger than this is reached.
If the high
key is present, onFound
is called for
that final pair if and only if this parameter is true.
A function that is called for each key-value pair. This
function can return {value:v}
to change the value associated
with the current key, {delete:true}
to delete the current pair,
{done:R}
to stop early with result R, or it can return nothing
(undefined or {}) to cause no effect and continue iterating.
{done:R}
can be combined with one of the other two commands.
The third argument counter
is the number of items iterated
previously; it equals 0 when onFound
is called the first time.
Optional
initialCounter: numberRemoves a range of key-value pairs from the B+ tree.
The number of key-value pairs that were deleted.
Computational complexity: O(log size + number of items deleted)
The first key scanned will be greater than or equal to low
.
Scanning stops when a key larger than this is reached.
Specifies whether the high
key, if present, is deleted.
Returns an iterator that provides items in reversed order.
Optional
highestKey: KKey at which to start iterating, or undefined to start at maxKey(). If the specified key doesn't exist then iteration starts at the next lower key (according to the comparator).
Optional
reusedArray: (K | V)[]Optional array used repeatedly to store key-value pairs, to avoid creating a new array on every iteration.
Optional
skipHighest: booleanIff this flag is true and the highestKey exists in the collection, the pair matching highestKey is skipped, not iterated.
Adds or overwrites a key-value pair in the B+ tree.
true if a new key-value pair was added.
Computational complexity: O(log size) Note: when overwriting a previous entry, the key is updated as well as the value. This has no effect unless the new key has data that does not affect its sort order.
the key is used to determine the sort order of data in the tree.
data to associate with the key (optional)
Returns the next pair whose key is smaller than the specified key (or undefined if there is none). If key === undefined, this function returns the highest pair.
The key to search for.
Optional
reusedArray: [K, V]Optional array used repeatedly to store key-value pairs, to avoid creating a new array each time you call this method.
Generated using TypeDoc
A mapping is a Collection indexed by keys that may have associated values.
Abstract
Template
V