Struct GenTree

Source
pub struct GenTree<T> { /* private fields */ }

Implementations§

Source§

impl<T> GenTree<T>

Source

pub fn new() -> GenTree<T>

Creates a new, zero-sized GenTree.

Source

pub fn new_with_capacity(capacity: usize) -> GenTree<T>

Creates a new GenTree that pre-allocates to the given capacity.

Source

pub fn root(&self) -> Position

Returns the Position to the tree’s root node.

Source

pub fn mut_root(&mut self, data: T)

Source

pub fn is_root(&self, position: &Position) -> bool

Indicates whether the given Position is the tree’s root.

Source

pub fn is_some(&self, position: &Position) -> bool

Indicates whether the given Position contains data.

Source

pub fn is_none(&self, position: &Position) -> bool

Indicates whether the given Position contains data.

Source

pub fn is_empty(&self) -> bool

Indicates whether the tree is empty.

Source

pub fn size(&self) -> usize

Returns the number of live nodes in the tree.

Source

pub fn num_children(&self, position: &Position) -> usize

Returns the number of children for a Node at the given Position.

Source

pub fn depth(&mut self, _node: &Position) -> usize

WARNING: Unimplemented

Source

pub fn height(&mut self, _node: &Position) -> usize

WARNING: Unimplemented

Source

pub fn get_data(&self, position: &Position) -> Option<&T>

Returns an immutable reference to the data at the given Position, if Some.

Source

pub fn get_for_pos(&self, position: &Position) -> Option<&T>

Returns an immutable reference to the data at the given Position, if Some.

Source

pub fn add_child(&mut self, position: &Position, data: T) -> Position

Adds a child to the given Position and returns its Position.

Source

pub fn children(&self, position: &Position) -> &Vec<Position>

Returns a reference to the list of child Positions for the given Position.

Source

pub fn remove(&mut self, position: Position) -> Option<T>

Removes a node at the given Position and returns its data. If the removed Position has a parent, all the deleted node’s children get pushed to the deleted Position’s parent. If the deleted Position has no parent (root) a new parent is designated as the first child of the deleted node, e.g. this is a tree, not a forest. Ordering for the designation of the new root is not guaranteed, and depends on when child Positions were added. For this reason, caution is advised when potentially deleting root nodes.

Runs in O(s + c) time where:

  • s is the number of the deleted node’s siblings (i.e. the number of its parent’s children),
  • c is the number of the deleted node’s children.

Precondition:

          3
       /    \
      5      9 (marked for deleteion)
    /  \    /  \
   8   12  11  14

Postcondition:

          3
       /  |  \
      5   11  14
    /  \    
   8   12  

Precondition:

          3 (marked for deletion)
       /  |  \
      5   11  14
    /  \    
   8   12  

Postcondition:

         5
    /  /   \  \
   8  12   11 14

Precondition:

          3 (marked for deletion)
       /    \
      9      5
    /  \    /  \
   8   12  11  14

Postcondition:

          9
       /  |  \
      8  12   5
             /  \
            11   14
Source

pub fn parent(&mut self, position: &Position) -> Option<Position>

Returns the Position of a given Position’s parent, if Some.

Trait Implementations§

Source§

impl<T: Debug> Debug for GenTree<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for GenTree<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for GenTree<T>

§

impl<T> RefUnwindSafe for GenTree<T>
where T: RefUnwindSafe,

§

impl<T> Send for GenTree<T>
where T: Send,

§

impl<T> Sync for GenTree<T>
where T: Sync,

§

impl<T> Unpin for GenTree<T>
where T: Unpin,

§

impl<T> UnwindSafe for GenTree<T>
where 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V