Esempio n. 1
0
  @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());
  }
Esempio n. 2
0
  /** @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);
  }
Esempio n. 3
0
 public int[] buckets() {
   return estimator.buckets();
 }