[][src]Struct treeid::Node

pub struct Node { /* fields omitted */ }

A position in the tree.

Nodes are encoded to binary in a modified form of LCF[1] (mLCF).

Deviations from the LCF encoding as described by Matula et al:

  • only suitable for rationals p/q where one (out of 2) of the continued fraction forms has both of the following properties:

    • composed of an odd number of natural terms
    • terms at odd indices are always 1
  • leading high bit / low bit is elided because (p >= q >= 1) and we don't need to differentiate from (1 <= p <= q).

use treeid::Node;

let node = Node::from(&[2, 4]);
let child = Node::from(&[2, 4, 1]);
let sibling = Node::from(&[2, 5]);
assert!(sibling.to_binary().gt(&child.to_binary()));
assert!(child.to_binary().gt(&node.to_binary()));
assert_eq!(node, Node::from_binary(&*node.to_binary()).unwrap());

Methods

impl Node[src]

pub fn root() -> Self[src]

Returns the root node.

use treeid::*;
assert_eq!(Node::from(&[]), Node::root());

pub fn from(v: &[u64]) -> Self[src]

Constructs a node from its tree position as a series of natural numbers.

pub fn parent(&self) -> Self[src]

pub fn parent_mut(&mut self)[src]

pub fn child(&self, id: u64) -> Self[src]

pub fn child_mut(&mut self, id: u64)[src]

pub fn sibling(&self, id: u64) -> Option<Self>[src]

pub fn sibling_mut(&mut self, id: u64)[src]

pub fn pred(&self) -> Option<Self>[src]

pub fn succ(&self) -> Self[src]

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

pub fn from_binary(mlcf_encoded: &[u8]) -> Option<Self>[src]

Decode an id from its mLCF encoded form. The input must have a length that is an even multiple of 8 to allow unpacking into an &mut [u64] directly.

pub fn to_binary(&self) -> Vec<u8>[src]

Writes this id into a Vec<[u8]> using mLCF encoding. The output will be padded with trailing zero bytes such that its length is a multiple of 8 - from_binary() can then pack it directly into an &mut [u64] and decode up to 8 bytes per iter instead of up to 1.

use treeid::*;
assert_eq!(&[0, 0, 0, 0, 0, 0, 0, 0], &*Node::from(&[1]).to_binary());
assert_eq!(&[0b10000000, 0, 0, 0, 0, 0, 0, 0], &*Node::from(&[2]).to_binary());
assert_eq!(&[0b10011000, 0, 0, 0, 0, 0, 0, 0], &*Node::from(&[2, 2]).to_binary());
assert_eq!(
    &[0b11000110, 0b11100111, 0b00100000, 0, 0, 0, 0, 0],
    &*Node::from(&[4, 3, 2, 5]).to_binary(),
);

Trait Implementations

impl Clone for Node[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl PartialEq<Node> for Node[src]

impl Debug for Node[src]

Auto Trait Implementations

impl Send for Node

impl Sync for Node

Blanket Implementations

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

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

type Owned = T

impl<T> From for T[src]

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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