Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make node constructors public, add RTree::new_from_root #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions rstar/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Unreleased

## Added
- Added `RTree::new_from_root`.

## Changed
- `ParentNode::new_root` and `ParentNode::new_parent` are now public.

# 0.11.0

## Added
Expand Down
6 changes: 4 additions & 2 deletions rstar/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ where
self.envelope.clone()
}

pub(crate) fn new_root<Params>() -> Self
/// Creates an empty root ParentNode.
pub fn new_root<Params>() -> Self
where
Params: RTreeParams,
{
Expand All @@ -95,7 +96,8 @@ where
}
}

pub(crate) fn new_parent(children: Vec<RTreeNode<T>>) -> Self {
/// Creates a ParentNode with the specified children.
pub fn new_parent(children: Vec<RTreeNode<T>>) -> Self {
let envelope = envelope_for_children(&children);

ParentNode { envelope, children }
Expand Down
26 changes: 26 additions & 0 deletions rstar/src/rtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,32 @@ where
Self::new_from_bulk_loading(elements, bulk_load::bulk_load_sequential::<_, Params>)
}

/// Creates a new r-tree from an existing root node. The size parameter must match the number of
/// leaves in the tree.
///
/// **Warning:** Manually constructed trees are **NOT** officially supported. You may only use
/// this method to load an r-tree previously constructed using this crate through a sequence of
/// safe operations such as [RTree::bulk_load], [RTree::insert], and [RTree::remove].
/// The leaf nodes' envelopes should match the envelopes of the items used to construct the
/// tree being loaded. Do not use this method to load a subtree of an r-tree as its own tree.
/// Failure to uphold any of the internal invariants will result in unexpected panics and
/// potentially incorrect behavior.
///
/// **Warning:** The tree with the specified root node must be a correct r-tree as produced by
/// the current version of this crate with the same compile time parameters. Forward and
/// backward compatibility is **NOT** guaranteed.
///
/// The tree's compile time parameters must be specified. Refer to the
/// [RTreeParams] trait for more information and a usage example.
pub fn new_from_root(root: ParentNode<T>, size: usize) -> Self {
verify_parameters::<T, Params>();
RTree {
root: root,
size: size,
_params: Default::default(),
}
}

/// Returns the number of objects in an r-tree.
///
/// # Example
Expand Down