本文整理汇总了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;
}
示例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());
}
示例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();
}
示例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};
}
示例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;
}
示例6: getTestValue
import com.clearspring.analytics.stream.cardinality.HyperLogLogPlus; //导入方法依赖的package包/类
@Override
protected Long getTestValue(final HyperLogLogPlus object) {
return object.cardinality();
}