public static final HllSketch writableWrap ( final WritableMemory wmem ) { final boolean compact = extractCompactFlag ( wmem ) ; if ( compact ) { throw new SketchesArgumentException ( "Cannot perform a writableWrap of a writable sketch image that is in compact form." ) ; } final int lgConfigK = extractLgK ( wmem ) ; final TgtHllType tgtHllType = extractTgtHllType ( wmem ) ; final long minBytes = getMaxUpdatableSerializationBytes ( lgConfigK , tgtHllType ) ; final long capBytes = wmem . getCapacity ( ) ; HllUtil . checkMemSize ( minBytes , capBytes ) ; final CurMode curMode = checkPreamble ( wmem ) ; final HllSketch directSketch ; if ( curMode == CurMode . HLL ) { if ( tgtHllType == TgtHllType . HLL_4 ) { directSketch = new HllSketch ( new DirectHll4Array ( lgConfigK , wmem ) ) ; } else if ( tgtHllType == TgtHllType . HLL_6 ) { directSketch = new HllSketch ( new DirectHll6Array ( lgConfigK , wmem ) ) ; } else { //Hll_8 directSketch = new HllSketch ( new DirectHll8Array ( lgConfigK , wmem ) ) ; } } else if ( curMode == CurMode . LIST ) { directSketch = new HllSketch ( new DirectCouponList ( lgConfigK , tgtHllType , curMode , wmem ) ) ; } else { directSketch = new HllSketch ( new DirectCouponHashSet ( lgConfigK , tgtHllType , wmem ) ) ; } return directSketch ; }
Wraps the given WritableMemory which must be a image of a valid updatable sketch and may have data . What remains on the java heap is a thin wrapper object that reads and writes to the given WritableMemory which depending on how the user configures the WritableMemory may actually reside on the Java heap or off - heap .