use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class HeapUpdateDoublesSketchTest method checkMemTooSmall1.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkMemTooSmall1() {
Memory mem = Memory.wrap(new byte[7]);
HeapUpdateDoublesSketch.heapifyInstance(mem);
fail();
// qs2.getQuantile(0.5);
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class HeapUpdateDoublesSketchTest method checkZeroPatternReturn.
@Test
public void checkZeroPatternReturn() {
int k = PreambleUtil.DEFAULT_K;
DoublesSketch qs1 = buildAndLoadQS(k, 64);
byte[] byteArr = qs1.toByteArray();
Memory mem = Memory.wrap(byteArr);
HeapUpdateDoublesSketch.heapifyInstance(mem);
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class CpcWrapperTest method check.
@SuppressWarnings("unused")
@Test
public void check() {
int lgK = 10;
CpcSketch sk1 = new CpcSketch(lgK);
CpcSketch sk2 = new CpcSketch(lgK);
CpcSketch skD = new CpcSketch(lgK);
double dEst = skD.getEstimate();
double dlb = skD.getLowerBound(2);
double dub = skD.getUpperBound(2);
int n = 100000;
for (int i = 0; i < n; i++) {
sk1.update(i);
sk2.update(i + n);
skD.update(i);
skD.update(i + n);
}
byte[] concatArr = skD.toByteArray();
CpcUnion union = new CpcUnion(lgK);
CpcSketch result = union.getResult();
double uEst = result.getEstimate();
double ulb = result.getLowerBound(2);
double uub = result.getUpperBound(2);
union.update(sk1);
union.update(sk2);
CpcSketch merged = union.getResult();
byte[] mergedArr = merged.toByteArray();
Memory concatMem = Memory.wrap(concatArr);
CpcWrapper concatSk = new CpcWrapper(concatMem);
assertEquals(concatSk.getLgK(), lgK);
printf(" %12s %12s %12s\n", "Lb", "Est", "Ub");
double ccEst = concatSk.getEstimate();
double ccLb = concatSk.getLowerBound(2);
double ccUb = concatSk.getUpperBound(2);
printf("Concatenated: %12.0f %12.0f %12.0f\n", ccLb, ccEst, ccUb);
// Memory mergedMem = Memory.wrap(mergedArr);
CpcWrapper mergedSk = new CpcWrapper(mergedArr);
double mEst = mergedSk.getEstimate();
double mLb = mergedSk.getLowerBound(2);
double mUb = mergedSk.getUpperBound(2);
printf("Merged: %12.0f %12.0f %12.0f\n", mLb, mEst, mUb);
assertEquals(Family.CPC, CpcWrapper.getFamily());
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class FdtSketchTest method checkFdtSketch.
@SuppressWarnings("deprecation")
@Test
public void checkFdtSketch() {
final int lgK = 14;
final FdtSketch sketch = new FdtSketch(lgK);
final String[] nodesArr = { "abc", "def" };
sketch.update(nodesArr);
final SketchIterator<ArrayOfStringsSummary> it = sketch.iterator();
int count = 0;
while (it.next()) {
final String[] nodesArr2 = it.getSummary().getValue();
assertEquals(nodesArr2, nodesArr);
count++;
}
assertEquals(count, 1);
// serialize
final byte[] byteArr = sketch.toByteArray();
// deserialize
Memory mem = Memory.wrap(byteArr);
FdtSketch sketch2 = new FdtSketch(mem);
// check output
final SketchIterator<ArrayOfStringsSummary> it2 = sketch2.iterator();
int count2 = 0;
while (it2.next()) {
final String[] nodesArr2 = it2.getSummary().getValue();
assertEquals(nodesArr2, nodesArr);
count2++;
}
assertEquals(count, count2);
assertEquals(sketch2.getEstimate(), sketch.getEstimate());
assertEquals(sketch2.getLowerBound(2), sketch.getLowerBound(2));
assertEquals(sketch2.getUpperBound(2), sketch.getUpperBound(2));
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class MurmurHash3v2Test method checkEmptiesNulls.
@Test
public void checkEmptiesNulls() {
long seed = 123;
long[] hashOut = new long[2];
try {
// mem empty
MurmurHash3v2.hash(Memory.wrap(new long[0]), 0, 0, seed, hashOut);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
try {
Memory mem = null;
// mem null
MurmurHash3v2.hash(mem, 0, 0, seed, hashOut);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
try {
String s = "";
// string empty
MurmurHash3v2.hash(s, seed, hashOut);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
try {
String s = null;
// string null
MurmurHash3v2.hash(s, seed, hashOut);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
try {
byte[] barr = new byte[0];
// byte[] empty
MurmurHash3v2.hash(barr, seed);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
try {
byte[] barr = null;
// byte[] null
MurmurHash3v2.hash(barr, seed);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
try {
char[] carr = new char[0];
// char[] empty
MurmurHash3v2.hash(carr, seed);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
try {
char[] carr = null;
// char[] null
MurmurHash3v2.hash(carr, seed);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
try {
int[] iarr = new int[0];
// int[] empty
MurmurHash3v2.hash(iarr, seed);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
try {
int[] iarr = null;
// int[] null
MurmurHash3v2.hash(iarr, seed);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
try {
long[] larr = new long[0];
// long[] empty
MurmurHash3v2.hash(larr, seed);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
try {
long[] larr = null;
// long[] null
MurmurHash3v2.hash(larr, seed);
fail();
}// OK
catch (final IllegalArgumentException e) {
}
}
Aggregations