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) {
}
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class CpcCBinariesTest method checkEmptyImages.
// Image checks
@Test
public void checkEmptyImages() {
final String fileName = "cpc-empty.sk";
final File file = getResourceFile(fileName);
try (MapHandle mh = Memory.map(file)) {
final Memory mem = mh.get();
final int cap = (int) mem.getCapacity();
final byte[] memByteArr = new byte[cap];
mem.getByteArray(0, memByteArr, 0, cap);
final CpcSketch sk = new CpcSketch(11);
final byte[] mem2ByteArr = sk.toByteArray();
final Memory mem2 = Memory.wrap(mem2ByteArr);
assertEquals(mem.getCapacity(), mem2.getCapacity());
assertEquals(memByteArr, mem2ByteArr);
} catch (final Exception e) {
e.printStackTrace();
}
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class CpcCBinariesTest method checkPinnedImages.
@Test
public void checkPinnedImages() {
final String fileName = "cpc-pinned.sk";
final File file = getResourceFile(fileName);
try (MapHandle mh = Memory.map(file)) {
final Memory mem = mh.get();
final int cap = (int) mem.getCapacity();
final byte[] cppMemByteArr = new byte[cap];
mem.getByteArray(0, cppMemByteArr, 0, cap);
final CpcSketch sk = new CpcSketch(11);
for (int i = 0; i < 2000; i++) {
sk.update(i);
}
final byte[] javaMemByteArr = sk.toByteArray();
final Memory mem2 = Memory.wrap(javaMemByteArr);
assertEquals(mem.getCapacity(), mem2.getCapacity());
assertEquals(cppMemByteArr, javaMemByteArr);
} catch (final Exception e) {
e.printStackTrace();
}
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class CpcCBinariesTest method checkPinnedBin.
@Test
public void checkPinnedBin() {
final String fileName = "cpc-pinned.sk";
final File file = getResourceFile(fileName);
try (MapHandle mh = Memory.map(file)) {
final Memory mem = mh.get();
println("CPP GENERATED SKETCH FROM BINARY FILE LgK=11, U0 to U1999");
println("PreambleUtil.toString(mem, true)" + LS);
println(PreambleUtil.toString(mem, true));
println(LS + LS + "################");
println("CpcSketch sk = CpcSketch.heapify(mem);");
println("sk.toString(true)" + LS);
final CpcSketch sk = CpcSketch.heapify(mem);
println(sk.toString(true));
assertEquals(sk.getFlavor(), Flavor.PINNED);
final double est1 = sk.getEstimate();
assertEquals(est1, 2000, 2000 * .02);
for (long i = 0; i < 2000; i++) {
sk.update(i);
}
final double est2 = sk.getEstimate();
// assert no change
assertEquals(est2, est1, 0);
} catch (final Exception e) {
e.printStackTrace();
}
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class CpcCBinariesTest method checkSlidingBin.
@Test
public void checkSlidingBin() {
final String fileName = "cpc-sliding.sk";
final File file = getResourceFile(fileName);
try (MapHandle mh = Memory.map(file)) {
final Memory mem = mh.get();
println("CPP GENERATED SKETCH FROM BINARY FILE LgK=11, U0 to U19999");
println("PreambleUtil.toString(mem, true)" + LS);
println(PreambleUtil.toString(mem, true));
println(LS + LS + "################");
println("CpcSketch sk = CpcSketch.heapify(mem);");
println("sk.toString(true)" + LS);
final CpcSketch sk = CpcSketch.heapify(mem);
println(sk.toString(true));
assertEquals(sk.getFlavor(), Flavor.SLIDING);
final double est1 = sk.getEstimate();
assertEquals(est1, 20000, 20000 * .02);
for (long i = 0; i < 20000; i++) {
sk.update(i);
}
final double est2 = sk.getEstimate();
assertEquals(est2, est1, 0);
} catch (final Exception e) {
e.printStackTrace();
}
}
Aggregations