/** * Switch from exact counting to estimation */ private void tip() { estimator = builder.build(); for (Object o : counter) { estimator.offer(o); } counter = null; builder = null; tipped = true; }
/** * Deserialization constructor * * @param bytes * @throws IOException * @throws ClassNotFoundException */ public CountThenEstimate(byte[] bytes) throws IOException, ClassNotFoundException { readExternal(new ObjectInputStream(new ByteArrayInputStream(bytes))); if (!tipped && builder.sizeof() <= bytes.length) { tip(); } }
estimators[t] = builder.build();
/** * Deserialization constructor * * @param bytes * @throws IOException * @throws ClassNotFoundException */ public CountThenEstimate(byte[] bytes) throws IOException, ClassNotFoundException { readExternal(new ObjectInputStream(new ByteArrayInputStream(bytes))); if (!tipped && builder.sizeof() <= bytes.length) { tip(); } }
/** * Switch from exact counting to estimation */ private void tip() { estimator = builder.build(); for (Object o : counter) { estimator.offer(o); } counter = null; builder = null; tipped = true; }
/** * Create a new count-then-estimate cardinality object with the tipping point provided. * After this has been reached, the provided builder will be used to create an estimator. * * @param tippingPoint Cardinality at which exact counting gives way to estimation * @param builder Factory for instantiating estimator after the tipping point is reached */ public CountThenEstimateBytes(final int tippingPoint, final IBuilder<ICardinality> builder) { _tippingPoint = tippingPoint; _builder = builder; if(tippingPoint == 0) { _counter = null; _estimator = builder.build(); _tipped = true; } else { _counter = new BytesRefHash(); } }
/** * Switch from exact counting to estimation. */ private void tip() { if(!_tipped) { _estimator = _builder.build(); process(_counter, new Procedure() { @Override public void consume(final BytesRef ref) { _estimator.offerHashed(__luceneMurmurHash.hash(ref)); } }); _counter = null; _longestBytesRefSize = 0; _builder = null; _tipped = true; _compacted = true; } }
public static void main(String[] args) throws IOException { long updateRate = -1; long count = 0; if (args.length > 0) { try { updateRate = Long.parseLong(args[0]); } catch (NumberFormatException e) { System.err.print("Bad update rate: '" + args[0] + "' Update rate must be an integer."); usage(); } } ICardinality card = AdaptiveCounting.Builder.obyCount(Integer.MAX_VALUE).build(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line = null; while ((line = in.readLine()) != null) { card.offer(line); count++; if (updateRate > 0 && count % updateRate == 0) { System.out.println(formatSummary(count, card.cardinality())); } } System.out.println(formatSummary(count, card.cardinality())); }
switch (dc.ver) { case VER_ADAPTIVE: dc.ic = max >= 0 ? AdaptiveCounting.Builder.obyCount(max).build() : new AdaptiveCounting(size); if (dc.ic instanceof LinearCounting) { dc.ver = VER_LINEAR;