123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 TriliTech <contact@trili.tech> *)(* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)typetree_instance=..typekey=stringlisttypevalue=bytesexceptionIncorrect_tree_typemoduletypeS=sigtypetreevalselect:tree_instance->treevalwrap:tree->tree_instancevalremove:tree->key->treeLwt.tvaladd:tree->key->value->treeLwt.tvaladd_tree:tree->key->tree->treeLwt.tvalfind:tree->key->valueoptionLwt.tvalfind_tree:tree->key->treeoptionLwt.tvalhash:tree->Context_hash.tvallength:tree->key->intLwt.tvallist:tree->?offset:int->?length:int->key->(string*tree)listLwt.tendtype'treebackend=(moduleSwithtypetree='tree)letselect:typetree.treebackend->tree_instance->tree=fun(moduleT)tree->T.selecttreeletwrap:typetree.treebackend->tree->tree_instance=fun(moduleT)tree->T.wraptreeletremove:typetree.treebackend->tree->key->treeLwt.t=fun(moduleT)treekey->T.removetreekeyletadd:typetree.treebackend->tree->key->value->treeLwt.t=fun(moduleT)treekeyvalue->T.addtreekeyvalueletadd_tree:typetree.treebackend->tree->key->tree->treeLwt.t=fun(moduleT)treekeysubtree->T.add_treetreekeysubtreeletfind:typetree.treebackend->tree->key->valueoptionLwt.t=fun(moduleT)treekey->T.findtreekeyletfind_tree:typetree.treebackend->tree->key->treeoptionLwt.t=fun(moduleT)treekey->T.find_treetreekeylethash:typetree.treebackend->tree->Context_hash.t=fun(moduleT)tree->T.hashtreeletlength:typetree.treebackend->tree->key->intLwt.t=fun(moduleT)treekey->T.lengthtreekeyletlist:typetree.treebackend->tree->?offset:int->?length:int->key->(string*tree)listLwt.t=fun(moduleT)tree?offset?lengthkey->T.listtree?offset?lengthkeytypewrapped_tree=Wrapped_tree:'tree*'treebackend->wrapped_treetypetree_instance+=Wrappedofwrapped_treemoduleWrapped:Swithtypetree=wrapped_tree=structtypetree=wrapped_treeletremove(Wrapped_tree(t,b))key=letopenLwt.Syntaxinlet+t=removebtkeyinWrapped_tree(t,b)letadd(Wrapped_tree(t,b))keyv=letopenLwt.Syntaxinlet+t=addbtkeyvinWrapped_tree(t,b)letadd_tree(Wrapped_tree(t,b))key(Wrapped_tree(t',b'))=letopenLwt.Syntaxinlett'=selectb(wrapb't')inlet+t=add_treebtkeyt'inWrapped_tree(t,b)letfind_tree(Wrapped_tree(t,b))key=letopenLwt.Syntaxinlet+t'=find_treebtkeyinmatcht'withSomet'->Some(Wrapped_tree(t',b))|None->Noneletlength(Wrapped_tree(t,b))key=lengthbtkeyletlist(Wrapped_tree(t,b))?offset?lengthkey=letopenLwt.Syntaxinlet+list=listbt?offset?lengthkeyinList.rev@@List.rev_map(fun(step,tree)->(step,Wrapped_tree(tree,b)))listletfind(Wrapped_tree(t,b))key=findbtkeylethash(Wrapped_tree(t,b))=hashbtletselect=function|Wrapped(Wrapped_tree(_,_)aswt)->wt|_->raiseIncorrect_tree_typeletwrapt=Wrappedtend