@Test public void aNotBEmpty() { AnotB<DoubleSummary> aNotB = new AnotB<>(); // calling getResult() before calling update() should yield an empty set CompactSketch<DoubleSummary> result = aNotB.getResult(); Assert.assertEquals(result.getRetainedEntries(), 0); Assert.assertTrue(result.isEmpty()); Assert.assertEquals(result.getEstimate(), 0.0); Assert.assertEquals(result.getLowerBound(1), 0.0); Assert.assertEquals(result.getUpperBound(1), 0.0); aNotB.update(null, null); result = aNotB.getResult(); Assert.assertEquals(result.getRetainedEntries(), 0); Assert.assertTrue(result.isEmpty()); Assert.assertEquals(result.getEstimate(), 0.0); Assert.assertEquals(result.getLowerBound(1), 0.0); Assert.assertEquals(result.getUpperBound(1), 0.0); UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build(); aNotB.update(sketch, sketch); result = aNotB.getResult(); Assert.assertEquals(result.getRetainedEntries(), 0); Assert.assertTrue(result.isEmpty()); Assert.assertEquals(result.getEstimate(), 0.0); Assert.assertEquals(result.getLowerBound(1), 0.0); Assert.assertEquals(result.getUpperBound(1), 0.0); }
if (a == null || a.getRetainedEntries() == 0) { return; } if (b == null || b.getRetainedEntries() == 0) { getNoMatchSetFromSketch(a); } else { final long[] hashTable; if (b instanceof CompactSketch) { hashTable = convertToHashTable(b); } else { hashTable = b.keys_;
/** * Gets the result of this operation * @return the result of this operation as a CompactSketch */ public CompactSketch<S> getResult() { if (count_ == 0) { return new CompactSketch<S>(null, null, theta_, isEmpty_); } final CompactSketch<S> result = new CompactSketch<S>(Arrays.copyOfRange(keys_, 0, count_), Arrays.copyOfRange(summaries_, 0, count_), theta_, isEmpty_); reset(); return result; }
@Test public void aNotBEmptyA() { UpdatableSketch<Double, DoubleSummary> sketchA = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build(); UpdatableSketch<Double, DoubleSummary> sketchB = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build(); sketchB.update(1, 1.0); sketchB.update(2, 1.0); AnotB<DoubleSummary> aNotB = new AnotB<>(); aNotB.update(sketchA, sketchB); CompactSketch<DoubleSummary> result = aNotB.getResult(); Assert.assertEquals(result.getRetainedEntries(), 0); Assert.assertTrue(result.isEmpty()); Assert.assertEquals(result.getEstimate(), 0.0); Assert.assertEquals(result.getLowerBound(1), 0.0); Assert.assertEquals(result.getUpperBound(1), 0.0); }
if (a == null || a.getRetainedEntries() == 0) { return; } if (b == null || b.getRetainedEntries() == 0) { getNoMatchSetFromSketch(a); } else { final long[] hashTable; if (b instanceof CompactSketch) { hashTable = convertToHashTable(b); } else { hashTable = b.keys_;
/** * Gets the result of this operation * @return the result of this operation as a CompactSketch */ public CompactSketch<S> getResult() { if (count_ == 0) { return new CompactSketch<S>(null, null, theta_, isEmpty_); } final CompactSketch<S> result = new CompactSketch<S>(Arrays.copyOfRange(keys_, 0, count_), Arrays.copyOfRange(summaries_, 0, count_), theta_, isEmpty_); reset(); return result; }
@Test public void aNotBEmptyB() { UpdatableSketch<Double, DoubleSummary> sketchA = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build(); sketchA.update(1, 1.0); sketchA.update(2, 1.0); UpdatableSketch<Double, DoubleSummary> sketchB = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build(); AnotB<DoubleSummary> aNotB = new AnotB<>(); aNotB.update(sketchA, sketchB); CompactSketch<DoubleSummary> result = aNotB.getResult(); Assert.assertEquals(result.getRetainedEntries(), 2); Assert.assertFalse(result.isEmpty()); Assert.assertEquals(result.getEstimate(), 2.0); Assert.assertEquals(result.getLowerBound(1), 2.0); Assert.assertEquals(result.getUpperBound(1), 2.0); // same thing, but compact sketches aNotB.update(sketchA.compact(), sketchB.compact()); result = aNotB.getResult(); Assert.assertEquals(result.getRetainedEntries(), 2); Assert.assertFalse(result.isEmpty()); Assert.assertEquals(result.getEstimate(), 2.0); Assert.assertEquals(result.getLowerBound(1), 2.0); Assert.assertEquals(result.getUpperBound(1), 2.0); }
@Test public void aNotBExactMode() { UpdatableSketch<Double, DoubleSummary> sketchA = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build(); sketchA.update(1, 1.0); sketchA.update(1, 1.0); sketchA.update(2, 1.0); sketchA.update(2, 1.0); UpdatableSketch<Double, DoubleSummary> sketchB = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build(); sketchB.update(2, 1.0); sketchB.update(2, 1.0); sketchB.update(3, 1.0); sketchB.update(3, 1.0); AnotB<DoubleSummary> aNotB = new AnotB<>(); aNotB.update(sketchA, sketchB); CompactSketch<DoubleSummary> result = aNotB.getResult(); Assert.assertEquals(result.getRetainedEntries(), 1); Assert.assertFalse(result.isEmpty()); Assert.assertEquals(result.getEstimate(), 1.0); Assert.assertEquals(result.getLowerBound(1), 1.0); Assert.assertEquals(result.getUpperBound(1), 1.0); SketchIterator<DoubleSummary> it = result.iterator(); Assert.assertTrue(it.next()); Assert.assertEquals(it.getSummary().getValue(), 2.0); Assert.assertFalse(it.next()); }