Trait TreeCollection

Source
pub trait TreeCollection<K, V>: TraversableCollection<K, V>{
Show 14 methods // Required methods fn breadth(&self) -> usize; fn child_nodes(&self, key: &K) -> Vec<&V>; fn depth_of(&self, key: &K) -> isize; fn height(&self) -> isize; fn height_from(&self, key: &K) -> isize; fn is_ancestor(&self, key_a: &K, key_b: &K) -> bool; fn is_descendant(&self, key_a: &K, key_b: &K) -> bool; fn is_leaf(&self, key: &K) -> bool; fn is_sibling(&self, key_a: &K, key_b: &K) -> bool; fn level_of(&self, key: &K) -> isize; fn parent_node(&self, key: &K) -> Option<&V>; fn root_node(&self) -> Option<&V>; fn set_node(&mut self, pair: KeyValue<K, V>) -> V; fn width(&self, level: usize) -> usize;
}

Required Methods§

Source

fn breadth(&self) -> usize

Returns the breadth of this ‘tree’. The breadth of a ‘tree’ is the total number of leaf ‘nodes’ that it has.

Source

fn child_nodes(&self, key: &K) -> Vec<&V>

Returns a list of child ‘nodes’ values belonging to the ‘node’ with the specified key. If no such ‘node’ exists or if the ‘node’ has no children, an empty vector is returned.

Source

fn depth_of(&self, key: &K) -> isize

Returns the depth of the ‘node’ with the specified key, or returns -1 if no such ‘node’ with that key exists. The depth of a ‘node’ is the number of edges it has from the root ‘node’. This is the same as the level of a ‘node’.

Source

fn height(&self) -> isize

Returns the height of this ‘tree’. The height of a ‘tree’ is the distance from the root ‘node’ to the leaf ‘node’ that is furthest away.

Source

fn height_from(&self, key: &K) -> isize

Returns the height of this ‘tree’ from the ‘node’ with the specified key, or returns -1 if no such ‘node’ with that key exists.

Source

fn is_ancestor(&self, key_a: &K, key_b: &K) -> bool

Returns true if the ‘node’ with the second specified key is an ancestor of the ‘node’ with the first specified key. If either key does not belong to an existing ‘node’, or the two ‘nodes’ are not ancestors, this returns false. An ancestor of a ‘node’ is a ‘node’ that can be reached by progressing up through the original ‘node’s’ parent node and its parent ‘node’ and so on.

Source

fn is_descendant(&self, key_a: &K, key_b: &K) -> bool

Returns true if the ‘node’ with the second specified key is a descendant of the ‘node’ with the first specified key. If either key does not belong to an existing ‘node’, or the two ‘nodes’ are not descendants, this returns false. A descendant of a ‘node’ is a ‘node’ that is reachable from another ‘node’ by progressing down through their child ‘nodes’ and their child’s child ‘nodes’ and so on.

Source

fn is_leaf(&self, key: &K) -> bool

Returns true if the ‘node’ with the specified key is a leaf ‘node’. If no such ‘node’ exists, false is returned. A leaf ‘node’ is a node with no child ‘nodes’.

Source

fn is_sibling(&self, key_a: &K, key_b: &K) -> bool

Returns true if the ‘node’ with the second specified key is a sibling of the ‘node’ with the first specified key. If either key does not belong to an existing ‘node’, or the two ‘nodes’ are not siblings, this returns false. A sibling of a ‘node’ is a ‘node’ that has the same parent ‘node’.

Source

fn level_of(&self, key: &K) -> isize

Returns the level of the ‘node’ with the specified key, or returns -1 if no such ‘node’ with that key exists. The level of a ‘node’ is the number of edges it has from the root ‘node’. This is the same as the depth of a ‘node’.

Source

fn parent_node(&self, key: &K) -> Option<&V>

Returns the parent ‘node’ value of the ‘node’ with the specified key. If no such ‘node’ exists or if the ‘node’ has no parent, this returns None.

Source

fn root_node(&self) -> Option<&V>

Returns the root ‘node’ value of this ‘tree’, or None if there is no root ‘node’.

Source

fn set_node(&mut self, pair: KeyValue<K, V>) -> V

Sets the value of the ‘node’ with the specified key to the specified value. Returns the value being replaced.

§Panics

This function panics if no such ‘node’ with the specified key exists.

Source

fn width(&self, level: usize) -> usize

Returns the width of the specified level of this ‘tree’. This returns 0 if the specified level does not exist in this ‘tree’. The width of a level is the number of ‘nodes’ in that level.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<K, V> TreeCollection<K, V> for Tree<K, V>

Source§

impl<K, V, const BALANCED: bool> TreeCollection<K, V> for BinaryTree<K, V, BALANCED>