com.hazelcast.cardinality

## Interface CardinalityEstimator

- All Superinterfaces:
    DistributedObject
  All Known Implementing Classes:
    ClientCardinalityEstimatorProxy

      public interface CardinalityEstimator
      extends DistributedObject

  CardinalityEstimator is a redundant and highly available distributed data-structure used for probabilistic cardinality estimation purposes, on unique items, in significantly sized data cultures.

  CardinalityEstimator is internally based on a HyperLogLog++ data-structure, and uses P^2 byte registers for storage and computation. (Default P = 14)

  Supports Quorum `QuorumConfig` since 3.10 in cluster versions 3.10 and higher.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(Object obj)` Add a new object in the estimation set.
    `ICompletableFuture<Void>` | `addAsync(Object obj)` Add a new object in the estimation set.
    `long` | `estimate()` Estimates the cardinality of the aggregation so far.
    `ICompletableFuture<Long>` | `estimateAsync()` Estimates the cardinality of the aggregation so far.

    - ### Methods inherited from interface com.hazelcast.core.DistributedObject

      `destroy, getName, getPartitionKey, getServiceName`

- - ### Method Detail

    - #### add

          void add(Object obj)

      Add a new object in the estimation set. This is the method you want to use to feed objects into the estimator.

      Objects are considered identical if they are serialized into the same binary blob. In other words: It does not use Java equality.

      Parameters:
        `obj` - object to add in the estimation set.
      Throws:
        `NullPointerException` - if obj is null
      Since:
        3.8

    - #### estimate

          long estimate()

      Estimates the cardinality of the aggregation so far. If it was previously estimated and never invalidated, then a cached version is used.
      Returns:
        a cached estimation or a newly computed one.
      Since:
        3.8

    - #### addAsync

          ICompletableFuture<Void> addAsync(Object obj)

      Add a new object in the estimation set. This is the method you want to use to feed objects into the estimator.

      Objects are considered identical if they are serialized into the same binary blob. In other words: It does not use Java equality.

      This method will dispatch a request and return immediately an `ICompletableFuture`. The operations result can be obtained in a blocking way, or a callback can be provided for execution upon completion, as demonstrated in the following examples:

               ICompletableFuture<Void> future = estimator.addAsync();
               // do something else, then read the result
               Boolean result = future.get(); // this method will block until the result is available

               ICompletableFuture<Void> future = estimator.addAsync();
               future.andThen(new ExecutionCallback<Void>() {
                    void onResponse(Void response) {
                        // do something
                    }

                    void onFailure(Throwable t) {
                        // handle failure
                    }
               });

      Parameters:
        `obj` - object to add in the estimation set.
      Returns:
        an `ICompletableFuture` API consumers can use to track execution of this request.
      Throws:
        `NullPointerException` - if obj is null
      Since:
        3.8

    - #### estimateAsync

          ICompletableFuture<Long> estimateAsync()

      Estimates the cardinality of the aggregation so far. If it was previously estimated and never invalidated, then a cached version is used.

      This method will dispatch a request and return immediately an `ICompletableFuture`. The operations result can be obtained in a blocking way, or a callback can be provided for execution upon completion, as demonstrated in the following examples:

               ICompletableFuture<Long> future = estimator.estimateAsync();
               // do something else, then read the result
               Long result = future.get(); // this method will block until the result is available

               ICompletableFuture<Long> future = estimator.estimateAsync();
               future.andThen(new ExecutionCallback<Long>() {
                    void onResponse(Long response) {
                        // do something with the result
                    }

                    void onFailure(Throwable t) {
                        // handle failure
                    }
               });

      Returns:
        `ICompletableFuture` bearing the response, the estimate.
      Since:
        3.8

Copyright © 2019. All rights reserved.