123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384(*
* 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.
*)openImportmoduleObject_counter:sigtypetvalstart:unit->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;}->tletstart()=letnb_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(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_leq ~arr ~get ~lo ~hi ~key] returns the nearest entry in the sorted
[arr] that is [<=] the given key. Routine is based on binary search. *)letnearest_leq~arr~get~lo~hi~key=assert(lo<=hi);ifgetarrlo>keythen`All_gt_keyelseifgetarrhi<=keythen`Somehielseletintervallohi=assert(getarrlo<=key&&key<getarrhi);assert(lo<hi);(lo,hi)inintervallohi|>iter_k(fun~k(lo,hi)->iflo+1=hithen`Someloelseletmid=(lo+hi)/2inifgetarrmid<=keythenk(intervalmidhi)elsek(intervallomid))