use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class SetOperation method wrap.
/**
* Wrap takes the SetOperation image in Memory and refers to it directly.
* There is no data copying onto the java heap.
*
* <p>Note: Only certain set operators during stateful operations can be serialized and thus
* wrapped.</p>
*
* @param srcMem an image of a SetOperation where the hash of the given expectedSeed matches the image seed hash.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
* @return a SetOperation backed by the given Memory
*/
public static SetOperation wrap(final WritableMemory srcMem, final long expectedSeed) {
final byte famID = srcMem.getByte(FAMILY_BYTE);
final Family family = idToFamily(famID);
final int serVer = srcMem.getByte(SER_VER_BYTE);
if (serVer != 3) {
throw new SketchesArgumentException("SerVer must be 3: " + serVer);
}
switch(family) {
case UNION:
{
return UnionImpl.wrapInstance(srcMem, expectedSeed);
}
case INTERSECTION:
{
return IntersectionImpl.wrapInstance(srcMem, expectedSeed, false);
}
default:
throw new SketchesArgumentException("SetOperation cannot wrap family: " + family.toString());
}
}
use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class SetOperation method wrap.
/**
* Wrap takes the SetOperation image in Memory and refers to it directly.
* There is no data copying onto the java heap.
*
* <p>Note: Only certain set operators during stateful operations can be serialized and thus
* wrapped.</p>
*
* @param srcMem an image of a SetOperation where the hash of the given expectedSeed matches the image seed hash.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
* @return a SetOperation backed by the given Memory
*/
public static SetOperation wrap(final Memory srcMem, final long expectedSeed) {
final byte famID = srcMem.getByte(FAMILY_BYTE);
final Family family = idToFamily(famID);
final int serVer = srcMem.getByte(SER_VER_BYTE);
if (serVer != 3) {
throw new SketchesArgumentException("SerVer must be 3: " + serVer);
}
switch(family) {
case UNION:
{
return UnionImpl.wrapInstance(srcMem, expectedSeed);
}
case INTERSECTION:
{
return IntersectionImpl.wrapInstance((WritableMemory) srcMem, expectedSeed, true);
}
default:
throw new SketchesArgumentException("SetOperation cannot wrap family: " + family.toString());
}
}
use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class HeapArrayOfDoublesUnion method heapifyUnion.
/**
* This is to create an instance given a serialized form and a custom seed
* @param mem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @return a ArrayOfDoublesUnion on the Java heap
*/
static ArrayOfDoublesUnion heapifyUnion(final Memory mem, final long seed) {
final byte version = mem.getByte(SERIAL_VERSION_BYTE);
if (version != serialVersionUID) {
throw new SketchesArgumentException("Serial version mismatch. Expected: " + serialVersionUID + ", actual: " + version);
}
SerializerDeserializer.validateFamily(mem.getByte(FAMILY_ID_BYTE), mem.getByte(PREAMBLE_LONGS_BYTE));
SerializerDeserializer.validateType(mem.getByte(SKETCH_TYPE_BYTE), SerializerDeserializer.SketchType.ArrayOfDoublesUnion);
final Memory sketchMem = mem.region(PREAMBLE_SIZE_BYTES, mem.getCapacity() - PREAMBLE_SIZE_BYTES);
final ArrayOfDoublesQuickSelectSketch sketch = new HeapArrayOfDoublesQuickSelectSketch(sketchMem, seed);
return new HeapArrayOfDoublesUnion(sketch, mem.getLong(THETA_LONG));
}
use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class DirectArrayOfDoublesUnion method wrapUnion.
static ArrayOfDoublesUnion wrapUnion(final WritableMemory mem, final long seed, final boolean isWritable) {
final byte version = mem.getByte(ArrayOfDoublesUnion.SERIAL_VERSION_BYTE);
if (version != ArrayOfDoublesUnion.serialVersionUID) {
throw new SketchesArgumentException("Serial version mismatch. Expected: " + serialVersionUID + ", actual: " + version);
}
SerializerDeserializer.validateFamily(mem.getByte(FAMILY_ID_BYTE), mem.getByte(PREAMBLE_LONGS_BYTE));
SerializerDeserializer.validateType(mem.getByte(SKETCH_TYPE_BYTE), SerializerDeserializer.SketchType.ArrayOfDoublesUnion);
if (isWritable) {
final WritableMemory sketchMem = mem.writableRegion(PREAMBLE_SIZE_BYTES, mem.getCapacity() - PREAMBLE_SIZE_BYTES);
return new DirectArrayOfDoublesUnion(new DirectArrayOfDoublesQuickSelectSketch(sketchMem, seed), mem);
}
final Memory sketchMem = mem.region(PREAMBLE_SIZE_BYTES, mem.getCapacity() - PREAMBLE_SIZE_BYTES);
return new DirectArrayOfDoublesUnionR(new DirectArrayOfDoublesQuickSelectSketchR(sketchMem, seed), mem);
}
Aggregations