BEGIN { TooBig=2; W=0; array(Breaks); array(Counts } m4_define(maxK, `Breaks[$1,0]') m4_define(maxV, `Breaks[$1,Breaks[$1,0]]') m4_define(minV, `Breaks[$1,Breaks[$1,1]]') m4_define(pushV, `Breaks[$1,++Breaks[$1,0]]=$2') function newW() { W++; return W; } function update(w,x, max,k ksame,maxK) { max = maxV(w); maxK = maxK(w); if (x > max ) { pushV(w,x); k = sizeK(w); } else { if (x < minV(w ) { insert(Breaks,w,1,x); k = 1 } else { k = binchop(w,x) # handle indentical values while (Breaks[w,k+1]==Breaks[w,k] && k < maxK) ksame++ k += int(rand()*ksame) }} Counts[w,k]++; all = ++Counts[w,0]; if ( Counts[w,k]/all > TooBig/maxK ) { } #Binary chop on key-value pairs. #Return the key in "a", of length "most" whose value is closest to "x". function binchop(w,x, most,left,middle,right) { left=1; most = mostK(w); right=most; while (left < right) { middle=int((left+right)/2); if (x> Breaks[w,middle]) {left=middle+1} else {right=middle}; }; return (x=Breaks[w,left]) ? left : 0 } function array(x) { split("",x,"") }