void Create() { if (_matchFinder == null) { LZBinTree bt = new LZBinTree(); int numHashBytes = 4; if (_matchFinderType == EMatchFinderType.BT2) numHashBytes = 2; bt.SetType(numHashBytes); _matchFinder = bt; } _literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits); if (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes) return; _matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, LZMABase.kMatchMaxLen + 1); _dictionarySizePrev = _dictionarySize; _numFastBytesPrev = _numFastBytes; }
public void SetCoderProperties(CoderPropID[] propIDs, object[] properties) { for (UInt32 i = 0; i < properties.Length; i++) { object prop = properties[i]; switch (propIDs[i]) { case CoderPropID.NumFastBytes: { if (!(prop is Int32)) throw new Exception(); Int32 numFastBytes = (Int32)prop; if (numFastBytes < 5 || numFastBytes > LZMABase.kMatchMaxLen) throw new Exception(); _numFastBytes = (UInt32)numFastBytes; break; } case CoderPropID.Algorithm: { break; } case CoderPropID.MatchFinder: { if (!(prop is String)) throw new Exception(); EMatchFinderType matchFinderIndexPrev = _matchFinderType; int m = FindMatchFinder(((string)prop).ToUpper()); if (m < 0) throw new Exception(); _matchFinderType = (EMatchFinderType)m; if (_matchFinder != null && matchFinderIndexPrev != _matchFinderType) { _dictionarySizePrev = 0xFFFFFFFF; _matchFinder = null; } break; } case CoderPropID.DictionarySize: { const int kDicLogSizeMaxCompress = 30; if (!(prop is Int32)) throw new Exception(); ; Int32 dictionarySize = (Int32)prop; if (dictionarySize < (UInt32)(1 << LZMABase.kDicLogSizeMin) || dictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress)) throw new Exception(); _dictionarySize = (UInt32)dictionarySize; int dicLogSize; for (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++) if (dictionarySize <= ((UInt32)(1) << dicLogSize)) break; _distTableSize = (UInt32)dicLogSize * 2; break; } case CoderPropID.PosStateBits: { if (!(prop is Int32)) throw new Exception(); Int32 v = (Int32)prop; if (v < 0 || v > (UInt32)LZMABase.kNumPosStatesBitsEncodingMax) throw new Exception(); _posStateBits = (int)v; _posStateMask = (((UInt32)1) << (int)_posStateBits) - 1; break; } case CoderPropID.LitPosBits: { if (!(prop is Int32)) throw new Exception(); Int32 v = (Int32)prop; if (v < 0 || v > (UInt32)LZMABase.kNumLitPosStatesBitsEncodingMax) throw new Exception(); _numLiteralPosStateBits = (int)v; break; } case CoderPropID.LitContextBits: { if (!(prop is Int32)) throw new Exception(); Int32 v = (Int32)prop; if (v < 0 || v > (UInt32)LZMABase.kNumLitContextBitsMax) throw new Exception(); ; _numLiteralContextBits = (int)v; break; } case CoderPropID.EndMarker: { if (!(prop is Boolean)) throw new Exception(); SetWriteEndMarkerMode((Boolean)prop); break; } default: throw new Exception(); } } }