DAGStore

Trait DAGStore 

Source
pub trait DAGStore {
    // Required methods
    fn get(&self, cid: &Hash) -> Option<&MerkleNode>;
    fn put(&mut self, node: MerkleNode) -> Result<Hash, DAGError>;
    fn put_unchecked(&mut self, node: MerkleNode) -> Result<Hash, DAGError>;
    fn heads(&self) -> Vec<Hash>;
    fn contains(&self, cid: &Hash) -> bool;
    fn ancestors(&self, cid: &Hash) -> HashSet<Hash>;
    fn children(&self, cid: &Hash) -> Vec<Hash>;
    fn topological_order(&self) -> Vec<Hash>;
    fn missing_nodes(&self) -> HashSet<Hash>;
    fn len(&self) -> usize;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Trait for content-addressed DAG storage.

Required Methods§

Source

fn get(&self, cid: &Hash) -> Option<&MerkleNode>

Get a node by its CID.

Source

fn put(&mut self, node: MerkleNode) -> Result<Hash, DAGError>

Store a node, returning its CID.

The node’s CID is verified before storage. Returns an error if verification fails or parents are missing.

Source

fn put_unchecked(&mut self, node: MerkleNode) -> Result<Hash, DAGError>

Store a node without checking for missing parents.

Used during sync when parents may arrive out of order.

Source

fn heads(&self) -> Vec<Hash>

Get the current heads (nodes without children).

Source

fn contains(&self, cid: &Hash) -> bool

Check if a node exists in the store.

Source

fn ancestors(&self, cid: &Hash) -> HashSet<Hash>

Get all ancestors of a node (transitive closure).

Source

fn children(&self, cid: &Hash) -> Vec<Hash>

Get immediate children of a node.

Source

fn topological_order(&self) -> Vec<Hash>

Get all nodes in topological order (parents before children).

Source

fn missing_nodes(&self) -> HashSet<Hash>

Get nodes that are missing (referenced but not present).

Source

fn len(&self) -> usize

Get the total number of nodes.

Provided Methods§

Source

fn is_empty(&self) -> bool

Check if the store is empty.

Implementors§