本文整理汇总了Java中com.clearspring.analytics.stream.cardinality.HyperLogLog.offer方法的典型用法代码示例。如果您正苦于以下问题:Java HyperLogLog.offer方法的具体用法?Java HyperLogLog.offer怎么用?Java HyperLogLog.offer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.clearspring.analytics.stream.cardinality.HyperLogLog
的用法示例。
在下文中一共展示了HyperLogLog.offer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hllSerializationTest
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
@Test
public void hllSerializationTest() {
HyperLogLog hll = new HyperLogLog(16);
for (int i = 0; i < 10; i++) {
hll.offer(i);
}
try {
//this would check if we can return the data as string
//and still be usable after we build HLL
//both should use the same bytes and same hash function to merge cardinality
String hllAsStr = Base64.encodeBase64String(hll.getBytes());
HyperLogLog hll2 = HyperLogLog.Builder.build(Base64.decodeBase64(hllAsStr));
assertEquals(hll.cardinality(), hll2.cardinality());
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: testHllFieldSerializedSize
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
@Test
public void testHllFieldSerializedSize()
throws Exception {
for (int i = 5; i < 10; i++) {
HyperLogLog hll = new HyperLogLog(i);
Assert.assertEquals(HllSizeUtils.getHllFieldSizeFromLog2m(i), hll.getBytes().length);
LOGGER.info("Estimated: " + hll.cardinality());
for (int j = 0; j < 100; j++) {
hll.offer(rand.nextLong());
}
Assert.assertEquals(HllSizeUtils.getHllFieldSizeFromLog2m(i), hll.getBytes().length);
LOGGER.info("Estimated: " + hll.cardinality());
for (int j = 0; j < 9900; j++) {
hll.offer(rand.nextLong());
}
Assert.assertEquals(HllSizeUtils.getHllFieldSizeFromLog2m(i), hll.getBytes().length);
LOGGER.info("Estimated: " + hll.cardinality());
}
}
示例3: main
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, CardinalityMergeException {
HyperLogLog hll = new HyperLogLog(12);
for (int i = 0; i < 25; i++) {
hll.offer(i);
}
System.out.println(hll.cardinality());
byte[] bytes =hll.getBytes();
HyperLogLog hll2 = new HyperLogLog(12);
HyperLogLog other = HyperLogLog.Builder.build(bytes);
hll2.addAll(other);
System.out.println(hll2.cardinality());
}
示例4: getHLLResultValues
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
private static List<Serializable> getHLLResultValues(int numberOfElements) {
List<Serializable> hllResultList = new ArrayList<Serializable>();
for (int i = 0; i < numberOfElements; ++i) {
HyperLogLog hllResult = new HyperLogLog(DistinctCountHLLAggregationFunction.DEFAULT_BIT_SIZE);
hllResult.offer(i);
hllResultList.add(hllResult);
}
return hllResultList;
}
示例5: init
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
@Override
public HyperLogLog init(TridentTuple tuple) {
HyperLogLog hll = zero();
//directly offer the object, internally the instance is checked
// and the hash is computed based on type
hll.offer(tuple.getValueByField(fieldName));
return hll;
}
示例6: testMerge
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
@Test
public void testMerge() {
HyperLogLog hll = new HyperLogLog(16);
for (int i = 0; i < 10; i++) {
hll.offer(i);
}
HyperLogLog hll2 = new HyperLogLog(16);
for (int i = 1000; i < (1000 + 10); i++) {
hll2.offer(i);
}
HyperLogLog hll3 = new HyperLogLog(16);
assertEquals(hll.cardinality(), 10);
assertEquals(hll2.cardinality(), 10);
assertEquals(hll3.cardinality(), 0);
try {
ICardinality hllMerged = hll.merge(hll2);
hllMerged = hllMerged.merge(hll3);
// System.out.println(hllMerged.cardinality());
assertEquals(hllMerged.cardinality(), 20);
} catch (CardinalityMergeException e) {
e.printStackTrace();
}
}
示例7: add
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
@Override
public void add(final HyperLogLog log, final Request request) {
log.offer(request.getValue().get());
}
示例8: offerNumberInRangeTo
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
public void offerNumberInRangeTo(HyperLogLog hyperLogLog, int start, int end) {
end = Math.min(end, arr.length);
for (int i = start; i < end; i++) {
hyperLogLog.offer(arr[i]);
}
}
示例9: singleValueHllAsString
import com.clearspring.analytics.stream.cardinality.HyperLogLog; //导入方法依赖的package包/类
/**
* 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);
}