use of org.apache.datasketches.ResizeFactor in project sketches-core by DataSketches.
the class HeapAlphaSketchTest method checkResetAndStartingSubMultiple.
@Test
public void checkResetAndStartingSubMultiple() {
int k = 1024;
int u = 4 * k;
UpdateSketch usk = UpdateSketch.builder().setFamily(fam_).setResizeFactor(X8).setNominalEntries(k).build();
// for internal checks
HeapAlphaSketch sk1 = (HeapAlphaSketch) usk;
assertTrue(usk.isEmpty());
for (int i = 0; i < u; i++) {
usk.update(i);
}
assertEquals(1 << sk1.getLgArrLongs(), 2 * k);
sk1.reset();
ResizeFactor rf = sk1.getResizeFactor();
int subMul = Util.startingSubMultiple(11, rf.lg(), 5);
assertEquals(sk1.getLgArrLongs(), subMul);
UpdateSketch usk2 = UpdateSketch.builder().setFamily(fam_).setResizeFactor(ResizeFactor.X1).setNominalEntries(k).build();
sk1 = (HeapAlphaSketch) usk2;
for (int i = 0; i < u; i++) {
usk2.update(i);
}
assertEquals(1 << sk1.getLgArrLongs(), 2 * k);
sk1.reset();
rf = sk1.getResizeFactor();
subMul = Util.startingSubMultiple(11, rf.lg(), 5);
assertEquals(sk1.getLgArrLongs(), subMul);
assertNull(sk1.getMemory());
assertFalse(sk1.isOrdered());
}
use of org.apache.datasketches.ResizeFactor in project sketches-core by DataSketches.
the class HeapQuickSelectSketchTest method checkResetAndStartingSubMultiple.
@Test
public void checkResetAndStartingSubMultiple() {
int k = 1024;
int u = 4 * k;
UpdateSketch usk = UpdateSketch.builder().setFamily(fam_).setResizeFactor(X8).setNominalEntries(k).build();
// for internal checks
HeapQuickSelectSketch sk1 = (HeapQuickSelectSketch) usk;
assertTrue(usk.isEmpty());
for (int i = 0; i < u; i++) {
usk.update(i);
}
assertEquals(1 << sk1.getLgArrLongs(), 2 * k);
sk1.reset();
ResizeFactor rf = sk1.getResizeFactor();
// messy
int subMul = Util.startingSubMultiple(11, rf.lg(), 5);
assertEquals(sk1.getLgArrLongs(), subMul);
UpdateSketch usk2 = UpdateSketch.builder().setFamily(fam_).setResizeFactor(ResizeFactor.X1).setNominalEntries(k).build();
sk1 = (HeapQuickSelectSketch) usk2;
for (int i = 0; i < u; i++) {
usk2.update(i);
}
assertEquals(1 << sk1.getLgArrLongs(), 2 * k);
sk1.reset();
rf = sk1.getResizeFactor();
// messy
subMul = Util.startingSubMultiple(11, rf.lg(), 5);
assertEquals(sk1.getLgArrLongs(), subMul);
assertNull(sk1.getMemory());
assertFalse(sk1.isOrdered());
}
use of org.apache.datasketches.ResizeFactor in project sketches-core by DataSketches.
the class ReservoirLongsSketchTest method checkBadConstructorArgs.
@Test
public void checkBadConstructorArgs() {
final long[] data = new long[128];
for (int i = 0; i < 128; ++i) {
data[i] = i;
}
final ResizeFactor rf = ResizeFactor.X8;
// no items
try {
ReservoirLongsSketch.getInstance(null, 128, rf, 128);
fail();
} catch (final SketchesException e) {
assertTrue(e.getMessage().contains("null reservoir"));
}
// size too small
try {
ReservoirLongsSketch.getInstance(data, 128, rf, 1);
fail();
} catch (final SketchesException e) {
assertTrue(e.getMessage().contains("size less than 2"));
}
// configured reservoir size smaller than items length
try {
ReservoirLongsSketch.getInstance(data, 128, rf, 64);
fail();
} catch (final SketchesException e) {
assertTrue(e.getMessage().contains("max size less than array length"));
}
// too many items seen vs items length, full sketch
try {
ReservoirLongsSketch.getInstance(data, 512, rf, 256);
fail();
} catch (final SketchesException e) {
assertTrue(e.getMessage().contains("too few samples"));
}
// too many items seen vs items length, under-full sketch
try {
ReservoirLongsSketch.getInstance(data, 256, rf, 256);
fail();
} catch (final SketchesException e) {
assertTrue(e.getMessage().contains("too few samples"));
}
}
use of org.apache.datasketches.ResizeFactor in project sketches-core by DataSketches.
the class DirectQuickSelectSketchTest method checkCorruptRFWithInsufficientArray.
@Test
public void checkCorruptRFWithInsufficientArray() {
// lgNomLongs = 10
int k = 1024;
int bytes = Sketches.getMaxUpdateSketchBytes(k);
byte[] arr = new byte[bytes];
WritableMemory mem = WritableMemory.writableWrap(arr);
// 3
ResizeFactor rf = ResizeFactor.X8;
UpdateSketch usk = UpdateSketch.builder().setNominalEntries(k).setResizeFactor(rf).build(mem);
usk.update(0);
// corrupt RF: X1
insertLgResizeFactor(mem, 0);
UpdateSketch dqss = DirectQuickSelectSketch.writableWrap(mem, DEFAULT_UPDATE_SEED);
// force-promote to X2
assertEquals(dqss.getResizeFactor(), ResizeFactor.X2);
}
use of org.apache.datasketches.ResizeFactor in project sketches-core by DataSketches.
the class ReservoirItemsSketchTest method checkBadConstructorArgs.
@Test
public void checkBadConstructorArgs() {
final ArrayList<String> data = new ArrayList<>(128);
for (int i = 0; i < 128; ++i) {
data.add(Integer.toString(i));
}
final ResizeFactor rf = ResizeFactor.X8;
// no items
try {
ReservoirItemsSketch.<Byte>newInstance(null, 128, rf, 128);
fail();
} catch (final SketchesException e) {
assertTrue(e.getMessage().contains("null reservoir"));
}
// size too small
try {
ReservoirItemsSketch.newInstance(data, 128, rf, 1);
fail();
} catch (final SketchesException e) {
assertTrue(e.getMessage().contains("size less than 2"));
}
// configured reservoir size smaller than items length
try {
ReservoirItemsSketch.newInstance(data, 128, rf, 64);
fail();
} catch (final SketchesException e) {
assertTrue(e.getMessage().contains("max size less than array length"));
}
// too many items seen vs items length, full sketch
try {
ReservoirItemsSketch.newInstance(data, 512, rf, 256);
fail();
} catch (final SketchesException e) {
assertTrue(e.getMessage().contains("too few samples"));
}
// too many items seen vs items length, under-full sketch
try {
ReservoirItemsSketch.newInstance(data, 256, rf, 256);
fail();
} catch (final SketchesException e) {
assertTrue(e.getMessage().contains("too few samples"));
}
}
Aggregations