Codota Logo
UpdatableSketch.update
Code IndexAdd Codota to your IDE (free)

How to use
update
method
in
com.yahoo.sketches.tuple.UpdatableSketch

Best Java code snippets using com.yahoo.sketches.tuple.UpdatableSketch.update (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew LinkedList()
  • Codota IconCollections.emptyList()
  • Codota Iconnew ArrayList()
  • Smart code suggestions by Codota
}
origin: DataSketches/sketches-core

/**
 * Updates this sketch with a long key and U value.
 * The value is passed to update() method of the Summary object associated with the key
 *
 * @param key The given long key
 * @param value The given U value
 */
public void update(final long key, final U value) {
update(new long[] {key}, value);
}
origin: DataSketches/sketches-core

/**
 * Updates this sketch with a double key and U value.
 * The value is passed to update() method of the Summary object associated with the key
 *
 * @param key The given double key
 * @param value The given U value
 */
public void update(final double key, final U value) {
 update(Util.doubleToLongArray(key), value);
}
origin: DataSketches/sketches-core

/**
 * Updates this sketch with a String key and U value.
 * The value is passed to update() method of the Summary object associated with the key
 *
 * @param key The given String key
 * @param value The given U value
 */
public void update(final String key, final U value) {
 update(Util.stringToByteArray(key), value);
}
origin: DataSketches/sketches-core

  private static void fillSketch(UpdatableSketch<Double, DoubleSummary> sketch,
    int numberOfElements, Double sketchValue) {


   for (int cont = 0; cont < numberOfElements; cont++) {
     sketch.update(random.nextLong(), sketchValue);
   }
  }
}
origin: DataSketches/sketches-core

@Test
public void updatesOfAllKeyTypes() {
 UpdatableSketch<Double, DoubleSummary> sketch =
   new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
 sketch.update(1L, 1.0);
 sketch.update(2.0, 1.0);
 byte[] bytes = { 3 };
 sketch.update(bytes, 1.0);
 int[] ints = { 4 };
 sketch.update(ints, 1.0);
 long[] longs = { 5L };
 sketch.update(longs, 1.0);
 sketch.update("a", 1.0);
 Assert.assertEquals(sketch.getEstimate(), 6.0);
}
origin: DataSketches/sketches-core

@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());
}
origin: DataSketches/sketches-core

@Test
public void sampling() {
 float samplingProbability = 0.001f;
 UpdatableSketch<Double, DoubleSummary> sketch =
   new UpdatableSketchBuilder<>(
     new DoubleSummaryFactory()).setSamplingProbability(samplingProbability).build();
 sketch.update("a", 1.0);
 Assert.assertFalse(sketch.isEmpty());
 Assert.assertTrue(sketch.isEstimationMode());
 Assert.assertEquals(sketch.getEstimate(), 0.0);
 Assert.assertTrue(sketch.getUpperBound(1) > 0.0);
 Assert.assertEquals(sketch.getLowerBound(1), 0.0, 0.0000001);
 Assert.assertEquals(sketch.getThetaLong() / (double) Long.MAX_VALUE,
   (double) samplingProbability);
 Assert.assertEquals(sketch.getTheta(), (double) samplingProbability);
}
origin: DataSketches/sketches-core

@Test
public void intersectionExactWithEmpty() {
 UpdatableSketch<Double, DoubleSummary> sketch1 =
   new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
 sketch1.update(1, 1.0);
 sketch1.update(2, 1.0);
 sketch1.update(3, 1.0);
 Sketch<DoubleSummary> sketch2 = Sketches.createEmptySketch();
 Intersection<DoubleSummary> intersection =
   new Intersection<>(new DoubleSummarySetOperations(Mode.Sum));
 intersection.update(sketch1);
 intersection.update(sketch2);
 CompactSketch<DoubleSummary> result = intersection.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);
}
origin: DataSketches/sketches-core

@Test
public void intersectionExactWithNull() {
 UpdatableSketch<Double, DoubleSummary> sketch1 =
   new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
 sketch1.update(1, 1.0);
 sketch1.update(2, 1.0);
 sketch1.update(3, 1.0);
 Intersection<DoubleSummary> intersection =
   new Intersection<>(new DoubleSummarySetOperations());
 intersection.update(sketch1);
 intersection.update(null);
 CompactSketch<DoubleSummary> result = intersection.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);
}
origin: DataSketches/sketches-core

@Test
public void serializeDeserializeExact() throws Exception {
 UpdatableSketch<Double, DoubleSummary> sketch1 =
   new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
 sketch1.update(1, 1.0);
 UpdatableSketch<Double, DoubleSummary> sketch2 = Sketches.heapifyUpdatableSketch(
   Memory.wrap(sketch1.toByteArray()),
   new DoubleSummaryDeserializer(), new DoubleSummaryFactory());
 Assert.assertEquals(sketch2.getEstimate(), 1.0);
 SketchIterator<DoubleSummary> it = sketch2.iterator();
 Assert.assertTrue(it.next());
 Assert.assertEquals(it.getSummary().getValue(), 1.0);
 Assert.assertFalse(it.next());
 // the same key, so still one unique
 sketch2.update(1, 1.0);
 Assert.assertEquals(sketch2.getEstimate(), 1.0);
 sketch2.update(2, 1.0);
 Assert.assertEquals(sketch2.getEstimate(), 2.0);
}
origin: DataSketches/sketches-core

@Test
public void serializeDeserializeSmallExact() {
 UpdatableSketch<Double, DoubleSummary> us = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
 us.update("a", 1.0);
 us.update("b", 1.0);
 us.update("c", 1.0);
 CompactSketch<DoubleSummary> sketch1 = us.compact();
 Sketch<DoubleSummary> sketch2 =
   Sketches.heapifySketch(Memory.wrap(sketch1.toByteArray()), new DoubleSummaryDeserializer());
 Assert.assertFalse(sketch2.isEmpty());
 Assert.assertFalse(sketch2.isEstimationMode());
 Assert.assertEquals(sketch2.getEstimate(), 3.0);
 Assert.assertEquals(sketch2.getLowerBound(1), 3.0);
 Assert.assertEquals(sketch2.getUpperBound(1), 3.0);
 Assert.assertEquals(sketch2.getRetainedEntries(), 3);
 Assert.assertEquals(sketch2.getThetaLong(), Long.MAX_VALUE);
 Assert.assertEquals(sketch2.getTheta(), 1.0);
 SketchIterator<DoubleSummary> it = sketch2.iterator();
 int count = 0;
 while (it.next()) {
  Assert.assertEquals(it.getSummary().getValue(), 1.0);
  count++;
 }
 Assert.assertEquals(count, 3);
}
origin: DataSketches/sketches-core

@Test
public void estimationModeWithSamplingNoResizing() {
 UpdatableSketch<Double, DoubleSummary> sketch =
   new UpdatableSketchBuilder<>(
     new DoubleSummaryFactory())
      .setSamplingProbability(0.5f)
      .setResizeFactor(ResizeFactor.X1).build();
 for (int i = 0; i < 16384; i++) {
  sketch.update(i, 1.0);
 }
 Assert.assertTrue(sketch.isEstimationMode());
 Assert.assertEquals(sketch.getEstimate(), 16384, 16384 * 0.01);
 Assert.assertTrue(sketch.getEstimate() >= sketch.getLowerBound(1));
 Assert.assertTrue(sketch.getEstimate() < sketch.getUpperBound(1));
}
origin: DataSketches/sketches-core

@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);
}
origin: DataSketches/sketches-core

@Test
public void nonEmptySketchWithNoEntries() {
 UpdatableSketch<Double, DoubleSummary> sketch =
   new UpdatableSketchBuilder<>(
     new DoubleSummaryFactory()).setSamplingProbability(0.0001f).build();
 sketch.update(0, 0.0);
 Assert.assertFalse(sketch.isEmpty());
 Assert.assertEquals(sketch.getRetainedEntries(), 0);
 Filter<DoubleSummary> filter = new Filter<>(o -> true);
 Sketch<DoubleSummary> filteredSketch = filter.filter(sketch);
 Assert.assertFalse(filteredSketch.isEmpty());
 Assert.assertEquals(filteredSketch.getEstimate(), sketch.getEstimate());
 Assert.assertEquals(filteredSketch.getThetaLong(), sketch.getThetaLong());
 Assert.assertEquals(filteredSketch.getLowerBound(1), sketch.getLowerBound(1));
 Assert.assertEquals(filteredSketch.getUpperBound(1), sketch.getUpperBound(1));
}
origin: DataSketches/sketches-core

@Test
public void intersectionNotEmptyNoEntries() {
 UpdatableSketch<Double, DoubleSummary> sketch1 =
   new UpdatableSketchBuilder<>
    (new DoubleSummaryFactory()).setSamplingProbability(0.01f).build();
 sketch1.update("a", 1.0); // this happens to get rejected because of sampling with low probability
 Intersection<DoubleSummary> intersection =
   new Intersection<>(new DoubleSummarySetOperations());
 intersection.update(sketch1);
 CompactSketch<DoubleSummary> result = intersection.getResult();
 Assert.assertEquals(result.getRetainedEntries(), 0);
 Assert.assertFalse(result.isEmpty());
 Assert.assertEquals(result.getEstimate(), 0.0);
 Assert.assertEquals(result.getLowerBound(1), 0.0, 0.0001);
 Assert.assertTrue(result.getUpperBound(1) > 0);
}
origin: DataSketches/sketches-core

@Test
public void serializeDeserializeSampling() throws Exception {
 int sketchSize = 16384;
 int numberOfUniques = sketchSize;
 UpdatableSketch<Double, DoubleSummary> sketch1 =
   new UpdatableSketchBuilder<>(new DoubleSummaryFactory())
   .setNominalEntries(sketchSize).setSamplingProbability(0.5f).build();
 for (int i = 0; i < numberOfUniques; i++) {
  sketch1.update(i, 1.0);
 }
 Sketch<DoubleSummary> sketch2 = Sketches.heapifySketch(
   Memory.wrap(sketch1.toByteArray()), new DoubleSummaryDeserializer());
 Assert.assertTrue(sketch2.isEstimationMode());
 Assert.assertEquals(sketch2.getEstimate() / numberOfUniques, 1.0, 0.01);
 Assert.assertEquals(sketch2.getRetainedEntries() / (double) numberOfUniques, 0.5, 0.01);
 Assert.assertEquals(sketch1.getTheta(), sketch2.getTheta());
}
origin: DataSketches/sketches-core

@Test
public void serializeDeserializeEstimation() throws Exception {
 UpdatableSketch<Double, DoubleSummary> us = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
 for (int i = 0; i < 8192; i++) us.update(i, 1.0);
 us.trim();
 CompactSketch<DoubleSummary> sketch1 = us.compact();
 byte[] bytes = sketch1.toByteArray();
 // for visual testing
 //TestUtil.writeBytesToFile(bytes, "CompactSketchWithDoubleSummary4K.bin");
 Sketch<DoubleSummary> sketch2 =
   Sketches.heapifySketch(Memory.wrap(bytes), new DoubleSummaryDeserializer());
 Assert.assertFalse(sketch2.isEmpty());
 Assert.assertTrue(sketch2.isEstimationMode());
 Assert.assertEquals(sketch2.getEstimate(), sketch1.getEstimate());
 Assert.assertEquals(sketch2.getThetaLong(), sketch1.getThetaLong());
 SketchIterator<DoubleSummary> it = sketch2.iterator();
 int count = 0;
 while (it.next()) {
  Assert.assertEquals(it.getSummary().getValue(), 1.0);
  count++;
 }
 Assert.assertEquals(count, 4096);
}
origin: DataSketches/sketches-core

@Test(expectedExceptions = SketchesArgumentException.class)
public void deserializeWrongType() {
 UpdatableSketch<Double, DoubleSummary> us = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
 for (int i = 0; i < 8192; i++) us.update(i, 1.0);
 CompactSketch<DoubleSummary> sketch1 = us.compact();
 Sketches.heapifyUpdatableSketch(Memory.wrap(sketch1.toByteArray()), new DoubleSummaryDeserializer(),
   new DoubleSummaryFactory());
}
origin: DataSketches/sketches-core

@Test
public void unionEstimationMode() {
 int key = 0;
 UpdatableSketch<Double, DoubleSummary> sketch1 =
   new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
 for (int i = 0; i < 8192; i++) {
  sketch1.update(key++, 1.0);
 }
 key -= 4096; // overlap half of the entries
 UpdatableSketch<Double, DoubleSummary> sketch2 =
   new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
 for (int i = 0; i < 8192; i++) {
  sketch2.update(key++, 1.0);
 }
 Union<DoubleSummary> union = new Union<>(4096, new DoubleSummarySetOperations());
 union.update(sketch1);
 union.update(sketch2);
 CompactSketch<DoubleSummary> result = union.getResult();
 Assert.assertEquals(result.getEstimate(), 12288.0, 12288 * 0.01);
 Assert.assertTrue(result.getLowerBound(1) <= result.getEstimate());
 Assert.assertTrue(result.getUpperBound(1) > result.getEstimate());
}
origin: DataSketches/sketches-core

@Test
public void serializeDeserializeEstimationNoResizing() throws Exception {
 UpdatableSketch<Double, DoubleSummary> sketch1 =
   new UpdatableSketchBuilder<>(
     new DoubleSummaryFactory()).setResizeFactor(ResizeFactor.X1).build();
 for (int j = 0; j < 10; j++) {
  for (int i = 0; i < 8192; i++) {
   sketch1.update(i, 1.0);
  }
 }
 sketch1.trim();
 byte[] bytes = sketch1.toByteArray();
 //for visual testing
 //TestUtil.writeBytesToFile(bytes, "UpdatableSketchWithDoubleSummary4K.bin");
 Sketch<DoubleSummary> sketch2 =
   Sketches.heapifySketch(Memory.wrap(bytes), new DoubleSummaryDeserializer());
 Assert.assertTrue(sketch2.isEstimationMode());
 Assert.assertEquals(sketch2.getEstimate(), 8192, 8192 * 0.99);
 Assert.assertEquals(sketch1.getTheta(), sketch2.getTheta());
 SketchIterator<DoubleSummary> it = sketch2.iterator();
 int count = 0;
 while (it.next()) {
  Assert.assertEquals(it.getSummary().getValue(), 10.0);
  count++;
 }
 Assert.assertEquals(count, 4096);
}
com.yahoo.sketches.tupleUpdatableSketchupdate

Javadoc

Updates this sketch with a double key and U value. The value is passed to update() method of the Summary object associated with the key

Popular methods of UpdatableSketch

  • compact
  • getThetaLong
  • reset
  • <init>
    This is to create an instance of a sketch given a serialized form
  • findOrInsert
  • getCurrentCapacity
  • getEstimate
  • getLowerBound
  • getNominalEntries
  • getResizeFactor
  • getRetainedEntries
  • getSamplingProbability
  • getRetainedEntries,
  • getSamplingProbability,
  • getSummaryFactory,
  • getTheta,
  • getUpperBound,
  • insertOrIgnore,
  • insertSummary,
  • isEmpty,
  • isEstimationMode

Popular in Java

  • Making http post requests using okhttp
  • putExtra (Intent)
  • orElseThrow (Optional)
  • onRequestPermissionsResult (Fragment)
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • ArrayList (java.util)
    Resizable-array implementation of the List interface. Implements all optional list operations, and p
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • JButton (javax.swing)
  • JPanel (javax.swing)
  • Logger (org.slf4j)
    The main user interface to logging. It is expected that logging takes place through concrete impleme
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now