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.