Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file caqti_heap.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960(* Copyright (C) 2014--2016 Petter A. Urkedal <paurkedal@gmail.com>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version, with the OCaml static compilation exception.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*)moduletypeS=sigtypeelttypetvalempty:tvalis_empty:t->boolvalcard:t->intvalpush:elt->t->tvalmerge:t->t->tvalpop_e:t->elt*tendmoduleMake(Elt:Set.OrderedType)=structtypeelt=Elt.ttypet=O|Yofint*elt*t*tletempty=Oletis_emptyh=h=Oletcard=function|O->0|Y(n,_,_,_)->nletrecpushe'=function|O->Y(1,e',O,O)|Y(n,e,hL,hR)->lete_min,e_max=ifElt.comparee'e<0thene',eelsee,e'inifcardhL<cardhRthenY(n+1,e_min,pushe_maxhL,hR)elseY(n+1,e_min,hL,pushe_maxhR)letrecmergehLhR=matchhL,hRwith|O,h|h,O->h|Y(nL,eL,hA,hB),Y(nR,eR,hC,hD)->ifElt.compareeLeR<0thenY(nL+nR,eL,mergehAhB,hR)elseY(nL+nR,eR,hL,mergehChD)letpop_e=function|O->invalid_arg"Caqti_heap.pop_e: Empty heap."|Y(_,e,hL,hR)->e,mergehLhRend