@Test public void testRoundtrip() { Estimator estimator = getEstimator(); for (int i = 0; i < estimator.getNumberOfBuckets(); i++) { estimator.setIfGreater(i, i % 16); } DenseEstimator other = new DenseEstimator(estimator.buckets()); assertEquals(estimator.buckets(), other.buckets()); }
/** @return true if the estimation was affected by this addition */ public boolean add(long value) { BucketAndHash bucketAndHash = fromHash(computeHash(value), estimator.getNumberOfBuckets()); int lowestBitPosition = Long.numberOfTrailingZeros(bucketAndHash.getHash()) + 1; if (estimator.getClass() == SparseEstimator.class && (estimator.estimateSizeInBytes() >= DenseEstimator.estimateSizeInBytes(estimator.getNumberOfBuckets()) || lowestBitPosition >= SparseEstimator.MAX_BUCKET_VALUE)) { estimator = new DenseEstimator(estimator.buckets()); } return estimator.setIfGreater(bucketAndHash.getBucket(), lowestBitPosition); }
public int[] buckets() { return estimator.buckets(); }