本文整理汇总了Java中com.clearspring.analytics.stream.cardinality.HyperLogLog.cardinality方法的典型用法代码示例。如果您正苦于以下问题:Java HyperLogLog.cardinality方法的具体用法?Java HyperLogLog.cardinality怎么用?Java HyperLogLog.cardinality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.clearspring.analytics.stream.cardinality.HyperLogLog
的用法示例。
在下文中一共展示了HyperLogLog.cardinality方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: count
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
@Override
public long count() {
final Iterator<HyperLogLog> it = states.iterator();
if (!it.hasNext()) {
return 0L;
}
HyperLogLog current = it.next();
while (it.hasNext()) {
try {
current.addAll(it.next());
} catch (CardinalityMergeException e) {
throw new RuntimeException(e);
}
}
return current.cardinality();
}
示例2: reduce
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
@Override
public Long reduce(List<HyperLogLog> combinedResultList) {
if ((combinedResultList == null) || combinedResultList.isEmpty()) {
return 0L;
}
HyperLogLog reducedResult = combinedResultList.get(0);
for (int i = 1; i < combinedResultList.size(); ++i) {
try {
reducedResult.addAll(combinedResultList.get(i));
} catch (CardinalityMergeException e) {
LOGGER.error("Caught exception while merging Cardinality using HyperLogLog", e);
Utils.rethrowException(e);
}
}
return reducedResult.cardinality();
}
示例3: testInsertionTime
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
@Test
public void testInsertionTime() {
int numOfItems = 10000000;
println("#items_inserted, HLL_time(nano), IntOpenHashSet(nano), time_ratio, estimate, precise, error");
for (int i = 0; i < numOfItems; i+=numOfItems/17) {
if (i == 0) {
continue;
}
RandomNumberArray arr = new RandomNumberArray(i, DUPLICATION_PER_ITEM);
HyperLogLog hllResult = new HyperLogLog(DistinctCountHLLAggregationFunction.DEFAULT_BIT_SIZE);
IntOpenHashSet set = new IntOpenHashSet(); //HashSet<Integer> set = new HashSet<Integer>();
long t1 = System.nanoTime();
arr.offerAllNumberTo(hllResult);
long t2 = System.nanoTime();
arr.offerAllNumberTo(set);
long t3 = System.nanoTime();
long estimate = hllResult.cardinality();
long precise = set.size();
println(i + ", " + "" + (t2 - t1) + ", " + (t3 - t2) + ", " + (t2 - t1 + 0.0) / (t3 - t2 + 0.0) + ", "
+ estimate + ", " + precise + ", " + getErrorString(precise, estimate));
}
assertEquals(true, true);
}
示例4: testMemoryConsumption
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
@Test
public void testMemoryConsumption() {
int numOfItems = 10000000;
println("#items_inserted, HLL_ser_size, openHashSet_ser_size, ser_size_ratio, estimate, precise, error");
for (int i = 0; i < numOfItems; i+=numOfItems/17) {
if (i == 0) {
continue;
}
RandomNumberArray arr = new RandomNumberArray(i, DUPLICATION_PER_ITEM);
HyperLogLog hllResult = new HyperLogLog(DistinctCountHLLAggregationFunction.DEFAULT_BIT_SIZE);
IntOpenHashSet set = new IntOpenHashSet();
arr.offerAllNumberTo(hllResult);
arr.offerAllNumberTo(set);
int hllSize = getSerializedSize(hllResult);
int setSize = getSerializedSize(set);
long estimate = hllResult.cardinality();
long precise = set.size();
println(i + ", " + hllSize + ", " + setSize + ", " + (hllSize + 0.0) / (setSize + 0.0) + ", "
+ estimate + ", " + precise + ", " + getErrorString(precise, estimate));
}
assertEquals(true, true);
}
示例5: fetchUniqueUserCount
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
public int fetchUniqueUserCount(final int minOfDay){
HyperLogLog hllSketch = fetchSketchForMin(minOfDay);
if (hllSketch!=null)
hllSketch.cardinality();
return -1;
}
示例6: count
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
@Override
public Response count(final HyperLogLog log, final Request request) {
return new NumericResponse<>(log.cardinality());
}
示例7: extractFinalResult
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
@Nonnull
@Override
public Long extractFinalResult(@Nonnull HyperLogLog intermediateResult) {
return intermediateResult.cardinality();
}