Esempio n. 1
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. 2
0
 public int getSizeInBytes() {
   return estimator.estimateSizeInBytes() + INSTANCE_SIZE;
 }