com.clearspring.analytics.stream.cardinality.HyperLogLog.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(224)

本文整理了Java中com.clearspring.analytics.stream.cardinality.HyperLogLog.<init>()方法的一些代码示例,展示了HyperLogLog.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HyperLogLog.<init>()方法的具体详情如下:
包路径:com.clearspring.analytics.stream.cardinality.HyperLogLog
类名称:HyperLogLog
方法名:<init>

HyperLogLog.<init>介绍

[英]Create a new HyperLogLog instance using the specified standard deviation.
[中]使用指定的标准偏差创建新的HyperLogLog实例。

代码示例

代码示例来源:origin: addthis/stream-lib

@Override
public HyperLogLog build() {
  return new HyperLogLog(log2m);
}

代码示例来源:origin: apache/incubator-pinot

public static HyperLogLog clone(HyperLogLog hll, int log2m) {
 try {
  HyperLogLog ret = new HyperLogLog(log2m);
  ret.addAll(hll);
  return ret;
 } catch (CardinalityMergeException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: apache/incubator-pinot

@Nonnull
@Override
public HyperLogLog extractAggregationResult(@Nonnull AggregationResultHolder aggregationResultHolder) {
 HyperLogLog hyperLogLog = aggregationResultHolder.getResult();
 if (hyperLogLog == null) {
  return new HyperLogLog(DEFAULT_LOG2M);
 } else {
  return hyperLogLog;
 }
}

代码示例来源:origin: apache/incubator-pinot

@Nonnull
@Override
public HyperLogLog extractGroupByResult(@Nonnull GroupByResultHolder groupByResultHolder, int groupKey) {
 HyperLogLog hyperLogLog = groupByResultHolder.getResult(groupKey);
 if (hyperLogLog == null) {
  return new HyperLogLog(_log2m);
 } else {
  return hyperLogLog;
 }
}

代码示例来源:origin: apache/incubator-pinot

@Nonnull
@Override
public HyperLogLog extractGroupByResult(@Nonnull GroupByResultHolder groupByResultHolder, int groupKey) {
 HyperLogLog hyperLogLog = groupByResultHolder.getResult(groupKey);
 if (hyperLogLog == null) {
  return new HyperLogLog(DEFAULT_LOG2M);
 } else {
  return hyperLogLog;
 }
}

代码示例来源:origin: apache/incubator-pinot

@Nonnull
@Override
public HyperLogLog extractAggregationResult(@Nonnull AggregationResultHolder aggregationResultHolder) {
 HyperLogLog hyperLogLog = aggregationResultHolder.getResult();
 if (hyperLogLog == null) {
  return new HyperLogLog(_log2m);
 } else {
  return hyperLogLog;
 }
}

代码示例来源:origin: apache/incubator-pinot

@Override
public HyperLogLog getInitialAggregatedValue(Object rawValue) {
 HyperLogLog initialValue;
 if (rawValue instanceof byte[]) {
  byte[] bytes = (byte[]) rawValue;
  initialValue = deserializeAggregatedValue(bytes);
  _maxByteSize = Math.max(_maxByteSize, bytes.length);
 } else {
  initialValue = new HyperLogLog(DistinctCountHLLAggregationFunction.DEFAULT_LOG2M);
  initialValue.offer(rawValue);
  _maxByteSize = Math.max(_maxByteSize, DEFAULT_LOG2M_BYTE_SIZE);
 }
 return initialValue;
}

代码示例来源:origin: apache/incubator-pinot

/**
 * Returns the HyperLogLog from the result holder or creates a new one if it does not exist.
 *
 * @param aggregationResultHolder Result holder
 * @return HyperLogLog from the result holder
 */
protected static HyperLogLog getHyperLogLog(@Nonnull AggregationResultHolder aggregationResultHolder) {
 HyperLogLog hyperLogLog = aggregationResultHolder.getResult();
 if (hyperLogLog == null) {
  hyperLogLog = new HyperLogLog(DEFAULT_LOG2M);
  aggregationResultHolder.setValue(hyperLogLog);
 }
 return hyperLogLog;
}

代码示例来源:origin: apache/incubator-pinot

/**
 * Returns the HyperLogLog from the result holder or creates a new one if it does not exist.
 *
 * @param aggregationResultHolder Result holder
 * @return HyperLogLog from the result holder
 */
private HyperLogLog getHyperLogLog(@Nonnull AggregationResultHolder aggregationResultHolder) {
 HyperLogLog hyperLogLog = aggregationResultHolder.getResult();
 if (hyperLogLog == null) {
  hyperLogLog = new HyperLogLog(_log2m);
  aggregationResultHolder.setValue(hyperLogLog);
 }
 return hyperLogLog;
}

代码示例来源:origin: apache/incubator-pinot

/**
 * Generate a hll from a single value, and convert it to string type.
 * It is used for default derived field value.
 * @param log2m
 * @param value
 * @return
 */
public static String singleValueHllAsString(int log2m, Object value) {
 HyperLogLog hll = new HyperLogLog(log2m);
 hll.offer(value);
 return convertHllToString(hll);
}

代码示例来源:origin: apache/incubator-pinot

/**
  * Returns the HyperLogLog for the given group key. If one does not exist, creates a new one and returns that.
  *
  * @param groupByResultHolder Result holder
  * @param groupKey Group key for which to return the HyperLogLog
  * @return HyperLogLog for the group key
  */
 private HyperLogLog getHyperLogLog(@Nonnull GroupByResultHolder groupByResultHolder, int groupKey) {
  HyperLogLog hyperLogLog = groupByResultHolder.getResult(groupKey);
  if (hyperLogLog == null) {
   hyperLogLog = new HyperLogLog(_log2m);
   groupByResultHolder.setValueForKey(groupKey, hyperLogLog);
  }
  return hyperLogLog;
 }
}

代码示例来源:origin: addthis/stream-lib

public static HyperLogLog build(DataInput serializedByteStream) throws IOException {
    int log2m = serializedByteStream.readInt();
    int byteArraySize = serializedByteStream.readInt();
    return new HyperLogLog(log2m,
        new RegisterSet(1 << log2m, Bits.getBits(serializedByteStream, byteArraySize)));
  }
}

代码示例来源:origin: apache/incubator-pinot

@Override
Object getRandomRawValue(Random random) {
 HyperLogLog hyperLogLog = new HyperLogLog(LOG2M);
 hyperLogLog.offer(random.nextInt(100));
 hyperLogLog.offer(random.nextInt(100));
 return ObjectSerDeUtils.HYPER_LOG_LOG_SER_DE.serialize(hyperLogLog);
}

代码示例来源:origin: apache/incubator-pinot

@Test
public void testHyperLogLog() {
 for (int i = 0; i < NUM_ITERATIONS; i++) {
  HyperLogLog expected = new HyperLogLog(7);
  byte[] bytes = ObjectSerDeUtils.serialize(expected);
  HyperLogLog actual = ObjectSerDeUtils.deserialize(bytes, ObjectSerDeUtils.ObjectType.HyperLogLog);
  assertEquals(actual.cardinality(), expected.cardinality(), ERROR_MESSAGE);
 }
}

代码示例来源:origin: addthis/stream-lib

@Test
public void testHighCardinality() {
  long start = System.currentTimeMillis();
  HyperLogLog hyperLogLog = new HyperLogLog(10);
  int size = 10000000;
  for (int i = 0; i < size; i++) {
    hyperLogLog.offer(TestICardinality.streamElement(i));
  }
  System.out.println("time: " + (System.currentTimeMillis() - start));
  long estimate = hyperLogLog.cardinality();
  double err = Math.abs(estimate - size) / (double) size;
  System.out.println(err);
  assertTrue(err < .1);
}

代码示例来源:origin: addthis/stream-lib

@Test
public void testHighCardinality_withDefinedRSD() {
  long start = System.currentTimeMillis();
  HyperLogLog hyperLogLog = new HyperLogLog(0.01);
  int size = 100000000;
  for (int i = 0; i < size; i++) {
    hyperLogLog.offer(TestICardinality.streamElement(i));
  }
  System.out.println("time: " + (System.currentTimeMillis() - start));
  long estimate = hyperLogLog.cardinality();
  double err = Math.abs(estimate - size) / (double) size;
  System.out.println(err);
  assertTrue(err < .1);
}

代码示例来源:origin: addthis/stream-lib

/**
 * should not fail with HyperLogLogMergeException: "Cannot merge estimators of different sizes"
 */
@Test
public void testMergeWithRegisterSet() throws CardinalityMergeException {
  HyperLogLog first = new HyperLogLog(16, new RegisterSet(1 << 20));
  HyperLogLog second = new HyperLogLog(16, new RegisterSet(1 << 20));
  first.offer(0);
  second.offer(1);
  first.merge(second);
}

代码示例来源:origin: addthis/stream-lib

@Test
public void testSerialization() throws IOException, ClassNotFoundException {
  HyperLogLog hll = new HyperLogLog(8);
  hll.offer("a");
  hll.offer("b");
  hll.offer("c");
  hll.offer("d");
  hll.offer("e");
  HyperLogLog hll2 = (HyperLogLog) TestUtils.deserialize(TestUtils.serialize(hll));
  assertEquals(hll.cardinality(), hll2.cardinality());
}

代码示例来源:origin: addthis/stream-lib

@Test
public void testSerializationUsingBuilder() throws IOException {
  HyperLogLog hll = new HyperLogLog(8);
  hll.offer("a");
  hll.offer("b");
  hll.offer("c");
  hll.offer("d");
  hll.offer("e");
  HyperLogLog hll2 = HyperLogLog.Builder.build(hll.getBytes());
  assertEquals(hll.cardinality(), hll2.cardinality());
}

代码示例来源:origin: addthis/stream-lib

@Test
public void testComputeCount() {
  HyperLogLog hyperLogLog = new HyperLogLog(16);
  hyperLogLog.offer(0);
  hyperLogLog.offer(1);
  hyperLogLog.offer(2);
  hyperLogLog.offer(3);
  hyperLogLog.offer(16);
  hyperLogLog.offer(17);
  hyperLogLog.offer(18);
  hyperLogLog.offer(19);
  hyperLogLog.offer(19);
  assertEquals(8, hyperLogLog.cardinality());
}

相关文章