ipld / go-ipld-prime

Golang interfaces for the IPLD Data Model, with core Codecs included, IPLD Schemas support, and some handy functional transforms tools.
MIT License
133 stars 50 forks source link

Add depth selector with optional stop-node #471

Open masih opened 2 years ago

masih commented 2 years ago

Understanding the shape of a DAG without having to download it is extremely beneficial in cases where the DAG is too large and or the transport of the entire DAG is too time-consuming. This is specifically true for blockchain-like DAGs that have a single link to previous, e.g. Network Indexer advertisement chain. For example, such a selector would allow storetheindex to efficiently estimate how far behind it is in processing advertisements of a provider without having to download the entire chain first.

Add the ability to get the depth of a DAG, recursing an edge from some given root with optional stop node.

rvagg commented 2 years ago

So the selector becomes a transform that can turn a DAG into a simple "depth" integer? Perhaps this could be implemented as an ADL, so interpretAs a depth-finder ADL that transforms an arbitrary DAG into an Int node.