Struct narwhal_dag::Node
source · [−]pub struct Node<T> { /* private fields */ }
Expand description
The Dag node, aka vertex.
Implementations
sourceimpl<T> Node<T>
impl<T> Node<T>
sourcepub fn new_leaf(value: T, compressible: bool) -> Self
pub fn new_leaf(value: T, compressible: bool) -> Self
Create a new DAG leaf node that contains the given value.
Example
use narwhal_dag::{ Node, NodeRef };
let node = Node::new_leaf(1, false);
sourcepub fn new(value: T, compressible: bool, parents: Vec<NodeRef<T>>) -> Self
pub fn new(value: T, compressible: bool, parents: Vec<NodeRef<T>>) -> Self
Create a new DAG inner node that contains the given value and points to the given parents.
sourcepub fn value(&self) -> &T
pub fn value(&self) -> &T
Return the value payload of the node
Example
use narwhal_dag::Node;
let node = Node::new_leaf(1, false);
assert_eq!(*node.value(), 1);
sourcepub fn is_leaf(&self) -> bool
pub fn is_leaf(&self) -> bool
Is the node parent-less?
Examples
use narwhal_dag::Node;
let node = Node::new_leaf(1, false);
assert_eq!(node.is_leaf(), true);
sourcepub fn is_compressible(&self) -> bool
pub fn is_compressible(&self) -> bool
Is the node compressible?
Examples
use narwhal_dag::Node;
let node = Node::new_leaf(1, true);
assert_eq!(node.is_compressible(), true);
sourcepub fn make_compressible(&self) -> bool
pub fn make_compressible(&self) -> bool
Make the node compressible. Returns true if the node was made compressible, false if it already was.
Beware: this operation is irreversible.
Examples
use narwhal_dag::Node;
let node = Node::new_leaf(1, false);
assert_eq!(node.make_compressible(), true);
let node2 = Node::new_leaf(2, true);
assert_eq!(node.make_compressible(), false);
sourceimpl<T: Sync + Send + Debug> Node<T>
impl<T: Sync + Send + Debug> Node<T>
sourcepub fn parents(&self) -> Vec<NodeRef<T>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn parents(&self) -> Vec<NodeRef<T>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Compress the path from this node to the next incompressible layer of the DAG. Returns the parents of the node.
After path compression, one of these three conditions holds:
- This node is a leaf node;
- This node has only incompressible parents, and keeps them;
- This node has compressible parents, and after path compression, they are replaced by their closest incompressible ancestors.
Trait Implementations
impl<T: Eq> Eq for Node<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Node<T>where
T: RefUnwindSafe,
impl<T> Send for Node<T>where
T: Send + Sync,
impl<T> Sync for Node<T>where
T: Send + Sync,
impl<T> Unpin for Node<T>where
T: Unpin,
impl<T> UnwindSafe for Node<T>where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more