Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file lwt_pqueue.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990(* This file is part of Lwt, released under the MIT license. See LICENSE.md for
details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)moduletypeOrderedType=sigtypetvalcompare:t->t->intendmoduletypeS=sigtypeelttypetvalempty:tvalis_empty:t->boolvaladd:elt->t->tvalunion:t->t->tvalfind_min:t->eltvallookup_min:t->eltoptionvalremove_min:t->tvalsize:t->intendmoduleMake(Ord:OrderedType):(Swithtypeelt=Ord.t)=structtypeelt=Ord.ttypet=treelistandtree=Nodeofelt*int*treelistletroot(Node(x,_,_))=xletrank(Node(_,r,_))=rletlink(Node(x1,r1,c1)ast1)(Node(x2,r2,c2)ast2)=letc=Ord.comparex1x2inifc<=0thenNode(x1,r1+1,t2::c1)elseNode(x2,r2+1,t1::c2)letrecinst=function[]->[t]|(t'::_)astswhenrankt<rankt'->t::ts|t'::ts->ins(linktt')tsletempty=[]letis_emptyts=ts=[]letaddxts=ins(Node(x,0,[]))tsletrecuniontsts'=matchts,ts'with([],_)->ts'|(_,[])->ts|(t1::ts1,t2::ts2)->ifrankt1<rankt2thent1::unionts1(t2::ts2)elseifrankt2<rankt1thent2::union(t1::ts1)ts2elseins(linkt1t2)(unionts1ts2)letrecfind_min=function[]->raiseNot_found|[t]->roott|t::ts->letx=find_mintsinletc=Ord.compare(roott)xinifc<0thenroottelsexletlookup_mint=trySome(find_mint)withNot_found->Noneletrecget_min=function[]->assertfalse|[t]->(t,[])|t::ts->let(t',ts')=get_mintsinletc=Ord.compare(roott)(roott')inifc<0then(t,ts)else(t',t::ts')letremove_min=function[]->raiseNot_found|ts->let(Node(_,_,c),ts)=get_mintsinunion(List.revc)tsletrecsizel=letsizetree(Node(_,_,tl))=1+sizetlinList.fold_left(funst->s+sizetreet)0lend