Module dag

Module dag 

Source
Expand description

DAG (Directed Acyclic Graph) traversal and analysis utilities.

This module provides utilities for working with IPLD Merkle DAGs:

  • Extracting CID links from IPLD data
  • Calculating DAG statistics
  • Validating DAG structures
  • Collecting all CIDs in a DAG

§Examples

use ipfrs_core::{Ipld, Cid, CidBuilder};
use ipfrs_core::dag::{extract_links, DagStats};
use std::collections::BTreeMap;

// Create IPLD with links
let cid1 = CidBuilder::new().build(b"data1").unwrap();
let cid2 = CidBuilder::new().build(b"data2").unwrap();

let mut map = BTreeMap::new();
map.insert("link1".to_string(), Ipld::link(cid1));
map.insert("link2".to_string(), Ipld::link(cid2));
let ipld = Ipld::Map(map);

// Extract all CID links
let links = extract_links(&ipld);
assert_eq!(links.len(), 2);

Structs§

DagMetrics
Additional DAG metrics beyond basic statistics.
DagStats
Statistics about a DAG structure

Functions§

collect_all_links
Extract all CID links from an IPLD structure recursively.
collect_unique_links
Extract unique CID links from an IPLD structure (no duplicates).
count_links_by_depth
Count the number of CID links at each depth level in the DAG.
count_nodes
Count the total number of nodes in a DAG
dag_depth
Get the maximum depth of a DAG
dag_diff
Find the differences between two IPLD DAGs
dag_fanout_by_level
Calculate the fanout (number of direct children) for each level of the DAG.
extract_links
Extract all CID links from an IPLD structure (non-recursive).
filter_dag
Filter an IPLD structure to only include nodes matching a predicate.
find_common_links
Find common ancestor links between two DAGs
find_leaves
Find all leaf nodes in a DAG
find_paths_to_cid
Find all paths from root to a specific CID in an IPLD structure.
is_dag
Validate that an IPLD structure forms a proper DAG (no cycles).
map_dag
Transform all nodes in a DAG using a mapping function.
merge_dags
Merge two DAGs into a single DAG
prune_dag
Prune nodes from a DAG based on a predicate
subgraph_size
Calculate the size (number of nodes) of a subgraph rooted at the given IPLD node.
topological_sort
Perform a topological sort on IPLD nodes containing CID links.
traverse_bfs
Traverse a DAG in breadth-first order, collecting all IPLD nodes.
traverse_dfs
Traverse a DAG in depth-first order, collecting all IPLD nodes.