pub struct Tree<V, S, T, const CHILDREN: usize> { /* private fields */ }Expand description
A generic “grid tree” which can be either a quadtree or an octree depending on the type parameters.
Implementations
The maximum number of children a branch node can have. 4 for a quadtree and 8 for an octree.
This constructor is only necessary if you need to use a custom shape S or vector V. Otherwise use the constructor
for OctreeI32 or QuadtreeI32.
Safety
You must guarantee that S correctly linearizes V vectors so that they don’t go out of array bounds in a block.
Refer to QuadtreeShapeI32 and OctreeShapeI32 for examples.
The Level where root nodes live.
Returns the unique root at self.root_level() that is an ancestor of descendant_key.
Iterate over all root keys.
Iterate over all root nodes.
Returns true iff this tree contains a node for ptr.
Returns true iff this tree contains a root node at coords.
Safety
The node for ptr must exist.
Safety
The node for ptr must exist.
Inserts value at the root node at key. Returns the old value.
Gets the root pointer or calls filler to insert a value first.
pub fn insert_child(
&mut self,
parent_ptr: NodePtr,
child_index: ChildIndex,
child_value: T
) -> (NodePtr, Option<T>)
pub fn insert_child(
&mut self,
parent_ptr: NodePtr,
child_index: ChildIndex,
child_value: T
) -> (NodePtr, Option<T>)
Inserts a child node of parent_ptr storing child_value. Returns the old child value if one exists.
Same as insert_child but child_offset is linearized into a ChildIndex based on the BranchShape.
This means any given coordinate in child_offset can only be 0 or 1!
pub fn fill_tree_from_root(
&mut self,
root_key: NodeKey<V>,
min_level: Level,
filler: impl FnMut(NodeKey<V>, &mut NodeEntry<'_, T, CHILDREN>) -> VisitCommand
)
pub fn fill_tree_from_root(
&mut self,
root_key: NodeKey<V>,
min_level: Level,
filler: impl FnMut(NodeKey<V>, &mut NodeEntry<'_, T, CHILDREN>) -> VisitCommand
)
Equivalent to calling fill_root and then fill_descendants of that root.
May return the RootNode for convenience.
pub fn child_entry(
&mut self,
parent_ptr: NodePtr,
child_index: ChildIndex
) -> NodeEntry<'_, T, CHILDREN>
pub fn child_entry(
&mut self,
parent_ptr: NodePtr,
child_index: ChildIndex
) -> NodeEntry<'_, T, CHILDREN>
Panics
- If
parent_ptris at level 0 and hence cannot have children. - If no node exists for
parent_ptr.
pub fn fill_descendants(
&mut self,
ancestor_ptr: NodePtr,
ancestor_coordinates: V,
min_level: Level,
filler: impl FnMut(NodeKey<V>, &mut NodeEntry<'_, T, CHILDREN>) -> VisitCommand
)
pub fn fill_descendants(
&mut self,
ancestor_ptr: NodePtr,
ancestor_coordinates: V,
min_level: Level,
filler: impl FnMut(NodeKey<V>, &mut NodeEntry<'_, T, CHILDREN>) -> VisitCommand
)
Inserts data in descendant “slots” of ancestor_ptr using filler().
Any node N is skipped if filler returns VisitCommand::SkipDescendants for any ancestor of N.
pub fn fill_path_to_node(
&mut self,
target_key: NodeKey<V>,
filler: impl FnMut(NodeKey<V>, &mut NodeEntry<'_, T, CHILDREN>) -> VisitCommand
)
pub fn fill_path_to_node(
&mut self,
target_key: NodeKey<V>,
filler: impl FnMut(NodeKey<V>, &mut NodeEntry<'_, T, CHILDREN>) -> VisitCommand
)
Call filler on all nodes from the root ancestor to target_key.
Looks up the root pointer for key in the top-level hash map.
Starting from the ancestor root, searches for the corresponding descendant node at key.
A ChildRelation is returned because it contains some extra useful info that is conveniently accessible during the
search.
pub fn find_descendant(
&self,
ancestor_ptr: NodePtr,
ancestor_coordinates: V,
descendant_key: NodeKey<V>
) -> Option<ChildRelation<V>>
pub fn find_descendant(
&self,
ancestor_ptr: NodePtr,
ancestor_coordinates: V,
descendant_key: NodeKey<V>
) -> Option<ChildRelation<V>>
Starting from the node at ancestor_ptr, searches for the corresponding descendant node at descendant_key.
Visits pointers for all non-empty children of the node at parent_ptr.
If parent_ptr does not exist or does not have any children, nothing happens.
pub fn visit_children_with_coordinates(
&self,
parent_ptr: NodePtr,
parent_coordinates: V,
visitor: impl FnMut(NodePtr, V)
)
pub fn visit_children_with_coordinates(
&self,
parent_ptr: NodePtr,
parent_coordinates: V,
visitor: impl FnMut(NodePtr, V)
)
Visits pointers and coordinates for all non-empty children of the node at parent_ptr with coordinates parent_coords.
If parent_ptr does not exist or does not have any children, nothing happens.
pub fn visit_tree_depth_first(
&self,
ancestor_ptr: NodePtr,
ancestor_coordinates: V,
min_level: Level,
visitor: impl FnMut(NodePtr, V) -> VisitCommand
)
pub fn visit_tree_depth_first(
&self,
ancestor_ptr: NodePtr,
ancestor_coordinates: V,
min_level: Level,
visitor: impl FnMut(NodePtr, V) -> VisitCommand
)
Visit ancestor_ptr and all descendants in depth-first order.
If visitor returns false, descendants of that node will not be visited.
pub fn visit_tree_breadth_first(
&self,
ancestor_ptr: NodePtr,
ancestor_coordinates: V,
min_level: Level,
visitor: impl FnMut(NodePtr, V) -> VisitCommand
)
pub fn visit_tree_breadth_first(
&self,
ancestor_ptr: NodePtr,
ancestor_coordinates: V,
min_level: Level,
visitor: impl FnMut(NodePtr, V) -> VisitCommand
)
Visit ancestor_ptr and all descendants in breadth-first order.
If visitor returns false, descendants of that node will not be visited.
Returns an array of pointers to the children of parent_ptr.
Returns None if parent_ptr is at level 0.
Drops the child node of relation and all descendants.
pub fn remove_tree(
&mut self,
relation: &ChildRelation<V>,
coordinates: V,
consumer: impl FnMut(NodeKey<V>, T)
)
pub fn remove_tree(
&mut self,
relation: &ChildRelation<V>,
coordinates: V,
consumer: impl FnMut(NodeKey<V>, T)
)
Moves the child node of relation (with coordinates) and all descendants into consumer.
Trait Implementations
Auto Trait Implementations
impl<V, S, T, const CHILDREN: usize> RefUnwindSafe for Tree<V, S, T, CHILDREN> where
S: RefUnwindSafe,
T: RefUnwindSafe,
V: RefUnwindSafe,
impl<V, S, T, const CHILDREN: usize> Send for Tree<V, S, T, CHILDREN> where
S: Send,
T: Send,
V: Send,
impl<V, S, T, const CHILDREN: usize> Sync for Tree<V, S, T, CHILDREN> where
S: Sync,
T: Sync,
V: Sync,
impl<V, S, T, const CHILDREN: usize> Unpin for Tree<V, S, T, CHILDREN> where
S: Unpin,
T: Unpin,
V: Unpin,
impl<V, S, T, const CHILDREN: usize> UnwindSafe for Tree<V, S, T, CHILDREN> where
S: UnwindSafe,
T: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more