1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253# 1 "src/base/misc/owl_heavyhitters_sketch.ml"(* functor to make a heavy hitters sketch based on CountMin. *)moduleMake(CM:Owl_countmin_sketch_sig.Sig):Owl_heavyhitters_sketch_sig.Sig=structtype('a,'b)inner={s:(moduleSet.Swithtypeelt='a*intandtypet='b);sketch:'aCM.sketch;mutablequeue:'b;mutablesize:int;k:float}type'at=E:('a,'b)inner->'atletinit~k~epsilon~delta(typea)=letmodulePQPair=structtypet=a*intletcompare(_,p0)(_,p1)=Stdlib.comparep0p1endinletmoduleS=Set.Make(PQPair)inE{s=(moduleS);sketch=CM.init~epsilon~delta;queue=S.empty;size=0;k}letadd(typea)(Eh:at)v=letmodulePQSet=(valh.s)inCM.incrh.sketchv;h.size<-h.size+1;letv_count=CM.counth.sketchvinletthreshold=float_of_inth.size/.h.kinifv_count|>float_of_int>thresholdthenh.queue<-h.queue|>PQSet.partition(fun(x,_)->x=v)|>snd|>PQSet.add(v,v_count)else();letrecclean_queuequeue=matchPQSet.min_elt_optqueuewith|Some(x,c)->iffloat_of_intc<thresholdthenclean_queue(PQSet.remove(x,c)queue)elsequeue|None->queueinh.queue<-clean_queueh.queueletget(typea)(Eh:at)=letmodulePQSet=(valh.s)inPQSet.elementsh.queue|>List.revendmoduleNative=Make(Owl_countmin_sketch.Native)moduleOwl=Make(Owl_countmin_sketch.Owl)