12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091(*
* Copyright (c) 2018-2022 Tarides <contact@tarides.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.
*)open!ImportmoduleObject_counter:sigtypetvalstart:Format.formatter->t*((unit->unit)*(unit->unit)*(unit->unit))valfinalise:t->unitvalfinalise_with_stats:t->int*int*intend=structtypet=|Object_counter:{display:(_,_)Progress.Display.t;nb_commits:intref;nb_nodes:intref;nb_contents:intref;}->tletstartppf=letconfig=Progress.Config.v~ppf()inletnb_commits=ref0inletnb_nodes=ref0inletnb_contents=ref0inletbar=letopenProgress.Lineinletcount_to_string(contents,nodes,commits)=Fmt.str"%dk contents / %dk nodes / %d commits"(contents/1000)(nodes/1000)commitsinusingcount_to_stringstringinletdisplay=Progress.Display.start~config(Progress.Multi.linebar)inlet[reporter]=Progress.Display.reportersdisplayinletupdate_fncount()=incrcount;reporter(!nb_contents,!nb_nodes,!nb_commits)inletcontents=update_fnnb_contentsandnodes=update_fnnb_nodesandcommits=update_fnnb_commitsin(Object_counter{display;nb_contents;nb_nodes;nb_commits},(contents,nodes,commits))letfinalise(Object_countert)=Progress.Display.finaliset.displayletfinalise_with_stats(Object_countertast_outer)=finaliset_outer;(!(t.nb_contents),!(t.nb_nodes),!(t.nb_commits))end(** [nearest_geq ~arr ~get ~lo ~hi ~key] returns the index of the nearest entry
in the sorted [arr] that is [>=] the given key. Routine is based on binary
search. *)letnearest_geq~arr~get~lo~hi~key=iflo>hithenNoneelsematchStdlib.comparekey(getarrhi)with|0->Somehi|cwhenc>0->None|_whengetarrlo>=key->Somelo|_->letrecsearchlohi=assert(lo<hi);assert(getarrlo<key&&key<getarrhi);iflo+1=hithenSomehielseletmid=(lo+hi)/2inmatchStdlib.comparekey(getarrmid)with|0->Somemid|cwhenc<0->searchlomid|_->searchmidhiinsearchlohi