12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576type'atree=Nodeof'a*'atreearrayletchildren(Node(_,a))=amoduletypeI=Hashtbl.HashedTypemoduleLift(I:I)=structtypet=I.ttreeletequal(Node(v1,_))(Node(v2,_))=I.equalv1v2lethash(Node(v,_))=I.hashvendletlayered_lookup(typea)?(m:(moduleIwithtypet=a)option)=let(moduleI)=matchmwith|Somem->m|None->(module(structtypet=aletequal=(=)lethash=Hashtbl.hashend))inletmoduleT=Lift(I)inLayered.layout~m:(moduleT)~childrenletrecdecoratef(Node(i,a)ast)=Node((i,ft),Array.map(decoratef)a)letlayered?m=letf=layered_lookup?minfun~distancet->letlookup=f~distancetindecoratelookuptlettreemap_iter~area=letchildren(Node(_,a))k=Array.iterkainTreemaps.layout~children~arealetrecdecoratef(Node(i,a))=Node((i,fi),Array.map(decoratef)a)lettreemap(typea)?(m:(moduleIwithtypet=a)option)=let(moduleI)=matchmwith|Somem->m|None->(module(structtypet=aletequal=(=)lethash=Hashtbl.hashend))inletmoduleH=Hashtbl.Make(I)inlethash_of_iterk=leth=H.create17ink(fun(Node(v,_),r)->H.addhvr);hinfun~areart->leth=hash_of_iter@@treemap_iter~areartindecorate(H.findh)t(*
* Copyright (c) 2019 Gabriel Radanne <drupyog@zoho.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)