load method
Bulk loads items into this r-tree.
This method returns this
to allow for this chaining:
RBushBase().load([...])
Implementation
RBushBase<T> load(Iterable<T> items) {
if (items.isEmpty) return this;
if (items.length < _minEntries) {
for (final item in items) insert(item);
return this;
}
// recursively build the tree with the given data from scratch using OMT algorithm
_RBushNode<T> node = _build(List.of(items), 0, items.length - 1, 0);
if (data.childrenLength == 0) {
// save as is if tree is empty
data = node;
} else if (data.height == node.height) {
// split root if trees have the same height
_splitRoot(data, node);
} else {
if (data.height < node.height) {
// swap trees if inserted one is bigger
final tmpNode = data;
data = node;
node = tmpNode;
}
// insert the small tree into the large tree at appropriate level
_insert(data.height - node.height - 1, inode: node);
}
return this;
}