Search in sources :

Example 11 with ArrayOfStringsSerDe

use of org.apache.datasketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.

the class ItemsSketchTest method checkPutMemory.

@Test
public void checkPutMemory() {
    final ItemsSketch<String> sketch = ItemsSketch.getInstance(16, Comparator.naturalOrder());
    for (int i = 0; i < 40; i++) {
        sketch.update(Integer.toString(i));
    }
    final byte[] byteArr = new byte[200];
    final WritableMemory mem = WritableMemory.writableWrap(byteArr);
    sketch.putMemory(mem, new ArrayOfStringsSerDe());
}
Also used : ArrayOfStringsSerDe(org.apache.datasketches.ArrayOfStringsSerDe) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 12 with ArrayOfStringsSerDe

use of org.apache.datasketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.

the class ItemsSketchTest method checkToFromByteArray2.

private static void checkToFromByteArray2(final int k, final int n) {
    final ItemsSketch<String> is = buildStringIS(k, n);
    byte[] byteArr;
    Memory mem;
    ItemsSketch<String> is2;
    final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe();
    // ordered
    byteArr = is.toByteArray(true, serDe);
    mem = Memory.wrap(byteArr);
    is2 = ItemsSketch.getInstance(mem, Comparator.naturalOrder(), serDe);
    for (double f = 0.1; f < 0.95; f += 0.1) {
        assertEquals(is.getQuantile(f), is2.getQuantile(f));
    }
    // Not-ordered
    byteArr = is.toByteArray(false, serDe);
    mem = Memory.wrap(byteArr);
    is2 = ItemsSketch.getInstance(mem, Comparator.naturalOrder(), serDe);
    for (double f = 0.1; f < 0.95; f += 0.1) {
        assertEquals(is.getQuantile(f), is2.getQuantile(f));
    }
}
Also used : ArrayOfStringsSerDe(org.apache.datasketches.ArrayOfStringsSerDe) Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory)

Example 13 with ArrayOfStringsSerDe

use of org.apache.datasketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.

the class ItemsSketchTest method checkGetInstanceExcep1.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkGetInstanceExcep1() {
    final Memory mem = Memory.wrap(new byte[4]);
    ItemsSketch.getInstance(mem, Comparator.naturalOrder(), new ArrayOfStringsSerDe());
}
Also used : ArrayOfStringsSerDe(org.apache.datasketches.ArrayOfStringsSerDe) Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 14 with ArrayOfStringsSerDe

use of org.apache.datasketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.

the class ItemsSketchTest method empty.

@Test
public void empty() {
    final ItemsSketch<String> sketch = ItemsSketch.getInstance(128, Comparator.naturalOrder());
    Assert.assertNotNull(sketch);
    Assert.assertTrue(sketch.isEmpty());
    Assert.assertEquals(sketch.getN(), 0);
    Assert.assertEquals(sketch.getRetainedItems(), 0);
    Assert.assertNull(sketch.getMinValue());
    Assert.assertNull(sketch.getMaxValue());
    Assert.assertNull(sketch.getQuantile(0.5));
    Assert.assertNull(sketch.getQuantiles(2));
    Assert.assertNull(sketch.getQuantiles(new double[] { 0.0, 1.0 }));
    final byte[] byteArr = sketch.toByteArray(new ArrayOfStringsSerDe());
    Assert.assertEquals(byteArr.length, 8);
    Assert.assertNull(sketch.getPMF(new String[0]));
    Assert.assertNull(sketch.getCDF(new String[0]));
    Assert.assertTrue(Double.isNaN(sketch.getRank("a")));
}
Also used : ArrayOfStringsSerDe(org.apache.datasketches.ArrayOfStringsSerDe) Test(org.testng.annotations.Test)

Example 15 with ArrayOfStringsSerDe

use of org.apache.datasketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.

the class ItemsUnionTest method basedOnSketch.

@Test
public void basedOnSketch() {
    final Comparator<String> comp = Comparator.naturalOrder();
    final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe();
    final ItemsSketch<String> sketch = ItemsSketch.getInstance(comp);
    ItemsUnion<String> union = ItemsUnion.getInstance(sketch);
    union.reset();
    final byte[] byteArr = sketch.toByteArray(serDe);
    final Memory mem = Memory.wrap(byteArr);
    union = ItemsUnion.getInstance(mem, comp, serDe);
    Assert.assertEquals(byteArr.length, 8);
    union.reset();
}
Also used : ArrayOfStringsSerDe(org.apache.datasketches.ArrayOfStringsSerDe) Memory(org.apache.datasketches.memory.Memory) Test(org.testng.annotations.Test)

Aggregations

ArrayOfStringsSerDe (org.apache.datasketches.ArrayOfStringsSerDe)20 Test (org.testng.annotations.Test)19 WritableMemory (org.apache.datasketches.memory.WritableMemory)15 Memory (org.apache.datasketches.memory.Memory)10 SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)1