• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java HLL类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.agkn.hll.HLL的典型用法代码示例。如果您正苦于以下问题:Java HLL类的具体用法?Java HLL怎么用?Java HLL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HLL类属于net.agkn.hll包,在下文中一共展示了HLL类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: assertCardinality

import net.agkn.hll.HLL; //导入依赖的package包/类
private static void assertCardinality(final HLLType hllType, final Collection<Long> items)
       throws CloneNotSupportedException {
    for(int log2m=MINIMUM_LOG2M_PARAM; log2m<=16; log2m++) {
        for(int regw=MINIMUM_REGWIDTH_PARAM; regw<=MAXIMUM_REGWIDTH_PARAM; regw++) {
            for(int expthr=MINIMUM_EXPTHRESH_PARAM; expthr<=MAXIMUM_EXPTHRESH_PARAM; expthr++ ) {
                for(final boolean sparse: new boolean[]{true, false}) {
                    HLL hll = new HLL(log2m, regw, expthr, sparse, hllType);
                    for(final Long item: items) {
                        hll.addRaw(item);
                    }
                    HLL copy = HLL.fromBytes(hll.toBytes());
                    assertEquals(copy.cardinality(), hll.cardinality());
                    assertEquals(copy.getType(), hll.getType());
                    assertEquals(copy.toBytes(), hll.toBytes());

                    HLL clone = hll.clone();
                    assertEquals(clone.cardinality(), hll.cardinality());
                    assertEquals(clone.getType(), hll.getType());
                    assertEquals(clone.toBytes(), hll.toBytes());
                }
            }
        }
    }
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:25,代码来源:HLLSerializationTest.java


示例2: globalStepTest

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Cumulatively adds random values to an EMPTY HLL.
 *
 * Format: cumulative add
 * Tests:
 * - EMPTY, EXPLICIT, SPARSE, PROBABILSTIC addition
 * - EMPTY to EXPLICIT promotion
 * - EXPLICIT to SPARSE promotion
 * - SPARSE to FULL promotion
 */
private static void globalStepTest(final ISchemaVersion schemaVersion) throws IOException {
    final FileWriter output = openOutput(schemaVersion, "comprehensive_promotion", TestType.ADD);

    final Random random = new Random(SEED);

    // the accumulator, starts empty
    final HLL hll = newHLL(HLLType.EMPTY);
    initLineAdd(output, hll, schemaVersion);

    for(int i=0; i<10000/*arbitrary*/; i++) {
        cumulativeAddLine(output, hll, random.nextLong(), schemaVersion);
    }

    output.flush();
    output.close();
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:27,代码来源:IntegrationTestGenerator.java


示例3: sparseStepTest

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Cumulatively sets successive registers to:
 *
 *     <code>(registerIndex % REGISTER_MAX_VALUE) + 1</code>
 *
 * by adding specifically constructed values to a SPARSE HLL.
 * Does not induce promotion.
 *
 * Format: cumulative add
 * Tests:
 * - SPARSE addition (predictable)
 */
private static void sparseStepTest(final ISchemaVersion schemaVersion) throws IOException {
    final FileWriter output = openOutput(schemaVersion, "sparse_step", TestType.ADD);

    // the accumulator, starts empty sparse probabilistic
    final HLL hll = newHLL(HLLType.SPARSE);
    initLineAdd(output, hll, schemaVersion);

    for(int i=0; i<SPARSE_THRESHOLD; i++) {
        final long rawValue = constructHLLValue(LOG2M, i, ((i % REGISTER_MAX_VALUE) + 1));
        cumulativeAddLine(output, hll, rawValue, schemaVersion);
    }

    output.flush();
    output.close();
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:28,代码来源:IntegrationTestGenerator.java


示例4: sparseRandomTest

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Cumulatively sets random registers of a SPARSE HLL to
 * random values by adding random values. Does not induce promotion.
 *
 * Format: cumulative add
 * Tests:
 * - SPARSE addition (random)
 */
private static void sparseRandomTest(final ISchemaVersion schemaVersion) throws IOException {
    final FileWriter output = openOutput(schemaVersion, "sparse_random", TestType.ADD);

    final Random random = new Random(SEED);

    // the accumulator, starts empty
    final HLL hll = newHLL(HLLType.SPARSE);
    initLineAdd(output, hll, schemaVersion);

    for(int i=0; i<SPARSE_THRESHOLD; i++) {
        final int registerIndex = Math.abs(random.nextInt()) % REGISTER_COUNT;
        final int registerValue = ((Math.abs(random.nextInt()) % REGISTER_MAX_VALUE) + 1);
        final long rawValue = constructHLLValue(LOG2M, registerIndex, registerValue);

        cumulativeAddLine(output, hll, rawValue, schemaVersion);
    }

    output.flush();
    output.close();
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:29,代码来源:IntegrationTestGenerator.java


示例5: sparseEdgeTest

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Cumulatively sets the first register (index 0) to value 2, the last
 * register (index m-1) to value 2, and then sets registers with indices in
 * the range 2 to (sparseCutoff + 2) to value 1 to trigger promotion.
 *
 * This tests for register alignment in the promotion from SPARSE
 * to FULL.
 *
 * Format: cumulative add
 * Tests:
 * - SPARSE addition
 * - SPARSE to FULL promotion
 */
private static void sparseEdgeTest(final ISchemaVersion schemaVersion) throws IOException {
    final FileWriter output = openOutput(schemaVersion, "sparse_edge", TestType.ADD);

    // the accumulator, starts empty
    final HLL hll = newHLL(HLLType.SPARSE);
    initLineAdd(output, hll, schemaVersion);

    final long firstValue = constructHLLValue(LOG2M, 0, 2);
    cumulativeAddLine(output, hll, firstValue, schemaVersion);

    final long lastValue = constructHLLValue(LOG2M, (1 << LOG2M) - 1, 2);
    cumulativeAddLine(output, hll, lastValue, schemaVersion);

    for(int i=2; i<(SPARSE_THRESHOLD + 2); i++) {
        final long middleValue = constructHLLValue(LOG2M, i, 1);

        cumulativeAddLine(output, hll, middleValue, schemaVersion);
    }

    output.flush();
    output.close();
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:36,代码来源:IntegrationTestGenerator.java


示例6: explicitPromotionTest

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Unions an EMPTY accumulator with EXPLICIT HLLs, each containing a
 * single random value.
 *
 * Format: cumulative union
 * Tests:
 * - EMPTY U EXPLICIT
 * - EXPLICIT U EXPLICIT
 * - EXPLICIT to SPARSE promotion
 * - SPARSE U EXPLICIT
 */
private static void explicitPromotionTest(final ISchemaVersion schemaVersion) throws IOException {
    final FileWriter output = openOutput(schemaVersion, "explicit_promotion", TestType.UNION);

    final Random random = new Random(SEED);

    // the accumulator, starts empty
    final HLL hll = newHLL(HLLType.EMPTY);
    final HLL emptyHLL = newHLL(HLLType.EMPTY);
    cumulativeUnionLine(output, hll, emptyHLL, schemaVersion);

    for(int i=0; i<(EXPLICIT_THRESHOLD+500)/*should be greater than promotion cutoff*/; i++) {
        // make an EXPLICIT set and populate with cardinality 1
        final HLL explicitHLL = newHLL(HLLType.EXPLICIT);
        explicitHLL.addRaw(random.nextLong());

        cumulativeUnionLine(output, hll, explicitHLL, schemaVersion);
    }

    output.flush();
    output.close();
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:33,代码来源:IntegrationTestGenerator.java


示例7: explicitOverlapTest

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Unions an EMPTY accumulator with EXPLICIT HLLs, each having a single
 * random value, twice in a row to verify that the set properties are
 * satisfied.
 *
 * Format: cumulative union
 * Tests:
 * - EMPTY U EXPLICIT
 * - EXPLICIT U EXPLICIT
 */
private static void explicitOverlapTest(final ISchemaVersion schemaVersion) throws IOException {
    final FileWriter output = openOutput(schemaVersion, "explicit_explicit", TestType.UNION);

    final Random random = new Random(SEED);

    // the accumulator, starts empty
    final HLL hll = newHLL(HLLType.EMPTY);
    final HLL emptyHLL = newHLL(HLLType.EMPTY);

    cumulativeUnionLine(output, hll, emptyHLL, schemaVersion);

    for(int i=0; i<EXPLICIT_THRESHOLD; i++) {
        // make an EXPLICIT set and populate with cardinality 1
        final HLL explicitHLL = newHLL(HLLType.EXPLICIT);
        explicitHLL.addRaw(random.nextLong());

        // union it into the accumulator twice, to test overlap (cardinality should not change)
        cumulativeUnionLine(output, hll, explicitHLL, schemaVersion);
        cumulativeUnionLine(output, hll, explicitHLL, schemaVersion);
    }

    output.flush();
    output.close();
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:35,代码来源:IntegrationTestGenerator.java


示例8: sparseProbabilisticOverlapTest

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Unions an EMPTY accumulator with SPARSE HLLs, each
 * having a single register set, twice in a row to verify that the set
 * properties are satisfied.
 *
 * Format: cumulative union
 * Tests:
 * - EMPTY U SPARSE
 * - SPARSE U SPARSE
 */
private static void sparseProbabilisticOverlapTest(final ISchemaVersion schemaVersion) throws IOException {
    final FileWriter output = openOutput(schemaVersion, "sparse_sparse", TestType.UNION);

    final Random random = new Random(SEED);

    // the accumulator, starts empty
    final HLL hll = newHLL(HLLType.EMPTY);
    final HLL emptyHLL = newHLL(HLLType.EMPTY);

    cumulativeUnionLine(output, hll, emptyHLL, schemaVersion);

    for(int i=0; i<SPARSE_THRESHOLD; i++) {
        // make a SPARSE set and populate with cardinality 1
        final HLL sparseHLL = newHLL(HLLType.SPARSE);
        final int registerIndex = Math.abs(random.nextInt()) % REGISTER_COUNT;
        final int registerValue = ((Math.abs(random.nextInt()) % REGISTER_MAX_VALUE) + 1);
        final long rawValue = constructHLLValue(LOG2M, registerIndex, registerValue);
        sparseHLL.addRaw(rawValue);

        cumulativeUnionLine(output, hll, sparseHLL, schemaVersion);
    }

    output.flush();
    output.close();
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:36,代码来源:IntegrationTestGenerator.java


示例9: probabilisticUnionTest

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Unions an EMPTY accumulator with FULL HLLs, each having
 * many registers set, twice in a row to verify that the set properties are
 * satisfied.
 *
 * Format: cumulative union
 * Tests:
 * - EMPTY U FULL
 * - FULL U FULL
 */
private static void probabilisticUnionTest(final ISchemaVersion schemaVersion) throws IOException {
    final FileWriter output = openOutput(schemaVersion, "probabilistic_probabilistic", TestType.UNION);

    final Random random = new Random(SEED);

    // the accumulator, starts empty
    final HLL hll = newHLL(HLLType.EMPTY);
    final HLL emptyHLL = newHLL(HLLType.EMPTY);
    cumulativeUnionLine(output, hll, emptyHLL, schemaVersion);

    for(int i=0; i<1000/*number of rows to generate*/; i++) {
        // make a FULL set and populate with
        final HLL fullHLL = newHLL(HLLType.FULL);
        final int elementCount = random.nextInt(10000/*arbitrary maximum cardinality*/);
        for(int j=0;j<elementCount;j++) {
            fullHLL.addRaw(random.nextLong());
        }

        cumulativeUnionLine(output, hll, fullHLL, schemaVersion);
    }

    output.flush();
    output.close();
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:35,代码来源:IntegrationTestGenerator.java


示例10: globalUnionTest

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Unions an EMPTY accumulator with random HLLs.
 *
 * Format: cumulative union
 * Tests:
 * - hopefully all union possibilities
 */
private static void globalUnionTest(final ISchemaVersion schemaVersion) throws IOException {
    final FileWriter output = openOutput(schemaVersion, "comprehensive", TestType.UNION);

    final Random random = new Random(SEED);

    // the accumulator, starts empty
    final HLL hll = newHLL(HLLType.EMPTY);
    final HLL emptyHLL = newHLL(HLLType.EMPTY);

    cumulativeUnionLine(output, hll, emptyHLL, schemaVersion);

    for(int i=0; i<1000/*number of rows to generate*/; i++) {
        final HLL randomHLL = generateRandomHLL(random);
        cumulativeUnionLine(output, hll, randomHLL, schemaVersion);
    }

    output.flush();
    output.close();
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:27,代码来源:IntegrationTestGenerator.java


示例11: iterate

import net.agkn.hll.HLL; //导入依赖的package包/类
@Override
public void iterate(AggregationBuffer agg, Object[] parameters)
    throws HiveException {
  HLLBuffer hllbuf = (HLLBuffer) agg;
  switch(hll_mode){
  case HASHING:
    try {
      // TODO Need to test the performance between this and typed primitives
      for (int i=0; i<parameters.length; i++) {
        Writable writable = (Writable)primitiveOIs.get(i).getPrimitiveWritableObject(parameters[i]);
        if (writable!=null)
          writable.write(dos);
      }
      dos.flush();
      hllbuf.hll.addRaw(hashFunc.hashBytes(baos.toByteArray()).asLong());
      baos.reset();
    } catch (IOException e) {
      throw new HiveException(e);
    }
    break;
  case MERGING:
    LazyBinary lb = (LazyBinary) hllOI.getStructFieldData(
        parameters[0], 
        hllOI.getStructFieldRef(SIGNATURE));
    HLL other = HLL.fromBytes(lb.getWritableObject().copyBytes());
    hllbuf.hll.union(other);
  }
}
 
开发者ID:dryman,项目名称:hive-probabilistic-utils,代码行数:29,代码来源:HyperLogLog.java


示例12: merge

import net.agkn.hll.HLL; //导入依赖的package包/类
@Override
public void merge(AggregationBuffer agg, Object partial)
    throws HiveException {
  HLLBuffer hllbuf = (HLLBuffer)agg;
  if (partial!=null){
    BytesWritable bw = intermediateOI.getPrimitiveWritableObject(partial);
    HLL other = HLL.fromBytes(bw.copyBytes());
    hllbuf.hll.union(other);
  }
  
}
 
开发者ID:dryman,项目名称:hive-probabilistic-utils,代码行数:12,代码来源:HyperLogLog.java


示例13: sparseProbabilisticPromotionTest

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Unions an EMPTY accumulator with SPARSE HLLs, each
 * having one register set.
 *
 * Format: cumulative union
 * Tests:
 * - EMPTY U SPARSE
 * - SPARSE U SPARSE
 * - SPARSE promotion
 * - SPARSE U FULL
 */
private static void sparseProbabilisticPromotionTest(final ISchemaVersion schemaVersion) throws IOException {
    final FileWriter output = openOutput(schemaVersion, "sparse_promotion", TestType.UNION);

    final Random random = new Random(SEED);

    // the accumulator, starts empty
    final HLL hll = newHLL(HLLType.EMPTY);
    final HLL emptyHLL = newHLL(HLLType.EMPTY);
    cumulativeUnionLine(output, hll, emptyHLL, schemaVersion);


    for(int i=0; i<(SPARSE_THRESHOLD + 1000)/*should be greater than promotion cutoff*/; i++) {
        // make a SPARSE set and populate with cardinality 1
        final HLL sparseHLL = newHLL(HLLType.SPARSE);

        final int registerIndex = Math.abs(random.nextInt()) % REGISTER_COUNT;
        final int registerValue = ((Math.abs(random.nextInt()) % REGISTER_MAX_VALUE) + 1);
        final long rawValue = constructHLLValue(LOG2M, registerIndex, registerValue);
        sparseHLL.addRaw(rawValue);

        cumulativeUnionLine(output, hll, sparseHLL, schemaVersion);
    }

    output.flush();
    output.close();
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:38,代码来源:IntegrationTestGenerator.java


示例14: stringCardinality

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Returns the algorithm-specific cardinality of the specified {@link HLL}
 * as a {@link String} appropriate for comparison with the algorithm-specific
 * cardinality provided by the PostgreSQL implementation.
 *
 * @param  hll the HLL whose algorithm-specific cardinality is to be printed.
 *         This cannot be <code>null</code>.
 * @return the algorithm-specific cardinality of the instance as a PostgreSQL-
 *         compatible String. This will never be <code>null</code>
 */
private static String stringCardinality(final HLL hll) {
    switch(hll.getType()) {
        case EMPTY:
            return "0";
        case EXPLICIT:/*promotion has not yet occurred*/
            return Long.toString(hll.cardinality());
        case SPARSE:
            return Double.toString(hll.sparseProbabilisticAlgorithmCardinality());
        case FULL:
            return Double.toString(hll.fullProbabilisticAlgorithmCardinality());
        default:
            throw new RuntimeException("Unknown HLL type " + hll.getType());
    }
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:25,代码来源:IntegrationTestGenerator.java


示例15: largeEstimatorCutoffTest

import net.agkn.hll.HLL; //导入依赖的package包/类
/**
 * Tests that {@link HLLUtil#largeEstimatorCutoff(int, int)} is the same
 * as a trivial implementation.
 */
@Test
public void largeEstimatorCutoffTest() {
    for(int log2m=HLL.MINIMUM_LOG2M_PARAM; log2m<=HLL.MAXIMUM_LOG2M_PARAM; log2m++) {
        for(int regWidth=HLL.MINIMUM_REGWIDTH_PARAM; regWidth<=HLL.MINIMUM_REGWIDTH_PARAM; regWidth++) {
            final double cutoff = HLLUtil.largeEstimatorCutoff(log2m, regWidth);

            // See blog post (http://research.neustar.biz/2013/01/24/hyperloglog-googles-take-on-engineering-hll/)
            // and original paper (Fig. 3) for information on 2^L and
            // "large range correction" cutoff.
            final double expected = Math.pow(2, Math.pow(2, regWidth) - 2 + log2m) / 30.0;
            assertEquals(cutoff, expected);
        }
    }
}
 
开发者ID:aggregateknowledge,项目名称:java-hll,代码行数:19,代码来源:HLLUtilTest.java


示例16: main

import net.agkn.hll.HLL; //导入依赖的package包/类
public static void main(String... args) {

HashFunction hasher = Hashing.murmur3_128();

final Integer[] data = new Integer[]{1, 1, 2, 2, 3, 3, 4, 4, 5, 5};

final HLL hll = new HLL(13/*log2m*/, 5/*registerWidth*/);

for (int item : data) {
  final long hashedValue = hasher.newHasher().putInt(item).hash().asLong();
  hll.addRaw(hashedValue);
}

System.out.println("Distinct count = " + hll.cardinality());

}
 
开发者ID:Hanmourang,项目名称:hiped2,代码行数:17,代码来源:Example.java


示例17: HLLBuffer

import net.agkn.hll.HLL; //导入依赖的package包/类
public HLLBuffer(){
  hll = new HLL(14/*log2m*/, 5/*registerWidth*/);
}
 
开发者ID:dryman,项目名称:hive-probabilistic-utils,代码行数:4,代码来源:HyperLogLog.java


示例18: HLLWrapper

import net.agkn.hll.HLL; //导入依赖的package包/类
public HLLWrapper() {
    hll = new HLL(13/*log2m*/, 5/*registerWidth*/);
}
 
开发者ID:buremba,项目名称:hazelcast-modules,代码行数:4,代码来源:HLLWrapper.java


示例19: set

import net.agkn.hll.HLL; //导入依赖的package包/类
public void set(byte[] bytes) {
    hll = HLL.fromBytes(bytes);
}
 
开发者ID:buremba,项目名称:hazelcast-modules,代码行数:4,代码来源:HLLWrapper.java


示例20: reset

import net.agkn.hll.HLL; //导入依赖的package包/类
public void reset() {
    hll = new HLL(13/*log2m*/, 5/*registerWidth*/);
}
 
开发者ID:buremba,项目名称:hazelcast-modules,代码行数:4,代码来源:HLLWrapper.java



注:本文中的net.agkn.hll.HLL类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TransactionOutPoint类代码示例发布时间:2022-05-22
下一篇:
Java MutableTrigger类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap