use of org.apache.datasketches.tuple.aninteger.IntegerSummary in project sketches-core by DataSketches.
the class TupleExamplesTest method example1.
@Test
public void example1() {
// Load source sketches
final UpdatableSketch<Integer, IntegerSummary> tupleSk = tupleBldr.build();
final UpdateSketch thetaSk = thetaBldr.build();
for (int i = 1; i <= 12; i++) {
tupleSk.update(i, 1);
thetaSk.update(i + 3);
}
// Union stateful: tuple, theta
final Union<IntegerSummary> union = new Union<>(isso);
union.union(tupleSk);
union.union(thetaSk, ufactory.newSummary().update(1));
final CompactSketch<IntegerSummary> ucsk = union.getResult();
int entries = ucsk.getRetainedEntries();
println("Union Stateful: tuple, theta: " + entries);
final SketchIterator<IntegerSummary> uiter = ucsk.iterator();
int counter = 1;
int twos = 0;
int ones = 0;
while (uiter.next()) {
final int i = uiter.getSummary().getValue();
// 9 entries = 2, 6 entries = 1
println(counter++ + ", " + i);
if (i == 1) {
ones++;
}
if (i == 2) {
twos++;
}
}
assertEquals(ones, 6);
assertEquals(twos, 9);
// Intersection stateful: tuple, theta
final Intersection<IntegerSummary> inter = new Intersection<>(isso);
inter.intersect(tupleSk);
inter.intersect(thetaSk, ifactory.newSummary().update(1));
final CompactSketch<IntegerSummary> icsk = inter.getResult();
entries = icsk.getRetainedEntries();
println("Intersection Stateful: tuple, theta: " + entries);
final SketchIterator<IntegerSummary> iiter = icsk.iterator();
counter = 1;
while (iiter.next()) {
final int i = iiter.getSummary().getValue();
// 9 entries = 1
println(counter++ + ", " + i);
assertEquals(i, 1);
}
}
use of org.apache.datasketches.tuple.aninteger.IntegerSummary in project sketches-core by DataSketches.
the class TupleExamplesTest method example3.
@Test
public void example3() {
// Load source sketches
final UpdatableSketch<Integer, IntegerSummary> tupleSk = tupleBldr.build();
final UpdateSketch thetaSk = thetaBldr.build();
for (int i = 1; i <= 12; i++) {
tupleSk.update(i, 1);
thetaSk.update(i + 3);
}
// Union, stateless: tuple1, tuple2
final Union<IntegerSummary> union = new Union<>(isso);
final CompactSketch<IntegerSummary> ucsk = union.union(tupleSk, thetaSk, ufactory.newSummary().update(1));
int entries = ucsk.getRetainedEntries();
println("Union: " + entries);
final SketchIterator<IntegerSummary> uiter = ucsk.iterator();
int counter = 1;
int twos = 0;
int ones = 0;
while (uiter.next()) {
final int i = uiter.getSummary().getValue();
// 9 entries = 2, 6 entries = 1
println(counter++ + ", " + i);
if (i == 1) {
ones++;
}
if (i == 2) {
twos++;
}
}
assertEquals(ones, 6);
assertEquals(twos, 9);
// Intersection stateless: tuple1, tuple2
final Intersection<IntegerSummary> inter = new Intersection<>(isso);
final CompactSketch<IntegerSummary> icsk = inter.intersect(tupleSk, thetaSk, ufactory.newSummary().update(1));
entries = icsk.getRetainedEntries();
println("Intersection: " + entries);
final SketchIterator<IntegerSummary> iiter = icsk.iterator();
counter = 1;
while (iiter.next()) {
final int i = iiter.getSummary().getValue();
// 9 entries = 2
println(counter++ + ", " + i);
assertEquals(i, 1);
}
}
Aggregations