当前位置: 首页>>代码示例>>Java>>正文


Java HyperLogLogPlus.cardinality方法代码示例

本文整理汇总了Java中com.clearspring.analytics.stream.cardinality.HyperLogLogPlus.cardinality方法的典型用法代码示例。如果您正苦于以下问题:Java HyperLogLogPlus.cardinality方法的具体用法?Java HyperLogLogPlus.cardinality怎么用?Java HyperLogLogPlus.cardinality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.clearspring.analytics.stream.cardinality.HyperLogLogPlus的用法示例。


在下文中一共展示了HyperLogLogPlus.cardinality方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import com.clearspring.analytics.stream.cardinality.HyperLogLogPlus; //导入方法依赖的package包/类
@Override
public boolean test(final HyperLogLogPlus input) {
    if (null == input) {
        return false;
    }
    final long cardinality = input.cardinality();
    if (orEqualTo) {
        if (cardinality <= controlValue) {
            return true;
        }
    } else {
        if (cardinality < controlValue) {
            return true;
        }
    }
    return false;
}
 
开发者ID:gchq,项目名称:Gaffer,代码行数:18,代码来源:HyperLogLogPlusIsLessThan.java

示例2: runTestWithSketch

import com.clearspring.analytics.stream.cardinality.HyperLogLogPlus; //导入方法依赖的package包/类
private void runTestWithSketch(final HyperLogLogPlus sketch) throws IOException {
    // When - serialise
    final String json = mapper.writeValueAsString(sketch);

    // Then - serialise
    final String[] parts = json.split("[:,]");
    final String[] expectedParts = {
            "{\"hyperLogLogPlus\"",
            "{\"hyperLogLogPlusSketchBytes\"",
            "BYTES",
            "\"cardinality\"",
            sketch.cardinality() + "}}"};
    for (int i = 0; i < parts.length; i++) {
        if (2 != i) { // skip checking the bytes
            assertEquals(expectedParts[i], parts[i]);
        }
    }

    // When - deserialise
    final HyperLogLogPlus deserialisedSketch = mapper.readValue(IOUtils.toInputStream(json), HyperLogLogPlus.class);

    // Then - deserialise
    assertNotNull(deserialisedSketch);
    assertEquals(sketch.cardinality(), deserialisedSketch.cardinality());
}
 
开发者ID:gchq,项目名称:Gaffer,代码行数:26,代码来源:HyperLogLogPlusJsonSerialisationTest.java

示例3: count

import com.clearspring.analytics.stream.cardinality.HyperLogLogPlus; //导入方法依赖的package包/类
@Override
public long count() {
    final Iterator<HyperLogLogPlus> it = states.iterator();

    if (!it.hasNext()) {
        return 0L;
    }

    HyperLogLogPlus current = it.next();

    while (it.hasNext()) {
        try {
            current.addAll(it.next());
        } catch (CardinalityMergeException e) {
            throw new RuntimeException(e);
        }
    }

    return current.cardinality();
}
 
开发者ID:spotify,项目名称:heroic,代码行数:21,代码来源:ReduceHyperLogLogPlusCardinalityBucket.java

示例4: serialise

import com.clearspring.analytics.stream.cardinality.HyperLogLogPlus; //导入方法依赖的package包/类
@Override
public Object[] serialise(final HyperLogLogPlus object) throws SerialisationException {
    try {
        if (null != object) {
            return new Object[]{object.getBytes(), object.cardinality()};
        }
    } catch (final IOException e) {
        throw new SerialisationException("Failed to get bytes from the HyperLogLogPlus object.");
    }
    return new Object[]{null};
}
 
开发者ID:gchq,项目名称:Gaffer,代码行数:12,代码来源:InLineHyperLogLogPlusParquetSerialiser.java

示例5: run

import com.clearspring.analytics.stream.cardinality.HyperLogLogPlus; //导入方法依赖的package包/类
@Override
public CloseableIterable<? extends Element> run() throws OperationException {
    /// [graph] create a graph using our schema and store properties
    // ---------------------------------------------------------
    final Graph graph = new Graph.Builder()
            .config(getDefaultGraphConfig())
            .addSchemas(StreamUtil.openStreams(getClass(), schemaPath))
            .storeProperties(getDefaultStoreProperties())
            .build();
    // ---------------------------------------------------------


    // [user] Create a user
    // ---------------------------------------------------------
    final User user = new User("user01");
    // ---------------------------------------------------------


    // [add] addElements - add the edges to the graph
    // ---------------------------------------------------------
    final Set<String> dummyData = Collections.singleton("");
    final OperationChain<Void> addOpChain = new OperationChain.Builder()
            .first(new GenerateElements.Builder<String>()
                    .generator(new HyperLogLogPlusElementGenerator())
                    .input(dummyData)
                    .build())
            .then(new AddElements())
            .build();

    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    print("Added 1000 entities for vertex A, each time w\nith a HyperLogLogPlus containing a vertex that A was seen in an edge with");


    // [get] Get all entities
    // ---------------------------------------------------------
    CloseableIterable<? extends Element> allEntities = graph.execute(new GetAllElements(), user);
    // ---------------------------------------------------------
    print("\nAll edges:");
    for (final Element entity : allEntities) {
        print("GET_ALL_ENTITIES_RESULT", entity.toString());
    }


    // [get the approximate degree of a] Get the entity for A and print out the estimate of the degree
    // ---------------------------------------------------------
    final GetElements query = new GetElements.Builder()
            .input(new EntitySeed("A"))
            .build();
    final Element element;
    try (final CloseableIterable<? extends Element> elements = graph.execute(query, user)) {
        element = elements.iterator().next();
    }
    final HyperLogLogPlus hyperLogLogPlus = (HyperLogLogPlus) element.getProperty("approxCardinality");
    final double approxDegree = hyperLogLogPlus.cardinality();
    final String degreeEstimate = "Entity A has approximate degree " + approxDegree;
    // ---------------------------------------------------------
    print("\nEntity A with an estimate of its degree");
    print("GET_APPROX_DEGREE_FOR_ENTITY_A", degreeEstimate);

    return null;
}
 
开发者ID:gchq,项目名称:gaffer-doc,代码行数:63,代码来源:HyperLogLogPlusWalkthrough.java

示例6: getTestValue

import com.clearspring.analytics.stream.cardinality.HyperLogLogPlus; //导入方法依赖的package包/类
@Override
protected Long getTestValue(final HyperLogLogPlus object) {
    return object.cardinality();
}
 
开发者ID:gchq,项目名称:Gaffer,代码行数:5,代码来源:HyperLogLogPlusSerialiserTest.java


注:本文中的com.clearspring.analytics.stream.cardinality.HyperLogLogPlus.cardinality方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。