Struct charcoal::Octree[][src]

pub struct Octree<B, L = B, K = usize, S = DefaultStorage<Node<B, L, K>>> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
{ /* fields omitted */ }

An octree.

See the module-level documentation for more.

Implementations

impl<B, L, K, S> Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

pub fn new(root: L) -> Self[src]

This is supported on crate feature octree only.

Creates an octree with the specified value for the root node.

Example

// The only way to create a tree...
let tree = Octree::<_>::new(87);
// ...is to simply create the root leaf node and storage. The turbofish there is needed to
// state that we are using the default storage method instead of asking the compiler to
// infer it, which would be impossible.

// No other nodes have been created yet:
assert!(tree.root().is_leaf());

pub fn with_capacity(capacity: usize, root: L) -> Self[src]

This is supported on crate feature octree only.

Creates an octree with the specified capacity for the storage.

Panics

The storage may panic if it has fixed capacity and the specified value does not match it.

Example

// Let's create a tree, but with some preallocated space for more nodes:
let mut tree = Octree::<_>::with_capacity(9, "Variable Names");
// The turbofish there is needed to state that we are using the default storage method
// instead of asking the compiler to infer it, which would be impossible.

// Capacity does not affect the actual nodes:
assert!(tree.root().is_leaf());

// Not until we create them ourselves:
tree.root_mut().make_branch([
    "Foo", "Bar", "Baz", "Quux", "Spam", "Eggs", "Monty", "Python",
]);

// If the default storage is backed by a dynamic memory allocation,
// at most one has happened to this point.

pub fn root(&self) -> NodeRef<'_, B, L, K, S>[src]

This is supported on crate feature octree only.

Returns a reference to the root node of the tree.

Example

// A tree always has a root node:
let tree = Octree::<_>::new("Root");

assert_eq!(
    // The into_inner() call extracts data from a NodeValue, which is used to generalize
    // tres to both work with same and different types for payloads of leaf and branch
    // nodes.
    *tree.root().value().into_inner(),
    "Root",
);

pub fn root_mut(&mut self) -> NodeRefMut<'_, B, L, K, S>[src]

This is supported on crate feature octree only.

Returns a mutable reference to the root node of the tree, allowing modifications to the entire tree.

Example

// A tree always has a root node:
let mut tree = Octree::<_>::new("Root");

let mut root_mut = tree.root_mut();
// The into_inner() call extracts data from a NodeValue, which is used to generalize trees
// to both work with same and different types for payloads of leaf and branch nodes.
*(root_mut.value_mut().into_inner()) = "The Source of the Beer";

pub fn num_nodes(&self) -> usize[src]

This is supported on crate feature octree only.

Returns the number of nodes in the tree.

pub fn capacity(&self) -> usize[src]

This is supported on crate feature octree only.

Returns the additional number of nodes which the tree can store without the need to reallocate.

pub fn reserve(&mut self, additional: usize)[src]

This is supported on crate feature octree only.

Reserves capacity for at least additional more elements to be inserted in the given storage. The storage may reserve more space to avoid frequent reallocations. After calling reserve, capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already sufficient.

pub fn shrink_to_fit(&mut self)[src]

This is supported on crate feature octree only.

Shrinks the capacity of the storage as much as possible.

It will drop down as close as possible to the current length, though dynamically allocated storages may not always reallocate exactly as much as it is needed to store all elements and none more.

impl<B, L, S> Octree<B, L, usize, SparseStorage<Node<B, L, usize>, S>> where
    S: ListStorage<Element = SparseStorageSlot<Node<B, L, usize>>>, 
[src]

pub fn defragment(&mut self)[src]

This is supported on crate feature octree only.

Removes all holes from the sparse storage.

Under the hood, this uses defragment_and_fix. It’s not possible to defragment without fixing the indicies, as that might cause undefined behavior.

Example

use charcoal::octree::SparseVecOctree;

// Create a tree which explicitly uses sparse storage:
let mut tree = SparseVecOctree::new(0);
// This is already the default, but for the sake of this example we'll stay explicit.

// Add some elements for the holes to appear:
tree.root_mut().make_branch([
    1, 2, 3, 4, 5, 6, 7, 8,
]).unwrap(); // You can replace this with proper error handling
tree
    .root_mut()
    .nth_child_mut(0)
    .unwrap() // This too
    .make_branch([
        9, 10, 11, 12, 13, 14, 15, 16,
    ])
    .unwrap(); // And this

tree
    .root_mut()
    .nth_child_mut(0)
    .unwrap() // Same as above
    .try_remove_children()
    .unwrap(); // Same here

// We ended up creating 8 holes:
assert_eq!(tree.num_holes(), 8);
// Let's patch them:
tree.defragment();
// Now there are none:
assert_eq!(tree.num_holes(), 0);

pub fn num_holes(&self) -> usize[src]

This is supported on crate feature octree only.

Returns the number of holes in the storage. This operation returns immediately instead of looping through the entire storage, since the sparse storage automatically tracks the number of holes it creates and destroys.

Example

See the example in defragment.

pub fn is_dense(&self) -> bool[src]

This is supported on crate feature octree only.

Returns true if there are no holes in the storage, false otherwise. This operation returns immediately instead of looping through the entire storage, since the sparse storage automatically tracks the number of holes it creates and destroys.

Example

See the example in defragment.

Trait Implementations

impl<B: Clone, L: Clone, K: Clone, S: Clone> Clone for Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

impl<B: Copy, L: Copy, K: Copy, S: Copy> Copy for Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

impl<B: Debug, L: Debug, K: Debug, S: Debug> Debug for Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

impl<B, L, K, S> Default for Octree<B, L, K, S> where
    L: Default,
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

impl<B: Eq, L: Eq, K: Eq, S: Eq> Eq for Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

impl<B: Hash, L: Hash, K: Hash, S: Hash> Hash for Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

impl<B: PartialEq, L: PartialEq, K: PartialEq, S: PartialEq> PartialEq<Octree<B, L, K, S>> for Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

impl<B, L, K, S> StructuralEq for Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

impl<B, L, K, S> StructuralPartialEq for Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

impl<B, L, K, S> Traversable for Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

type Leaf = L

The payload of the node if it’s a leaf node.

type Branch = B

The payload of the node if it’s a branch node.

type Cursor = K

The type for the cursor which will be used for keeping track of the traversed nodes. Read more

impl<B, L, K, S> TraversableMut for Octree<B, L, K, S> where
    S: Storage<Element = Node<B, L, K>, Key = K>,
    K: Clone + Debug + Eq
[src]

This is supported on crate feature octree only.

type PackedChildren = PackedChildren<L>

A container for the leaf children of a branch node.

Auto Trait Implementations

impl<B, L, K, S> RefUnwindSafe for Octree<B, L, K, S> where
    K: RefUnwindSafe,
    S: RefUnwindSafe

impl<B, L, K, S> Send for Octree<B, L, K, S> where
    K: Send,
    S: Send

impl<B, L, K, S> Sync for Octree<B, L, K, S> where
    K: Sync,
    S: Sync

impl<B, L, K, S> Unpin for Octree<B, L, K, S> where
    K: Unpin,
    S: Unpin

impl<B, L, K, S> UnwindSafe for Octree<B, L, K, S> where
    K: UnwindSafe,
    S: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Slottable for T where
    T: Copy
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.