@Test public void checkToByteArray() { UpdateDoublesSketch ds = DoublesSketch.builder().build(); //k = 128 ds.update(1); ds.update(2); byte[] arr = ds.toByteArray(false); assertEquals(arr.length, ds.getUpdatableStorageBytes()); }
@Test public void checkGetStorageBytes2() { int k = PreambleUtil.DEFAULT_K; long v = 1; UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build(); for (int i = 0; i< 1000; i++) { qs.update(v++); // for (int j = 0; j < 1000; j++) { // qs.update(v++); // } byte[] byteArr = qs.toByteArray(false); assertEquals(byteArr.length, qs.getUpdatableStorageBytes()); } }
@Test public void checkPutMemory() { UpdateDoublesSketch qs1 = DoublesSketch.builder().build(); //k = 128 for (int i=0; i<1000; i++) { qs1.update(i); } int bytes = qs1.getUpdatableStorageBytes(); WritableMemory dstMem = WritableMemory.wrap(new byte[bytes]); qs1.putMemory(dstMem, false); Memory srcMem = dstMem; DoublesSketch qs2 = DoublesSketch.heapify(srcMem); assertEquals(qs1.getMinValue(), qs2.getMinValue(), 0.0); assertEquals(qs1.getMaxValue(), qs2.getMaxValue(), 0.0); }
@Test public void checkDeprecated1() { UpdateDoublesSketch qs1 = DoublesSketch.builder().build(); for (int i=0; i<1000; i++) { qs1.update(i); } int bytes = qs1.getCompactStorageBytes(); WritableMemory dstMem = WritableMemory.wrap(new byte[bytes]); qs1.putMemory(dstMem); Memory srcMem = dstMem; DoublesUnionBuilder bldr = new DoublesUnionBuilder(); bldr.setMaxK(128); DoublesUnion union = bldr.build(); //virgin union union = DoublesUnion.heapify(srcMem); //heapify DoublesSketch qs2 = union.getResult(); assertEquals(qs1.getCompactStorageBytes(), qs2.getCompactStorageBytes()); assertEquals(qs1.getUpdatableStorageBytes(), qs2.getUpdatableStorageBytes()); union = DoublesUnion.heapify(qs2); //heapify again DoublesSketch qs3 = union.getResult(); assertEquals(qs2.getCompactStorageBytes(), qs3.getCompactStorageBytes()); assertEquals(qs2.getUpdatableStorageBytes(), qs3.getUpdatableStorageBytes()); assertFalse(qs2 == qs3); //different objects }