count_nodes

Function count_nodes 

Source
pub fn count_nodes(ipld: &Ipld) -> usize
Expand description

Count the total number of nodes in a DAG

This includes all nodes at all levels, counting duplicates if they appear multiple times in the structure.

§Arguments

  • ipld - The DAG to count nodes in

§Returns

The total number of nodes (including the root)

§Example

use ipfrs_core::Ipld;
use ipfrs_core::dag::count_nodes;

let ipld = Ipld::List(vec![
    Ipld::Integer(1),
    Ipld::Integer(2),
    Ipld::List(vec![Ipld::Integer(3)]),
]);

assert_eq!(count_nodes(&ipld), 5); // List + 2 ints + inner list + 1 int