Docs.rs
  • flat-tree-6.0.0
    • flat-tree 6.0.0
    • Permalink
    • Docs.rs crate page
    • MIT OR Apache-2.0
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • mafintosh
    • yoshuawuyts
    • github:datrs:maintainers
    • Dependencies
      • criterion ^0.3 dev
    • Versions
    • 100% of the crate is documented
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Badges
    • Builds
    • Metadata
    • Shorthand URLs
    • Download
    • Rustdoc JSON
    • Build queue
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate flat_tree

flat_tree6.0.0

  • All Items

Sections

  • Series of functions to map a binary tree to a list

Crate Items

  • Structs
  • Functions

Crates

  • flat_tree

Crate flat_tree

Source
Expand description

§Series of functions to map a binary tree to a list

You can represent a binary tree in a simple flat list using the following structure:

                                    15
              7                                             23
      3                 11                      19                      27
  1       5        9          13          17          21          25          29
0   2   4   6   8    10    12    14    16    18    20    22    24    26    28    30...

Each number represents an index in a flat list. So a tree:

      A
  B       C
D   E   F   G  ...

would be represented as a list: [D B E A F C G]

Furthermore, indexes 0, 2, 4, 6 are on depth 0. 1, 5, 9 on depth 1. And so forth.

depth = 2  ^        3
depth = 1  |    1       5
depth = 0  |  0   2   4   6  ...

In some cases it is also useful to calculate an offset. Indexes 0, 1, 3, 7 have an offset 0:

                (7)
       (3)
  (1)       5
(0)   2   4   6      ...

2, 5, 11, 23 offset 1:

                 7
       3                  (11)
  1        (5)        9          13
0   (2)   4   6    8    10    12    14

This module exposes a series of functions to help you build and maintain this data structure.

Structs§

Iterator
Iterator over a flat-tree.

Functions§

children
Returns both children of a node.
count
Returns how many nodes are in the tree that the node spans.
count_leaves
Returns how many leaves are in the tree that the node spans.
depth
Returns the depth of a node.
full_roots
Returns a list of all the full roots (subtrees where all nodes have either 2 or 0 children) < index.
index
Returns the flat-tree of the tree node at the specified depth and offset.
left_child
Returns only the left child of a node.
left_span
Returns the left most node in the tree that it spans.
offset
Returns the offset of a node.
parent
Returns the parent of a node with a depth.
right_child
Returns only the left child of a node.
right_span
Returns the right most node in the tree that the node spans.
sibling
Returns the sibling of a node.
spans
Returns the left and right most nodes in the tree that the node spans.
uncle
Returns the parent’s sibling, of a node.

Results

Settings
Help
    struct
    flat_tree::Iterator
    Iterator over a flat-tree.
    method
    flat_tree::Iterator::index
    &Iterator -> u64
    Get the current index.
    method
    flat_tree::Iterator::factor
    &Iterator -> u64
    Get the current factor.
    method
    flat_tree::Iterator::offset
    &Iterator -> u64
    Get the current offset.
    method
    flat_tree::Iterator::is_left
    &Iterator -> bool
    Check if the position of the iterator is currently on a …
    method
    flat_tree::Iterator::is_right
    &Iterator -> bool
    Check if the position of the iterator is currently on a …
    method
    flat_tree::Iterator::count_nodes
    &Iterator -> u64
    Returns how many nodes are in the tree of the current …
    method
    flat_tree::Iterator::count_leaves
    &Iterator -> u64
    Returns how many leaves are in the tree of the current …
    method
    flat_tree::Iterator::prev
    &mut Iterator -> u64
    Move the cursor and get the previous item from the current …
    method
    flat_tree::Iterator::parent
    &mut Iterator -> u64
    Get the parent for the current position and move the …
    method
    flat_tree::Iterator::sibling
    &mut Iterator -> u64
    Get the sibling for the current position and move the …
    method
    flat_tree::Iterator::contains
    &Iterator, u64 -> bool
    Check if the the iterator contains given index.
    method
    flat_tree::Iterator::left_span
    &mut Iterator -> u64
    Get the left_span for the current position and move the …
    method
    flat_tree::Iterator::next_tree
    &mut Iterator -> u64
    Move to the next tree from the current position and return …
    method
    flat_tree::Iterator::prev_tree
    &mut Iterator -> u64
    Move to the previous tree from the current position and …
    method
    flat_tree::Iterator::left_child
    &mut Iterator -> u64
    Get the left_child for the current position and move the …
    method
    flat_tree::Iterator::right_span
    &mut Iterator -> u64
    Get the right_span for the current position and move the …
    method
    flat_tree::Iterator::right_child
    &mut Iterator -> u64
    Get the right_child for the current position and move the …
    method
    flat_tree::Iterator::next
    &mut Iterator -> Option<Iterator::Item>
    method
    flat_tree::Iterator::seek
    &mut Iterator, u64 -> ()
    Seek to a position in the iterator.
    method
    flat_tree::Iterator::full_root
    &mut Iterator, u64 -> bool
    Move cursor to the full root of given leaf index that the …
    method
    flat_tree::Iterator::fmt
    &Iterator, &mut Formatter -> Result
    method
    flat_tree::Iterator::default
    -> Iterator
    method
    flat_tree::Iterator::new
    u64 -> Iterator
    Create a new iterator.