public static int LZ4_saveDictHC( LZ4_streamHC_t *LZ4_streamHCPtr, byte *safeBuffer, int dictSize) { LZ4_streamHC_t *streamPtr = LZ4_streamHCPtr; int prefixSize = (int)(streamPtr->end - (streamPtr->@base + streamPtr->dictLimit)); if (dictSize > 64 * KB) { dictSize = 64 * KB; } if (dictSize < 4) { dictSize = 0; } if (dictSize > prefixSize) { dictSize = prefixSize; } Mem.Move(safeBuffer, streamPtr->end - dictSize, dictSize); uint endIndex = (uint)(streamPtr->end - streamPtr->@base); streamPtr->end = (byte *)safeBuffer + dictSize; streamPtr->@base = streamPtr->end - endIndex; streamPtr->dictLimit = endIndex - (uint)dictSize; streamPtr->lowLimit = endIndex - (uint)dictSize; if (streamPtr->nextToUpdate < streamPtr->dictLimit) { streamPtr->nextToUpdate = streamPtr->dictLimit; } return(dictSize); }
public static int LZ4_loadDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, byte *dictionary, int dictSize) { LZ4_streamHC_t *ctxPtr = LZ4_streamHCPtr; Assert(LZ4_streamHCPtr != null); if (dictSize > 64 * KB) { dictionary += dictSize - 64 * KB; dictSize = 64 * KB; } /* need a full initialization, there are bad side-effects when using resetFast() */ { int cLevel = ctxPtr->compressionLevel; LZ4_initStreamHC(LZ4_streamHCPtr); LZ4_setCompressionLevel(LZ4_streamHCPtr, cLevel); } LZ4HC_init_internal(ctxPtr, (byte *)dictionary); ctxPtr->end = (byte *)dictionary + dictSize; if (dictSize >= 4) { LZ4HC_Insert(ctxPtr, ctxPtr->end - 3); } return(dictSize); }
public static void LZ4HC_clearTables(LZ4_streamHC_t *hc4) { // uint hashTable[LZ4HC_HASHTABLESIZE]; // ushort chainTable[LZ4HC_MAXD]; Mem.Fill((byte *)hc4->hashTable, 0, sizeof(uint) * LZ4HC_HASHTABLESIZE); Mem.Fill((byte *)hc4->chainTable, 0xFF, sizeof(ushort) * LZ4HC_MAXD); }
public static int LZ4_freeStreamHC(LZ4_streamHC_t *LZ4_streamHCPtr) { if (LZ4_streamHCPtr == null) { return(0); } Mem.Free(LZ4_streamHCPtr); return(0); }
public static LZ4_streamHC_t *LZ4_createStreamHC() { LZ4_streamHC_t *LZ4_streamHCPtr = (LZ4_streamHC_t *)Mem.Alloc(sizeof(LZ4_streamHC_t)); if (LZ4_streamHCPtr == null) { return(null); } LZ4_initStreamHC(LZ4_streamHCPtr); return(LZ4_streamHCPtr); }
public static void LZ4_setCompressionLevel( LZ4_streamHC_t *LZ4_streamHCPtr, int compressionLevel) { if (compressionLevel < 1) { compressionLevel = LZ4HC_CLEVEL_DEFAULT; } if (compressionLevel > LZ4HC_CLEVEL_MAX) { compressionLevel = LZ4HC_CLEVEL_MAX; } LZ4_streamHCPtr->compressionLevel = (short)compressionLevel; }
public static void LZ4_resetStreamHC_fast( LZ4_streamHC_t *LZ4_streamHCPtr, int compressionLevel) { if (LZ4_streamHCPtr->dirty) { LZ4_initStreamHC(LZ4_streamHCPtr); } else { LZ4_streamHCPtr->end -= LZ4_streamHCPtr->@base; LZ4_streamHCPtr->@base = null; LZ4_streamHCPtr->dictCtx = null; } LZ4_setCompressionLevel(LZ4_streamHCPtr, compressionLevel); }
public static void LZ4HC_init_internal(LZ4_streamHC_t *hc4, byte *start) { var startingOffset = (hc4->end - hc4->@base); if (startingOffset < 0 || startingOffset > 1 * GB) { LZ4HC_clearTables(hc4); startingOffset = 0; } startingOffset += 64 * KB; hc4->nextToUpdate = (uint)startingOffset; hc4->@base = start - startingOffset; hc4->end = start; hc4->dictBase = start - startingOffset; hc4->dictLimit = (uint)startingOffset; hc4->lowLimit = (uint)startingOffset; }
public static void LZ4HC_setExternalDict(LZ4_streamHC_t *ctxPtr, byte *newBlock) { if (ctxPtr->end >= ctxPtr->@base + ctxPtr->dictLimit + 4) { LZ4HC_Insert( ctxPtr, ctxPtr->end - 3); /* Referencing remaining dictionary content */ } /* Only one memory segment for extDict, so any previous extDict is lost at this stage */ ctxPtr->lowLimit = ctxPtr->dictLimit; ctxPtr->dictLimit = (uint)(ctxPtr->end - ctxPtr->@base); ctxPtr->dictBase = ctxPtr->@base; ctxPtr->@base = newBlock - ctxPtr->dictLimit; ctxPtr->end = newBlock; ctxPtr->nextToUpdate = ctxPtr->dictLimit; /* match referencing will resume from there */ /* cannot reference an extDict and a dictCtx at the same time */ ctxPtr->dictCtx = null; }
public static LZ4_streamHC_t *LZ4_initStreamHC(void *buffer, int size) { LZ4_streamHC_t *LZ4_streamHCPtr = (LZ4_streamHC_t *)buffer; if (buffer == null) { return(null); } if (size < sizeof(LZ4_streamHC_t)) { return(null); } LZ4_streamHCPtr->end = (byte *)-1; LZ4_streamHCPtr->@base = null; LZ4_streamHCPtr->dictCtx = null; LZ4_streamHCPtr->favorDecSpeed = false; LZ4_streamHCPtr->dirty = false; LZ4_setCompressionLevel(LZ4_streamHCPtr, LZ4HC_CLEVEL_DEFAULT); return(LZ4_streamHCPtr); }
public static void LZ4HC_Insert(LZ4_streamHC_t *hc4, byte *ip) { ushort *chainTable = hc4->chainTable; uint * hashTable = hc4->hashTable; byte * @base = hc4->@base; uint target = (uint)(ip - @base); uint idx = hc4->nextToUpdate; while (idx < target) { uint h = LZ4HC_hashPtr(@base + idx); uint delta = idx - hashTable[h]; if (delta > LZ4_DISTANCE_MAX) { delta = LZ4_DISTANCE_MAX; } DELTANEXTU16(chainTable, idx) = (ushort)delta; hashTable[h] = idx; idx++; } hc4->nextToUpdate = target; }
public static LZ4_streamHC_t *LZ4_initStreamHC(LZ4_streamHC_t *stream) => LZ4_initStreamHC(stream, sizeof(LZ4_streamHC_t));
public static void LZ4_favorDecompressionSpeed(LZ4_streamHC_t *LZ4_streamHCPtr, int favor) { LZ4_streamHCPtr->favorDecSpeed = (favor != 0); }