Skip to main content

Tree

Struct Tree 

Source
pub struct Tree<T, C = i32> {
    pub arena: Vec<Node<T, C>>,
    pub free_list: Vec<usize>,
    pub root: Option<usize>,
    pub item_count: i32,
    pub dead_count: i32,
    pub extent: KdBox<C>,
    pub delete_flip: bool,
}
Expand description

A 3D KD-Tree implementation using arena allocation.

The tree stores items of type T associated with a 6-element bounding box [left, bottom, floor, right, top, ceil]. It uses a Vec-backed arena for node storage to improve performance and cache locality.

Fields§

§arena: Vec<Node<T, C>>§free_list: Vec<usize>§root: Option<usize>§item_count: i32§dead_count: i32§extent: KdBox<C>§delete_flip: bool

Implementations§

Source§

impl<T: PartialEq + Clone, C: Coord> Tree<T, C>

Source

pub fn new() -> Self

Creates a new, empty 3D KD-Tree.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new 3D KD-Tree with a pre-allocated capacity for the node arena.

Source

pub fn insert(&mut self, item: T, size: KdBox<C>)

Inserts an item into the tree with the given 3D bounding box.

Source

pub fn is_member(&self, item: &T, size: &KdBox<C>) -> bool

Checks if the given item is stored in the tree with the specified bounding box.

Source

pub fn delete(&mut self, item: &T, size: &KdBox<C>) -> bool

Marks an item as deleted (soft delete).

Source

pub fn hard_delete(&mut self, item: &T, size: &KdBox<C>) -> bool

Physically deletes an item from the tree and restructures the nodes (hard delete).

Source

pub fn count(&self) -> i32

Source

pub fn badness(&self)

Source§

impl<T: PartialEq + Clone, C: Coord> Tree<T, C>

Source

pub fn start(&self, area: KdBox<C>) -> Generator<'_, T, C>

Returns an iterator over all items that intersect with the given 3D bounding box.

Source

pub fn nearest(&self, x: C, y: C, z: C, m: usize) -> Vec<Priority<T>>

Finds the m nearest neighbors to the point (x, y, z).

Source

pub fn really_delete( &mut self, data: &T, old_size: &KdBox<C>, ) -> (Status, i32, i32)

Deletes structurally an item from the tree (really delete).

Auto Trait Implementations§

§

impl<T, C> Freeze for Tree<T, C>
where C: Freeze,

§

impl<T, C> RefUnwindSafe for Tree<T, C>

§

impl<T, C> Send for Tree<T, C>
where C: Send, T: Send,

§

impl<T, C> Sync for Tree<T, C>
where C: Sync, T: Sync,

§

impl<T, C> Unpin for Tree<T, C>
where C: Unpin, T: Unpin,

§

impl<T, C> UnsafeUnpin for Tree<T, C>
where C: UnsafeUnpin,

§

impl<T, C> UnwindSafe for Tree<T, C>
where C: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.