package containers
A modular, clean and powerful extension of the OCaml standard library
Install
Dune Dependency
Authors
Maintainers
Sources
v2.8.tar.gz
md5=03b80e963186e91ddac62ef645bf7fb2
sha512=c8f434808be540c16926bf03d89f394d33fc2d092f963a7b6d412481229e0a96290f1ad7c7d522415115d35426b7aa0b3fda4b991ddc321dad279d402c9a0c0b
doc/containers.iter/CCKTree/index.html
Module CCKTree
Source
Lazy Tree Structure
This structure can be used to represent trees and directed graphs (as infinite trees) in a lazy fashion. Like CCKList
, it is a structural type.
Basics
Fold on values in no specified order. May not terminate if the tree is infinite.
Graph Traversals
Build a set structure given a total ordering.
Depth-first traversal of the tree.
force t
evaluates t
completely and returns a regular tree structure.
Look for an element that maps to Some _
.
Pretty-printing
Example (tree of calls for naive Fibonacci function):
let mk_fib n =
let rec fib' l r i =
if i=n then r else fib' r (l+r) (i+1)
in fib' 1 1 1;;
let rec fib n = match n with
| 0 | 1 -> CCKTree.singleton (`Cst n)
| _ -> CCKTree.node2 (`Plus (mk_fib n)) (fib (n-1)) (fib (n-2));;
let pp_node fmt = function
| `Cst n -> Format.fprintf fmt "%d" n
| `Plus n -> Format.fprintf fmt "%d" n;;
Format.printf "%a@." (CCKTree.pp pp_node) (fib 8);;
A pretty-printer using S-expressions and boxes to render the tree. Empty nodes are not rendered; sharing is ignored.
Pretty printing in the DOT (graphviz) format
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page