/* * Copyright 2013 Aggregate Knowledge, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ if(hll===undefined){var hll={version:"1.0.0"}}(function(){var c=5,m=13;var b=0,g=1;hll.HLL=function(C,x){var D=this;if(arguments.length<1){C=m}if(arguments.length<2){x=c}if((C<4)||(C>24)){throw new Error("Register width must be between 4 and 24 inclusive (log2m = "+C+").")}if((x<1)||(x>5)){throw new Error("Register width must be between 1 and 5 inclusive (registerWidth = "+x+").")}D.log2m=C;D.m=1<=0;t--){D.registers.push(0)}var B=((1<>>0;var s=((1<>>0;var w=B-1,y=w+C,r=Math.pow(2,y);var u=(r/30),v=5*D.registers.length/2;var z=e(D.m);function A(F){var E=hll.util.leastSignificantBit(F[b])+1;return Math.min(B,E)}D.addRaw=function(G){var E=G[b]&s;var F=A(hll.util.shiftRightUnsignedLong(G,C));D.registers[E]=Math.max(D.registers[E],F)};D.algorithmCardinality=function(){var E=D.m;var I=0;var J=0;var F=D.registers;for(var G=E-1;G>=0;G--){var H=F[G];I+=1/((1<>>0);if(H==0){J++}}var K=z/I;if((J!=0)&&(K=0;J--){K[J]=Math.max(K[J],F[J])}return D};D.fold=function(F){if(F==D.log2m){return D.clone()}if((F<1)||(F>D.log2m)){throw new Error("'log2m' cannot be less than 1 or greater than the current value.")}var J=new hll.HLL(F,D.registerWidth);var I=J.registers,H=D.registers;var K=D.log2m-F,E=J.m;for(var G=E-1;G>=0;G--){I[G]=Math.min(H[G]+K,B)}return J};D.clone=function(){var H=new hll.HLL(D.log2m,D.registerWidth);var G=D.registers,E=H.registers;for(var F=D.m-1;F>=0;F--){E[F]=G[F]}return H};D.clear=function(){var E=D.registers;for(var F=D.m-1;F>=0;F--){E[F]=0}return D};D.toHexString=function(){var H=new hll.util.ByteWriter();H.addBits(20,8);H.addBits(x-1,3);H.addBits(C,5);H.addBits(0,8);var E=D.m;var F=D.registers;for(var G=0;G=0;u--){v.push(hll.util.getBitSequenceValueFromByteArray(A,s,x));s+=x}var r=new hll.HLL(z,x);r.registers=v;return r}function h(s){var r=new Uint8Array(s);return j(s,3,p(r[1]))}function k(s){var r=new Uint8Array(s);return o(p(r[1]))}function i(s){var r=new Uint8Array(s);return n(s,3,p(r[1]))}function o(r){return new hll.HLL(r.log2m,r.registerWidth)}function n(t,x,u){var w=new hll.HLL(u.log2m,u.registerWidth);var r=new Uint8Array(t);var s=x;while(s=0;v--){w.push(0)}var D=u*l;D+=(t*y)%l;var E=new Uint8Array(x);var r=Math.floor(((E.length-u)*l)/(C+y));for(var v=r-1;v>=0;v--){var A=hll.util.getBitSequenceValueFromByteArray(E,D,C);D+=C;var z=hll.util.getBitSequenceValueFromByteArray(E,D,y);D+=y;w[A]=z}var s=new hll.HLL(C,y);s.registers=w;return s}})(); if(hll===undefined){var hll={version:"1.0.0"}}if(hll.util===undefined){hll.util={version:"1.0.0"}}(function(){var d=8;var a=0,b=1;hll.util.shiftRightLong=function(h,e){e&=63;if(e==0){return h}var g=h[b];if(e<32){var f=h[a];return[((f>>>e)|(g<<(32-e))),(g>>e)]}else{return[(g>>(e-32)),(g>=0?0:-1)]}};hll.util.shiftRightUnsignedLong=function(h,e){e&=63;if(e==0){return h}var g=h[b];if(e<32){var f=h[a];return[((f>>>e)|(g<<(32-e))),(g>>>e)]}else{if(numBits==32){return[g,0]}else{return[(g>>>(e-32)),0]}}};hll.util.extractLong=function(e,h){var f=0,g=0;g|=e[h]<<24;g|=e[h+1]<<16;g|=e[h+2]<<8;g|=e[h+3];f|=e[h+4]<<24;f|=e[h+5]<<16;f|=e[h+6]<<8;f|=e[h+7];return[f>>>0,g>>>0]};hll.util.upperNibble=function(e){return e>>4};hll.util.lowerNibble=function(e){return e&15};hll.util.hexToArrayBuffer=function(j){j=j.substring(2);var h=j.length/2;var g=new ArrayBuffer(h);var f=new Uint8Array(g);for(var e=0;e>>(d-(g+e)))&((1<>>3;var l=(e+g)>>>3;var m=e&7;if(h==l){return hll.util.getBitSequenceFromByte(o[l],m,g)}var n=(e+g)&7;var p=0;var f=0;for(var k=l;k>=h;k--){var j;if(k==h){j=hll.util.getBitSequenceFromByte(o[k],m,d-m)}else{if(k==l){j=hll.util.getBitSequenceFromByte(o[k],0,n)}else{j=o[k]}}p|=j<>>0)&255)]+0}if((e&65535)!=0){return c[((e>>>8)&255)]+8}if((e&16777215)!=0){return c[((e>>>16)&255)]+16}return c[((e>>>24)&255)]+24};hll.util.ByteWriter=function(){var f=this;var h=0;var e=[];var g=d;f.addBits=function(m,k){var l=k;while(l>0){var i=Math.min(l,g);var j=((m>>>(l-i))&((1<>>0;h|=(j<<(g-i));l-=i;g-=i;if(g<=0){e.push(h);h=0;g=d}}};f.getBytes=function(){if(g