io.airlift.stats.cardinality.HyperLogLog类的使用及代码示例

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

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

HyperLogLog介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

@Override
  public Object getExpectedValue(int start, int length)
  {
    if (length == 0) {
      return null;
    }

    HyperLogLog hll = HyperLogLog.newInstance(NUMBER_OF_BUCKETS);
    for (int i = start; i < start + length; i++) {
      hll.add(i);
    }
    hll.makeDense();
    return new SqlVarbinary(hll.serialize().getBytes());
  }
}

代码示例来源:origin: prestodb/presto

@ScalarFunction
@Description("compute the cardinality of a HyperLogLog instance")
@SqlType(StandardTypes.BIGINT)
public static long cardinality(@SqlType(StandardTypes.HYPER_LOG_LOG) Slice serializedHll)
{
  return HyperLogLog.newInstance(serializedHll).cardinality();
}

代码示例来源:origin: prestodb/presto

@InputFunction
public static void input(@AggregationState HyperLogLogState state, @SqlType(StandardTypes.DOUBLE) double value)
{
  HyperLogLog hll = getOrCreateHyperLogLog(state);
  state.addMemoryUsage(-hll.estimatedInMemorySize());
  hll.add(Double.doubleToLongBits(value));
  state.addMemoryUsage(hll.estimatedInMemorySize());
}

代码示例来源:origin: prestodb/presto

@ScalarOperator(CAST)
@SqlType(StandardTypes.P4_HYPER_LOG_LOG)
public static Slice castToP4Hll(@SqlType(StandardTypes.HYPER_LOG_LOG) Slice slice)
{
  HyperLogLog hll = HyperLogLog.newInstance(slice);
  hll.makeDense();
  return hll.serialize();
}

代码示例来源:origin: prestodb/presto

@ScalarFunction
  @SqlType(StandardTypes.HYPER_LOG_LOG)
  public static Slice createHll(@SqlType(StandardTypes.BIGINT) long value)
  {
    HyperLogLog hll = HyperLogLog.newInstance(4096);
    hll.add(value);
    return hll.serialize();
  }
}

代码示例来源:origin: prestodb/presto

private static void merge(@AggregationState HyperLogLogState state, HyperLogLog input)
{
  HyperLogLog previous = state.getHyperLogLog();
  if (previous == null) {
    state.setHyperLogLog(input);
    state.addMemoryUsage(input.estimatedInMemorySize());
  }
  else {
    state.addMemoryUsage(-previous.estimatedInMemorySize());
    previous.mergeWith(input);
    state.addMemoryUsage(previous.estimatedInMemorySize());
  }
}

代码示例来源:origin: airlift/airlift

private void verifyRoundtrip(List<Long> sequence)
  {
    HyperLogLog hll = HyperLogLog.newInstance(2048);

    for (Long value : sequence) {
      hll.add(value);
    }

    hll.verify();

    Slice serialized = hll.serialize();
    HyperLogLog deserialized = HyperLogLog.newInstance(serialized);
    deserialized.verify();

    assertEquals(hll.cardinality(), deserialized.cardinality());

    Slice reserialized = deserialized.serialize();
    assertSlicesEqual(serialized, reserialized);
  }
}

代码示例来源:origin: io.airlift/stats

HyperLogLog hll = HyperLogLog.newInstance(numberOfBuckets);
for (int cardinality = 1; cardinality <= maxCardinality; cardinality++) {
  hll.add(ThreadLocalRandom.current().nextLong());
    double error = (hll.cardinality() - cardinality) * 1.0 / cardinality;

代码示例来源:origin: prestodb/presto

@Override
public void serialize(HyperLogLogState state, BlockBuilder out)
{
  if (state.getHyperLogLog() == null) {
    out.appendNull();
  }
  else {
    HYPER_LOG_LOG.writeSlice(out, state.getHyperLogLog().serialize());
  }
}

代码示例来源:origin: prestodb/presto

private static HyperLogLog getOrCreateHyperLogLog(HyperLogLogState state, double maxStandardError)
{
  HyperLogLog hll = state.getHyperLogLog();
  if (hll == null) {
    hll = HyperLogLog.newInstance(standardErrorToBuckets(maxStandardError));
    state.setHyperLogLog(hll);
    state.addMemoryUsage(hll.estimatedInMemorySize());
  }
  return hll;
}

代码示例来源:origin: prestodb/presto

public static HyperLogLog newHyperLogLog()
{
  return HyperLogLog.newInstance(NUMBER_OF_BUCKETS);
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

@InputFunction
@IntermediateInputFunction
public static void merge(HyperLogLogState state, @SqlType(StandardTypes.HYPER_LOG_LOG) Slice value)
{
  HyperLogLog input = HyperLogLog.newInstance(value);
  HyperLogLog previous = state.getHyperLogLog();
  if (previous == null) {
    state.setHyperLogLog(input);
    state.addMemoryUsage(input.estimatedInMemorySize());
  }
  else {
    state.addMemoryUsage(-previous.estimatedInMemorySize());
    previous.mergeWith(input);
    state.addMemoryUsage(previous.estimatedInMemorySize());
  }
}

代码示例来源:origin: prestodb/presto

@InputFunction
@TypeParameter("T")
public static void input(
    @OperatorDependency(operator = XX_HASH_64, returnType = StandardTypes.BIGINT, argumentTypes = {"T"}) MethodHandle methodHandle,
    @AggregationState HyperLogLogState state,
    @SqlType("T") Slice value,
    @SqlType(StandardTypes.DOUBLE) double maxStandardError)
{
  HyperLogLog hll = getOrCreateHyperLogLog(state, maxStandardError);
  state.addMemoryUsage(-hll.estimatedInMemorySize());
  long hash;
  try {
    hash = (long) methodHandle.invokeExact(value);
  }
  catch (Throwable t) {
    throw internalError(t);
  }
  hll.addHash(hash);
  state.addMemoryUsage(hll.estimatedInMemorySize());
}

代码示例来源:origin: prestodb/presto

public void add(Slice value)
{
  addHash(Murmur3.hash64(value));
  hll.add(value);
}

代码示例来源:origin: prestodb/presto

public long cardinality()
{
  if (isExact()) {
    return minhash.size();
  }
  return hll.cardinality();
}

代码示例来源:origin: prestodb/presto

@Override
  public long getEstimatedSize()
  {
    long estimatedSize = INSTANCE_SIZE;
    if (hll != null) {
      estimatedSize += hll.estimatedInMemorySize();
    }
    return estimatedSize;
  }
}

代码示例来源:origin: prestodb/presto

public void mergeWith(SetDigest other)
{
  hll.mergeWith(other.hll);
  LongBidirectionalIterator iterator = other.minhash.keySet().iterator();
  while (iterator.hasNext()) {
    long key = iterator.nextLong();
    int count = minhash.get(key) + other.minhash.get(key);
    minhash.put(key, Shorts.saturatedCast(count));
  }
  while (minhash.size() > maxHashes) {
    minhash.remove(minhash.lastLongKey());
  }
}

代码示例来源:origin: io.airlift/stats

public void add(long value)
{
  addHash(Murmur3Hash128.hash64(value));
}

代码示例来源:origin: prestodb/presto

private static Slice nextHyperLogLog(Random random)
{
  HyperLogLog hll = HyperLogLog.newInstance(HYPER_LOG_LOG_BUCKETS);
  int size = random.nextInt(MAX_HYPER_LOG_LOG_ELEMENTS);
  for (int i = 0; i < size; i++) {
    hll.add(random.nextLong());
  }
  return hll.serialize();
}

代码示例来源:origin: airlift/airlift

private void verifyMerge(List<Long> one, List<Long> two)
{
  HyperLogLog hll1 = HyperLogLog.newInstance(2048);
  HyperLogLog hll2 = HyperLogLog.newInstance(2048);
  HyperLogLog expected = HyperLogLog.newInstance(2048);
  for (long value : one) {
    hll1.add(value);
    expected.add(value);
  }
  for (long value : two) {
    hll2.add(value);
    expected.add(value);
  }
  hll1.verify();
  hll2.verify();
  hll1.mergeWith(hll2);
  hll1.verify();
  assertEquals(hll1.cardinality(), expected.cardinality());
  assertEquals(hll1.serialize(), expected.serialize());
}

相关文章