com.wallstop-studios.unity-helpers 2.0.0-rc79.3 → 2.0.0-rc79.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +5 -1
- package/.github/workflows/npm-publish.yml +2 -2
- package/Runtime/Core/Extension/IReadonlyListExtensions.cs +1 -1
- package/Runtime/Core/Extension/IReadonlyListExtensions.cs.meta +1 -1
- package/Runtime/Core/Extension/StringExtensions.cs +1 -1
- package/Runtime/Core/Helper/StringInList.cs +3 -21
- package/Runtime/Core/Threading/SingleThreadedThreadPool.cs +157 -49
- package/Runtime/Utils/Buffers.cs +118 -2
- package/Runtime/Utils/SevenZip/Common/CRC.cs +9 -0
- package/Runtime/Utils/SevenZip/Common/InBuffer.cs +15 -2
- package/Runtime/Utils/SevenZip/Common/OutBuffer.cs +7 -2
- package/Runtime/Utils/SevenZip/Compress/LZ/LzBinTree.cs +50 -0
- package/Runtime/Utils/SevenZip/Compress/LZ/LzInWindow.cs +26 -0
- package/Runtime/Utils/SevenZip/Compress/LZ/LzOutWindow.cs +27 -0
- package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaBase.cs +9 -0
- package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaDecoder.cs +80 -17
- package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaEncoder.cs +265 -30
- package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoder.cs +9 -0
- package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoderBit.cs +13 -1
- package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoderBitTree.cs +11 -4
- package/Tests/Runtime/Core/Threading/SingleThreadedThreadPoolTests.cs +54 -0
- package/Tests/Runtime/Core/Threading/SingleThreadedThreadPoolTests.cs.meta +3 -0
- package/Tests/Runtime/Core/Threading.meta +3 -0
- package/Tests/Runtime/Core.meta +3 -0
- package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs +1 -1
- package/Tests/Runtime/DataStructures/CyclicBufferTests.cs +1 -1
- package/Tests/Runtime/DataStructures/QuadTreeTests.cs +1 -1
- package/Tests/Runtime/DataStructures/SpatialTreeTests.cs +1 -1
- package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs +1 -1
- package/Tests/Runtime/Extensions/DictionaryExtensionTests.cs +1 -1
- package/Tests/Runtime/Extensions/EnumExtensionTests.cs +1 -1
- package/Tests/Runtime/Extensions/IListExtensionTests.cs +1 -1
- package/Tests/Runtime/Extensions/IReadonlyListExtensionTests.cs +1 -1
- package/Tests/Runtime/Extensions/IReadonlyListExtensionTests.cs.meta +1 -1
- package/Tests/Runtime/Extensions/LoggingExtensionTests.cs +1 -1
- package/Tests/Runtime/Extensions/RandomExtensionTests.cs +1 -1
- package/Tests/Runtime/Extensions/StringExtensionTests.cs +1 -1
- package/Tests/Runtime/Helper/ObjectHelperTests.cs +1 -1
- package/Tests/Runtime/Helper/WallMathTests.cs +1 -1
- package/Tests/Runtime/Performance/KDTreePerformanceTests.cs +1 -1
- package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs +1 -1
- package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs +1 -2
- package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs +1 -1
- package/Tests/Runtime/Random/RandomTestBase.cs +2 -2
- package/Tests/Runtime/Serialization/JsonSerializationTest.cs +1 -1
- package/Tests/Runtime/Utils/BuffersTests.cs +55 -0
- package/Tests/Runtime/Utils/BuffersTests.cs.meta +3 -0
- package/package.json +3 -1
|
@@ -16,7 +16,7 @@ namespace SevenZip.Compression.LZMA
|
|
|
16
16
|
|
|
17
17
|
const UInt32 kIfinityPrice = 0xFFFFFFF;
|
|
18
18
|
|
|
19
|
-
static Byte[] g_FastPos = new Byte[1 << 11];
|
|
19
|
+
static readonly Byte[] g_FastPos = new Byte[1 << 11];
|
|
20
20
|
|
|
21
21
|
static Encoder()
|
|
22
22
|
{
|
|
@@ -28,38 +28,54 @@ namespace SevenZip.Compression.LZMA
|
|
|
28
28
|
{
|
|
29
29
|
UInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));
|
|
30
30
|
for (UInt32 j = 0; j < k; j++, c++)
|
|
31
|
+
{
|
|
31
32
|
g_FastPos[c] = slotFast;
|
|
33
|
+
}
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
static UInt32 GetPosSlot(UInt32 pos)
|
|
36
38
|
{
|
|
37
39
|
if (pos < (1 << 11))
|
|
40
|
+
{
|
|
38
41
|
return g_FastPos[pos];
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
if (pos < (1 << 21))
|
|
45
|
+
{
|
|
40
46
|
return (UInt32)(g_FastPos[pos >> 10] + 20);
|
|
47
|
+
}
|
|
48
|
+
|
|
41
49
|
return (UInt32)(g_FastPos[pos >> 20] + 40);
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
static UInt32 GetPosSlot2(UInt32 pos)
|
|
45
53
|
{
|
|
46
54
|
if (pos < (1 << 17))
|
|
55
|
+
{
|
|
47
56
|
return (UInt32)(g_FastPos[pos >> 6] + 12);
|
|
57
|
+
}
|
|
58
|
+
|
|
48
59
|
if (pos < (1 << 27))
|
|
60
|
+
{
|
|
49
61
|
return (UInt32)(g_FastPos[pos >> 16] + 32);
|
|
62
|
+
}
|
|
63
|
+
|
|
50
64
|
return (UInt32)(g_FastPos[pos >> 26] + 52);
|
|
51
65
|
}
|
|
52
66
|
|
|
53
67
|
Base.State _state = new Base.State();
|
|
54
68
|
Byte _previousByte;
|
|
55
|
-
UInt32[] _repDistances = new UInt32[Base.kNumRepDistances];
|
|
69
|
+
readonly UInt32[] _repDistances = new UInt32[Base.kNumRepDistances];
|
|
56
70
|
|
|
57
71
|
void BaseInit()
|
|
58
72
|
{
|
|
59
73
|
_state.Init();
|
|
60
74
|
_previousByte = 0;
|
|
61
75
|
for (UInt32 i = 0; i < Base.kNumRepDistances; i++)
|
|
76
|
+
{
|
|
62
77
|
_repDistances[i] = 0;
|
|
78
|
+
}
|
|
63
79
|
}
|
|
64
80
|
|
|
65
81
|
const int kDefaultDictionaryLogSize = 22;
|
|
@@ -79,7 +95,9 @@ namespace SevenZip.Compression.LZMA
|
|
|
79
95
|
public void Init()
|
|
80
96
|
{
|
|
81
97
|
for (int i = 0; i < 0x300; i++)
|
|
98
|
+
{
|
|
82
99
|
m_Encoders[i].Init();
|
|
100
|
+
}
|
|
83
101
|
}
|
|
84
102
|
|
|
85
103
|
public void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)
|
|
@@ -154,21 +172,28 @@ namespace SevenZip.Compression.LZMA
|
|
|
154
172
|
public void Create(int numPosBits, int numPrevBits)
|
|
155
173
|
{
|
|
156
174
|
if (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)
|
|
175
|
+
{
|
|
157
176
|
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
158
179
|
m_NumPosBits = numPosBits;
|
|
159
180
|
m_PosMask = ((uint)1 << numPosBits) - 1;
|
|
160
181
|
m_NumPrevBits = numPrevBits;
|
|
161
182
|
uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);
|
|
162
183
|
m_Coders = new Encoder2[numStates];
|
|
163
184
|
for (uint i = 0; i < numStates; i++)
|
|
185
|
+
{
|
|
164
186
|
m_Coders[i].Create();
|
|
187
|
+
}
|
|
165
188
|
}
|
|
166
189
|
|
|
167
190
|
public void Init()
|
|
168
191
|
{
|
|
169
192
|
uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);
|
|
170
193
|
for (uint i = 0; i < numStates; i++)
|
|
194
|
+
{
|
|
171
195
|
m_Coders[i].Init();
|
|
196
|
+
}
|
|
172
197
|
}
|
|
173
198
|
|
|
174
199
|
public Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)
|
|
@@ -183,10 +208,12 @@ namespace SevenZip.Compression.LZMA
|
|
|
183
208
|
{
|
|
184
209
|
RangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();
|
|
185
210
|
RangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();
|
|
186
|
-
|
|
211
|
+
|
|
212
|
+
readonly RangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[
|
|
187
213
|
Base.kNumPosStatesEncodingMax
|
|
188
214
|
];
|
|
189
|
-
|
|
215
|
+
|
|
216
|
+
readonly RangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[
|
|
190
217
|
Base.kNumPosStatesEncodingMax
|
|
191
218
|
];
|
|
192
219
|
RangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(
|
|
@@ -248,19 +275,27 @@ namespace SevenZip.Compression.LZMA
|
|
|
248
275
|
for (i = 0; i < Base.kNumLowLenSymbols; i++)
|
|
249
276
|
{
|
|
250
277
|
if (i >= numSymbols)
|
|
278
|
+
{
|
|
251
279
|
return;
|
|
280
|
+
}
|
|
281
|
+
|
|
252
282
|
prices[st + i] = a0 + _lowCoder[posState].GetPrice(i);
|
|
253
283
|
}
|
|
254
284
|
for (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)
|
|
255
285
|
{
|
|
256
286
|
if (i >= numSymbols)
|
|
287
|
+
{
|
|
257
288
|
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
258
291
|
prices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);
|
|
259
292
|
}
|
|
260
293
|
for (; i < numSymbols; i++)
|
|
294
|
+
{
|
|
261
295
|
prices[st + i] =
|
|
262
296
|
b1
|
|
263
297
|
+ _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);
|
|
298
|
+
}
|
|
264
299
|
}
|
|
265
300
|
};
|
|
266
301
|
|
|
@@ -268,9 +303,11 @@ namespace SevenZip.Compression.LZMA
|
|
|
268
303
|
|
|
269
304
|
class LenPriceTableEncoder : LenEncoder
|
|
270
305
|
{
|
|
271
|
-
UInt32[] _prices = new UInt32[
|
|
306
|
+
readonly UInt32[] _prices = new UInt32[
|
|
307
|
+
Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax
|
|
308
|
+
];
|
|
272
309
|
UInt32 _tableSize;
|
|
273
|
-
UInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];
|
|
310
|
+
readonly UInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];
|
|
274
311
|
|
|
275
312
|
public void SetTableSize(UInt32 tableSize)
|
|
276
313
|
{
|
|
@@ -291,14 +328,18 @@ namespace SevenZip.Compression.LZMA
|
|
|
291
328
|
public void UpdateTables(UInt32 numPosStates)
|
|
292
329
|
{
|
|
293
330
|
for (UInt32 posState = 0; posState < numPosStates; posState++)
|
|
331
|
+
{
|
|
294
332
|
UpdateTable(posState);
|
|
333
|
+
}
|
|
295
334
|
}
|
|
296
335
|
|
|
297
336
|
public new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)
|
|
298
337
|
{
|
|
299
338
|
base.Encode(rangeEncoder, symbol, posState);
|
|
300
339
|
if (--_counters[posState] == 0)
|
|
340
|
+
{
|
|
301
341
|
UpdateTable(posState);
|
|
342
|
+
}
|
|
302
343
|
}
|
|
303
344
|
}
|
|
304
345
|
|
|
@@ -342,38 +383,40 @@ namespace SevenZip.Compression.LZMA
|
|
|
342
383
|
}
|
|
343
384
|
};
|
|
344
385
|
|
|
345
|
-
Optimal[] _optimum = new Optimal[kNumOpts];
|
|
386
|
+
readonly Optimal[] _optimum = new Optimal[kNumOpts];
|
|
346
387
|
LZ.IMatchFinder _matchFinder = null;
|
|
347
|
-
RangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();
|
|
388
|
+
readonly RangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();
|
|
348
389
|
|
|
349
|
-
RangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[
|
|
390
|
+
readonly RangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[
|
|
350
391
|
Base.kNumStates << Base.kNumPosStatesBitsMax
|
|
351
392
|
];
|
|
352
|
-
|
|
353
|
-
RangeCoder.BitEncoder[]
|
|
354
|
-
RangeCoder.BitEncoder[]
|
|
355
|
-
RangeCoder.BitEncoder[]
|
|
356
|
-
RangeCoder.BitEncoder[]
|
|
393
|
+
|
|
394
|
+
readonly RangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];
|
|
395
|
+
readonly RangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];
|
|
396
|
+
readonly RangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];
|
|
397
|
+
readonly RangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];
|
|
398
|
+
|
|
399
|
+
readonly RangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[
|
|
357
400
|
Base.kNumStates << Base.kNumPosStatesBitsMax
|
|
358
401
|
];
|
|
359
402
|
|
|
360
|
-
RangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[
|
|
403
|
+
readonly RangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[
|
|
361
404
|
Base.kNumLenToPosStates
|
|
362
405
|
];
|
|
363
406
|
|
|
364
|
-
RangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[
|
|
407
|
+
readonly RangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[
|
|
365
408
|
Base.kNumFullDistances - Base.kEndPosModelIndex
|
|
366
409
|
];
|
|
367
410
|
RangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(
|
|
368
411
|
Base.kNumAlignBits
|
|
369
412
|
);
|
|
370
413
|
|
|
371
|
-
LenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();
|
|
372
|
-
LenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();
|
|
414
|
+
readonly LenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();
|
|
415
|
+
readonly LenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();
|
|
373
416
|
|
|
374
|
-
LiteralEncoder _literalEncoder = new LiteralEncoder();
|
|
417
|
+
readonly LiteralEncoder _literalEncoder = new LiteralEncoder();
|
|
375
418
|
|
|
376
|
-
UInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen * 2 + 2];
|
|
419
|
+
readonly UInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen * 2 + 2];
|
|
377
420
|
|
|
378
421
|
UInt32 _numFastBytes = kNumFastBytesDefault;
|
|
379
422
|
UInt32 _longestMatchLength;
|
|
@@ -386,13 +429,15 @@ namespace SevenZip.Compression.LZMA
|
|
|
386
429
|
|
|
387
430
|
bool _longestMatchWasFound;
|
|
388
431
|
|
|
389
|
-
UInt32[] _posSlotPrices = new UInt32[
|
|
432
|
+
readonly UInt32[] _posSlotPrices = new UInt32[
|
|
390
433
|
1 << (Base.kNumPosSlotBits + Base.kNumLenToPosStatesBits)
|
|
391
434
|
];
|
|
392
|
-
|
|
435
|
+
|
|
436
|
+
readonly UInt32[] _distancesPrices = new UInt32[
|
|
393
437
|
Base.kNumFullDistances << Base.kNumLenToPosStatesBits
|
|
394
438
|
];
|
|
395
|
-
|
|
439
|
+
|
|
440
|
+
readonly UInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];
|
|
396
441
|
UInt32 _alignPriceCount;
|
|
397
442
|
|
|
398
443
|
UInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);
|
|
@@ -422,14 +467,20 @@ namespace SevenZip.Compression.LZMA
|
|
|
422
467
|
LZ.BinTree bt = new LZ.BinTree();
|
|
423
468
|
int numHashBytes = 4;
|
|
424
469
|
if (_matchFinderType == EMatchFinderType.BT2)
|
|
470
|
+
{
|
|
425
471
|
numHashBytes = 2;
|
|
472
|
+
}
|
|
473
|
+
|
|
426
474
|
bt.SetType(numHashBytes);
|
|
427
475
|
_matchFinder = bt;
|
|
428
476
|
}
|
|
429
477
|
_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);
|
|
430
478
|
|
|
431
479
|
if (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)
|
|
480
|
+
{
|
|
432
481
|
return;
|
|
482
|
+
}
|
|
483
|
+
|
|
433
484
|
_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);
|
|
434
485
|
_dictionarySizePrev = _dictionarySize;
|
|
435
486
|
_numFastBytesPrev = _numFastBytes;
|
|
@@ -438,9 +489,14 @@ namespace SevenZip.Compression.LZMA
|
|
|
438
489
|
public Encoder()
|
|
439
490
|
{
|
|
440
491
|
for (int i = 0; i < kNumOpts; i++)
|
|
492
|
+
{
|
|
441
493
|
_optimum[i] = new Optimal();
|
|
494
|
+
}
|
|
495
|
+
|
|
442
496
|
for (int i = 0; i < Base.kNumLenToPosStates; i++)
|
|
497
|
+
{
|
|
443
498
|
_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);
|
|
499
|
+
}
|
|
444
500
|
}
|
|
445
501
|
|
|
446
502
|
void SetWriteEndMarkerMode(bool writeEndMarker)
|
|
@@ -469,9 +525,14 @@ namespace SevenZip.Compression.LZMA
|
|
|
469
525
|
}
|
|
470
526
|
_literalEncoder.Init();
|
|
471
527
|
for (i = 0; i < Base.kNumLenToPosStates; i++)
|
|
528
|
+
{
|
|
472
529
|
_posSlotEncoder[i].Init();
|
|
530
|
+
}
|
|
531
|
+
|
|
473
532
|
for (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)
|
|
533
|
+
{
|
|
474
534
|
_posEncoders[i].Init();
|
|
535
|
+
}
|
|
475
536
|
|
|
476
537
|
_lenEncoder.Init((UInt32)1 << _posStateBits);
|
|
477
538
|
_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);
|
|
@@ -492,11 +553,13 @@ namespace SevenZip.Compression.LZMA
|
|
|
492
553
|
{
|
|
493
554
|
lenRes = _matchDistances[numDistancePairs - 2];
|
|
494
555
|
if (lenRes == _numFastBytes)
|
|
556
|
+
{
|
|
495
557
|
lenRes += _matchFinder.GetMatchLen(
|
|
496
558
|
(int)lenRes - 1,
|
|
497
559
|
_matchDistances[numDistancePairs - 1],
|
|
498
560
|
Base.kMatchMaxLen - lenRes
|
|
499
561
|
);
|
|
562
|
+
}
|
|
500
563
|
}
|
|
501
564
|
_additionalOffset++;
|
|
502
565
|
}
|
|
@@ -529,7 +592,9 @@ namespace SevenZip.Compression.LZMA
|
|
|
529
592
|
{
|
|
530
593
|
price = _isRepG0[state.Index].GetPrice1();
|
|
531
594
|
if (repIndex == 1)
|
|
595
|
+
{
|
|
532
596
|
price += _isRepG1[state.Index].GetPrice0();
|
|
597
|
+
}
|
|
533
598
|
else
|
|
534
599
|
{
|
|
535
600
|
price += _isRepG1[state.Index].GetPrice1();
|
|
@@ -550,11 +615,16 @@ namespace SevenZip.Compression.LZMA
|
|
|
550
615
|
UInt32 price;
|
|
551
616
|
UInt32 lenToPosState = Base.GetLenToPosState(len);
|
|
552
617
|
if (pos < Base.kNumFullDistances)
|
|
618
|
+
{
|
|
553
619
|
price = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];
|
|
620
|
+
}
|
|
554
621
|
else
|
|
622
|
+
{
|
|
555
623
|
price =
|
|
556
624
|
_posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)]
|
|
557
625
|
+ _alignPrices[pos & Base.kAlignMask];
|
|
626
|
+
}
|
|
627
|
+
|
|
558
628
|
return price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);
|
|
559
629
|
}
|
|
560
630
|
|
|
@@ -591,8 +661,8 @@ namespace SevenZip.Compression.LZMA
|
|
|
591
661
|
return _optimumCurrentIndex;
|
|
592
662
|
}
|
|
593
663
|
|
|
594
|
-
UInt32[] reps = new UInt32[Base.kNumRepDistances];
|
|
595
|
-
UInt32[] repLens = new UInt32[Base.kNumRepDistances];
|
|
664
|
+
readonly UInt32[] reps = new UInt32[Base.kNumRepDistances];
|
|
665
|
+
readonly UInt32[] repLens = new UInt32[Base.kNumRepDistances];
|
|
596
666
|
|
|
597
667
|
UInt32 GetOptimum(UInt32 position, out UInt32 backRes)
|
|
598
668
|
{
|
|
@@ -625,7 +695,9 @@ namespace SevenZip.Compression.LZMA
|
|
|
625
695
|
return 1;
|
|
626
696
|
}
|
|
627
697
|
if (numAvailableBytes > Base.kMatchMaxLen)
|
|
698
|
+
{
|
|
628
699
|
numAvailableBytes = Base.kMatchMaxLen;
|
|
700
|
+
}
|
|
629
701
|
|
|
630
702
|
UInt32 repMaxIndex = 0;
|
|
631
703
|
UInt32 i;
|
|
@@ -634,7 +706,9 @@ namespace SevenZip.Compression.LZMA
|
|
|
634
706
|
reps[i] = _repDistances[i];
|
|
635
707
|
repLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);
|
|
636
708
|
if (repLens[i] > repLens[repMaxIndex])
|
|
709
|
+
{
|
|
637
710
|
repMaxIndex = i;
|
|
711
|
+
}
|
|
638
712
|
}
|
|
639
713
|
if (repLens[repMaxIndex] >= _numFastBytes)
|
|
640
714
|
{
|
|
@@ -701,14 +775,19 @@ namespace SevenZip.Compression.LZMA
|
|
|
701
775
|
_optimum[0].Backs3 = reps[3];
|
|
702
776
|
|
|
703
777
|
UInt32 len = lenEnd;
|
|
704
|
-
do
|
|
705
|
-
|
|
778
|
+
do
|
|
779
|
+
{
|
|
780
|
+
_optimum[len--].Price = kIfinityPrice;
|
|
781
|
+
} while (len >= 2);
|
|
706
782
|
|
|
707
783
|
for (i = 0; i < Base.kNumRepDistances; i++)
|
|
708
784
|
{
|
|
709
785
|
UInt32 repLen = repLens[i];
|
|
710
786
|
if (repLen < 2)
|
|
787
|
+
{
|
|
711
788
|
continue;
|
|
789
|
+
}
|
|
790
|
+
|
|
712
791
|
UInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);
|
|
713
792
|
do
|
|
714
793
|
{
|
|
@@ -732,7 +811,10 @@ namespace SevenZip.Compression.LZMA
|
|
|
732
811
|
{
|
|
733
812
|
UInt32 offs = 0;
|
|
734
813
|
while (len > _matchDistances[offs])
|
|
814
|
+
{
|
|
735
815
|
offs += 2;
|
|
816
|
+
}
|
|
817
|
+
|
|
736
818
|
for (; ; len++)
|
|
737
819
|
{
|
|
738
820
|
UInt32 distance = _matchDistances[offs + 1];
|
|
@@ -750,7 +832,9 @@ namespace SevenZip.Compression.LZMA
|
|
|
750
832
|
{
|
|
751
833
|
offs += 2;
|
|
752
834
|
if (offs == numDistancePairs)
|
|
835
|
+
{
|
|
753
836
|
break;
|
|
837
|
+
}
|
|
754
838
|
}
|
|
755
839
|
}
|
|
756
840
|
}
|
|
@@ -761,7 +845,10 @@ namespace SevenZip.Compression.LZMA
|
|
|
761
845
|
{
|
|
762
846
|
cur++;
|
|
763
847
|
if (cur == lenEnd)
|
|
848
|
+
{
|
|
764
849
|
return Backward(out backRes, cur);
|
|
850
|
+
}
|
|
851
|
+
|
|
765
852
|
UInt32 newLen;
|
|
766
853
|
ReadMatchDistances(out newLen, out numDistancePairs);
|
|
767
854
|
if (newLen >= _numFastBytes)
|
|
@@ -781,22 +868,36 @@ namespace SevenZip.Compression.LZMA
|
|
|
781
868
|
{
|
|
782
869
|
state = _optimum[_optimum[cur].PosPrev2].State;
|
|
783
870
|
if (_optimum[cur].BackPrev2 < Base.kNumRepDistances)
|
|
871
|
+
{
|
|
784
872
|
state.UpdateRep();
|
|
873
|
+
}
|
|
785
874
|
else
|
|
875
|
+
{
|
|
786
876
|
state.UpdateMatch();
|
|
877
|
+
}
|
|
787
878
|
}
|
|
788
879
|
else
|
|
880
|
+
{
|
|
789
881
|
state = _optimum[posPrev].State;
|
|
882
|
+
}
|
|
883
|
+
|
|
790
884
|
state.UpdateChar();
|
|
791
885
|
}
|
|
792
886
|
else
|
|
887
|
+
{
|
|
793
888
|
state = _optimum[posPrev].State;
|
|
889
|
+
}
|
|
890
|
+
|
|
794
891
|
if (posPrev == cur - 1)
|
|
795
892
|
{
|
|
796
893
|
if (_optimum[cur].IsShortRep())
|
|
894
|
+
{
|
|
797
895
|
state.UpdateShortRep();
|
|
896
|
+
}
|
|
798
897
|
else
|
|
898
|
+
{
|
|
799
899
|
state.UpdateChar();
|
|
900
|
+
}
|
|
800
901
|
}
|
|
801
902
|
else
|
|
802
903
|
{
|
|
@@ -811,9 +912,13 @@ namespace SevenZip.Compression.LZMA
|
|
|
811
912
|
{
|
|
812
913
|
pos = _optimum[cur].BackPrev;
|
|
813
914
|
if (pos < Base.kNumRepDistances)
|
|
915
|
+
{
|
|
814
916
|
state.UpdateRep();
|
|
917
|
+
}
|
|
815
918
|
else
|
|
919
|
+
{
|
|
816
920
|
state.UpdateMatch();
|
|
921
|
+
}
|
|
817
922
|
}
|
|
818
923
|
Optimal opt = _optimum[posPrev];
|
|
819
924
|
if (pos < Base.kNumRepDistances)
|
|
@@ -910,9 +1015,15 @@ namespace SevenZip.Compression.LZMA
|
|
|
910
1015
|
numAvailableBytes = numAvailableBytesFull;
|
|
911
1016
|
|
|
912
1017
|
if (numAvailableBytes < 2)
|
|
1018
|
+
{
|
|
913
1019
|
continue;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
914
1022
|
if (numAvailableBytes > _numFastBytes)
|
|
1023
|
+
{
|
|
915
1024
|
numAvailableBytes = _numFastBytes;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
916
1027
|
if (!nextIsChar && matchByte != currentByte)
|
|
917
1028
|
{
|
|
918
1029
|
// try Literal + rep0
|
|
@@ -931,7 +1042,10 @@ namespace SevenZip.Compression.LZMA
|
|
|
931
1042
|
{
|
|
932
1043
|
UInt32 offset = cur + 1 + lenTest2;
|
|
933
1044
|
while (lenEnd < offset)
|
|
1045
|
+
{
|
|
934
1046
|
_optimum[++lenEnd].Price = kIfinityPrice;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
935
1049
|
UInt32 curAndLenPrice =
|
|
936
1050
|
nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);
|
|
937
1051
|
Optimal optimum = _optimum[offset];
|
|
@@ -957,12 +1071,18 @@ namespace SevenZip.Compression.LZMA
|
|
|
957
1071
|
numAvailableBytes
|
|
958
1072
|
);
|
|
959
1073
|
if (lenTest < 2)
|
|
1074
|
+
{
|
|
960
1075
|
continue;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
961
1078
|
UInt32 lenTestTemp = lenTest;
|
|
962
1079
|
do
|
|
963
1080
|
{
|
|
964
1081
|
while (lenEnd < cur + lenTest)
|
|
1082
|
+
{
|
|
965
1083
|
_optimum[++lenEnd].Price = kIfinityPrice;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
966
1086
|
UInt32 curAndLenPrice =
|
|
967
1087
|
repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);
|
|
968
1088
|
Optimal optimum = _optimum[cur + lenTest];
|
|
@@ -977,7 +1097,9 @@ namespace SevenZip.Compression.LZMA
|
|
|
977
1097
|
lenTest = lenTestTemp;
|
|
978
1098
|
|
|
979
1099
|
if (repIndex == 0)
|
|
1100
|
+
{
|
|
980
1101
|
startLen = lenTest + 1;
|
|
1102
|
+
}
|
|
981
1103
|
|
|
982
1104
|
// if (_maxMode)
|
|
983
1105
|
if (lenTest < numAvailableBytesFull)
|
|
@@ -1029,7 +1151,10 @@ namespace SevenZip.Compression.LZMA
|
|
|
1029
1151
|
{
|
|
1030
1152
|
UInt32 offset = lenTest + 1 + lenTest2;
|
|
1031
1153
|
while (lenEnd < cur + offset)
|
|
1154
|
+
{
|
|
1032
1155
|
_optimum[++lenEnd].Price = kIfinityPrice;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1033
1158
|
UInt32 curAndLenPrice =
|
|
1034
1159
|
nextRepMatchPrice
|
|
1035
1160
|
+ GetRepPrice(0, lenTest2, state2, posStateNext);
|
|
@@ -1057,7 +1182,10 @@ namespace SevenZip.Compression.LZMA
|
|
|
1057
1182
|
newLen > _matchDistances[numDistancePairs];
|
|
1058
1183
|
numDistancePairs += 2
|
|
1059
1184
|
)
|
|
1185
|
+
{
|
|
1060
1186
|
;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1061
1189
|
_matchDistances[numDistancePairs] = newLen;
|
|
1062
1190
|
numDistancePairs += 2;
|
|
1063
1191
|
}
|
|
@@ -1065,11 +1193,15 @@ namespace SevenZip.Compression.LZMA
|
|
|
1065
1193
|
{
|
|
1066
1194
|
normalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();
|
|
1067
1195
|
while (lenEnd < cur + newLen)
|
|
1196
|
+
{
|
|
1068
1197
|
_optimum[++lenEnd].Price = kIfinityPrice;
|
|
1198
|
+
}
|
|
1069
1199
|
|
|
1070
1200
|
UInt32 offs = 0;
|
|
1071
1201
|
while (startLen > _matchDistances[offs])
|
|
1202
|
+
{
|
|
1072
1203
|
offs += 2;
|
|
1204
|
+
}
|
|
1073
1205
|
|
|
1074
1206
|
for (UInt32 lenTest = startLen; ; lenTest++)
|
|
1075
1207
|
{
|
|
@@ -1136,7 +1268,10 @@ namespace SevenZip.Compression.LZMA
|
|
|
1136
1268
|
|
|
1137
1269
|
UInt32 offset = lenTest + 1 + lenTest2;
|
|
1138
1270
|
while (lenEnd < cur + offset)
|
|
1271
|
+
{
|
|
1139
1272
|
_optimum[++lenEnd].Price = kIfinityPrice;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1140
1275
|
curAndLenPrice =
|
|
1141
1276
|
nextRepMatchPrice
|
|
1142
1277
|
+ GetRepPrice(0, lenTest2, state2, posStateNext);
|
|
@@ -1155,7 +1290,9 @@ namespace SevenZip.Compression.LZMA
|
|
|
1155
1290
|
}
|
|
1156
1291
|
offs += 2;
|
|
1157
1292
|
if (offs == numDistancePairs)
|
|
1293
|
+
{
|
|
1158
1294
|
break;
|
|
1295
|
+
}
|
|
1159
1296
|
}
|
|
1160
1297
|
}
|
|
1161
1298
|
}
|
|
@@ -1171,7 +1308,9 @@ namespace SevenZip.Compression.LZMA
|
|
|
1171
1308
|
void WriteEndMarker(UInt32 posState)
|
|
1172
1309
|
{
|
|
1173
1310
|
if (!_writeEndMark)
|
|
1311
|
+
{
|
|
1174
1312
|
return;
|
|
1313
|
+
}
|
|
1175
1314
|
|
|
1176
1315
|
_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState]
|
|
1177
1316
|
.Encode(_rangeEncoder, 1);
|
|
@@ -1212,11 +1351,16 @@ namespace SevenZip.Compression.LZMA
|
|
|
1212
1351
|
_needReleaseMFStream = true;
|
|
1213
1352
|
_inStream = null;
|
|
1214
1353
|
if (_trainSize > 0)
|
|
1354
|
+
{
|
|
1215
1355
|
_matchFinder.Skip(_trainSize);
|
|
1356
|
+
}
|
|
1216
1357
|
}
|
|
1217
1358
|
|
|
1218
1359
|
if (_finished)
|
|
1360
|
+
{
|
|
1219
1361
|
return;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1220
1364
|
_finished = true;
|
|
1221
1365
|
|
|
1222
1366
|
Int64 progressPosValuePrev = nowPos64;
|
|
@@ -1270,7 +1414,10 @@ namespace SevenZip.Compression.LZMA
|
|
|
1270
1414
|
subCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);
|
|
1271
1415
|
}
|
|
1272
1416
|
else
|
|
1417
|
+
{
|
|
1273
1418
|
subCoder.Encode(_rangeEncoder, curByte);
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1274
1421
|
_previousByte = curByte;
|
|
1275
1422
|
_state.UpdateChar();
|
|
1276
1423
|
}
|
|
@@ -1284,15 +1431,21 @@ namespace SevenZip.Compression.LZMA
|
|
|
1284
1431
|
{
|
|
1285
1432
|
_isRepG0[_state.Index].Encode(_rangeEncoder, 0);
|
|
1286
1433
|
if (len == 1)
|
|
1434
|
+
{
|
|
1287
1435
|
_isRep0Long[complexState].Encode(_rangeEncoder, 0);
|
|
1436
|
+
}
|
|
1288
1437
|
else
|
|
1438
|
+
{
|
|
1289
1439
|
_isRep0Long[complexState].Encode(_rangeEncoder, 1);
|
|
1440
|
+
}
|
|
1290
1441
|
}
|
|
1291
1442
|
else
|
|
1292
1443
|
{
|
|
1293
1444
|
_isRepG0[_state.Index].Encode(_rangeEncoder, 1);
|
|
1294
1445
|
if (pos == 1)
|
|
1446
|
+
{
|
|
1295
1447
|
_isRepG1[_state.Index].Encode(_rangeEncoder, 0);
|
|
1448
|
+
}
|
|
1296
1449
|
else
|
|
1297
1450
|
{
|
|
1298
1451
|
_isRepG1[_state.Index].Encode(_rangeEncoder, 1);
|
|
@@ -1300,7 +1453,9 @@ namespace SevenZip.Compression.LZMA
|
|
|
1300
1453
|
}
|
|
1301
1454
|
}
|
|
1302
1455
|
if (len == 1)
|
|
1456
|
+
{
|
|
1303
1457
|
_state.UpdateShortRep();
|
|
1458
|
+
}
|
|
1304
1459
|
else
|
|
1305
1460
|
{
|
|
1306
1461
|
_repMatchLenEncoder.Encode(
|
|
@@ -1314,7 +1469,10 @@ namespace SevenZip.Compression.LZMA
|
|
|
1314
1469
|
if (pos != 0)
|
|
1315
1470
|
{
|
|
1316
1471
|
for (UInt32 i = pos; i >= 1; i--)
|
|
1472
|
+
{
|
|
1317
1473
|
_repDistances[i] = _repDistances[i - 1];
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1318
1476
|
_repDistances[0] = distance;
|
|
1319
1477
|
}
|
|
1320
1478
|
}
|
|
@@ -1335,6 +1493,7 @@ namespace SevenZip.Compression.LZMA
|
|
|
1335
1493
|
UInt32 posReduced = pos - baseVal;
|
|
1336
1494
|
|
|
1337
1495
|
if (posSlot < Base.kEndPosModelIndex)
|
|
1496
|
+
{
|
|
1338
1497
|
RangeCoder.BitTreeEncoder.ReverseEncode(
|
|
1339
1498
|
_posEncoders,
|
|
1340
1499
|
baseVal - posSlot - 1,
|
|
@@ -1342,6 +1501,7 @@ namespace SevenZip.Compression.LZMA
|
|
|
1342
1501
|
footerBits,
|
|
1343
1502
|
posReduced
|
|
1344
1503
|
);
|
|
1504
|
+
}
|
|
1345
1505
|
else
|
|
1346
1506
|
{
|
|
1347
1507
|
_rangeEncoder.EncodeDirectBits(
|
|
@@ -1357,7 +1517,10 @@ namespace SevenZip.Compression.LZMA
|
|
|
1357
1517
|
}
|
|
1358
1518
|
UInt32 distance = pos;
|
|
1359
1519
|
for (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)
|
|
1520
|
+
{
|
|
1360
1521
|
_repDistances[i] = _repDistances[i - 1];
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1361
1524
|
_repDistances[0] = distance;
|
|
1362
1525
|
_matchPriceCount++;
|
|
1363
1526
|
}
|
|
@@ -1369,9 +1532,15 @@ namespace SevenZip.Compression.LZMA
|
|
|
1369
1532
|
{
|
|
1370
1533
|
// if (!_fastMode)
|
|
1371
1534
|
if (_matchPriceCount >= (1 << 7))
|
|
1535
|
+
{
|
|
1372
1536
|
FillDistancesPrices();
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1373
1539
|
if (_alignPriceCount >= Base.kAlignTableSize)
|
|
1540
|
+
{
|
|
1374
1541
|
FillAlignPrices();
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1375
1544
|
inSize = nowPos64;
|
|
1376
1545
|
outSize = _rangeEncoder.GetProcessedSizeAdd();
|
|
1377
1546
|
if (_matchFinder.GetNumAvailableBytes() == 0)
|
|
@@ -1461,7 +1630,10 @@ namespace SevenZip.Compression.LZMA
|
|
|
1461
1630
|
bool finished;
|
|
1462
1631
|
CodeOneBlock(out processedInSize, out processedOutSize, out finished);
|
|
1463
1632
|
if (finished)
|
|
1633
|
+
{
|
|
1464
1634
|
return;
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1465
1637
|
if (progress != null)
|
|
1466
1638
|
{
|
|
1467
1639
|
progress.SetProgress(processedInSize, processedOutSize);
|
|
@@ -1475,7 +1647,7 @@ namespace SevenZip.Compression.LZMA
|
|
|
1475
1647
|
}
|
|
1476
1648
|
|
|
1477
1649
|
const int kPropSize = 5;
|
|
1478
|
-
Byte[] properties = new Byte[kPropSize];
|
|
1650
|
+
readonly Byte[] properties = new Byte[kPropSize];
|
|
1479
1651
|
|
|
1480
1652
|
public void WriteCoderProperties(System.IO.Stream outStream)
|
|
1481
1653
|
{
|
|
@@ -1483,11 +1655,14 @@ namespace SevenZip.Compression.LZMA
|
|
|
1483
1655
|
(_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits
|
|
1484
1656
|
);
|
|
1485
1657
|
for (int i = 0; i < 4; i++)
|
|
1658
|
+
{
|
|
1486
1659
|
properties[1 + i] = (Byte)((_dictionarySize >> (8 * i)) & 0xFF);
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1487
1662
|
outStream.Write(properties, 0, kPropSize);
|
|
1488
1663
|
}
|
|
1489
1664
|
|
|
1490
|
-
UInt32[] tempPrices = new UInt32[Base.kNumFullDistances];
|
|
1665
|
+
readonly UInt32[] tempPrices = new UInt32[Base.kNumFullDistances];
|
|
1491
1666
|
UInt32 _matchPriceCount;
|
|
1492
1667
|
|
|
1493
1668
|
void FillDistancesPrices()
|
|
@@ -1512,19 +1687,29 @@ namespace SevenZip.Compression.LZMA
|
|
|
1512
1687
|
|
|
1513
1688
|
UInt32 st = (lenToPosState << Base.kNumPosSlotBits);
|
|
1514
1689
|
for (posSlot = 0; posSlot < _distTableSize; posSlot++)
|
|
1690
|
+
{
|
|
1515
1691
|
_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1516
1694
|
for (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)
|
|
1695
|
+
{
|
|
1517
1696
|
_posSlotPrices[st + posSlot] += (
|
|
1518
1697
|
(((posSlot >> 1) - 1) - Base.kNumAlignBits)
|
|
1519
1698
|
<< RangeCoder.BitEncoder.kNumBitPriceShiftBits
|
|
1520
1699
|
);
|
|
1700
|
+
}
|
|
1521
1701
|
|
|
1522
1702
|
UInt32 st2 = lenToPosState * Base.kNumFullDistances;
|
|
1523
1703
|
UInt32 i;
|
|
1524
1704
|
for (i = 0; i < Base.kStartPosModelIndex; i++)
|
|
1705
|
+
{
|
|
1525
1706
|
_distancesPrices[st2 + i] = _posSlotPrices[st + i];
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1526
1709
|
for (; i < Base.kNumFullDistances; i++)
|
|
1710
|
+
{
|
|
1527
1711
|
_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];
|
|
1712
|
+
}
|
|
1528
1713
|
}
|
|
1529
1714
|
_matchPriceCount = 0;
|
|
1530
1715
|
}
|
|
@@ -1532,17 +1717,25 @@ namespace SevenZip.Compression.LZMA
|
|
|
1532
1717
|
void FillAlignPrices()
|
|
1533
1718
|
{
|
|
1534
1719
|
for (UInt32 i = 0; i < Base.kAlignTableSize; i++)
|
|
1720
|
+
{
|
|
1535
1721
|
_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1536
1724
|
_alignPriceCount = 0;
|
|
1537
1725
|
}
|
|
1538
1726
|
|
|
1539
|
-
static string[] kMatchFinderIDs = { "BT2", "BT4" };
|
|
1727
|
+
static readonly string[] kMatchFinderIDs = { "BT2", "BT4" };
|
|
1540
1728
|
|
|
1541
1729
|
static int FindMatchFinder(string s)
|
|
1542
1730
|
{
|
|
1543
1731
|
for (int m = 0; m < kMatchFinderIDs.Length; m++)
|
|
1732
|
+
{
|
|
1544
1733
|
if (s == kMatchFinderIDs[m])
|
|
1734
|
+
{
|
|
1545
1735
|
return m;
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1546
1739
|
return -1;
|
|
1547
1740
|
}
|
|
1548
1741
|
|
|
@@ -1556,10 +1749,16 @@ namespace SevenZip.Compression.LZMA
|
|
|
1556
1749
|
case CoderPropID.NumFastBytes:
|
|
1557
1750
|
{
|
|
1558
1751
|
if (!(prop is Int32))
|
|
1752
|
+
{
|
|
1559
1753
|
throw new InvalidParamException();
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1560
1756
|
Int32 numFastBytes = (Int32)prop;
|
|
1561
1757
|
if (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)
|
|
1758
|
+
{
|
|
1562
1759
|
throw new InvalidParamException();
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1563
1762
|
_numFastBytes = (UInt32)numFastBytes;
|
|
1564
1763
|
break;
|
|
1565
1764
|
}
|
|
@@ -1577,11 +1776,17 @@ namespace SevenZip.Compression.LZMA
|
|
|
1577
1776
|
case CoderPropID.MatchFinder:
|
|
1578
1777
|
{
|
|
1579
1778
|
if (!(prop is String))
|
|
1779
|
+
{
|
|
1580
1780
|
throw new InvalidParamException();
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1581
1783
|
EMatchFinderType matchFinderIndexPrev = _matchFinderType;
|
|
1582
1784
|
int m = FindMatchFinder(((string)prop).ToUpper());
|
|
1583
1785
|
if (m < 0)
|
|
1786
|
+
{
|
|
1584
1787
|
throw new InvalidParamException();
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1585
1790
|
_matchFinderType = (EMatchFinderType)m;
|
|
1586
1791
|
if (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)
|
|
1587
1792
|
{
|
|
@@ -1594,14 +1799,19 @@ namespace SevenZip.Compression.LZMA
|
|
|
1594
1799
|
{
|
|
1595
1800
|
const int kDicLogSizeMaxCompress = 30;
|
|
1596
1801
|
if (!(prop is Int32))
|
|
1802
|
+
{
|
|
1597
1803
|
throw new InvalidParamException();
|
|
1804
|
+
}
|
|
1598
1805
|
;
|
|
1599
1806
|
Int32 dictionarySize = (Int32)prop;
|
|
1600
1807
|
if (
|
|
1601
1808
|
dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin)
|
|
1602
1809
|
|| dictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress)
|
|
1603
1810
|
)
|
|
1811
|
+
{
|
|
1604
1812
|
throw new InvalidParamException();
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1605
1815
|
_dictionarySize = (UInt32)dictionarySize;
|
|
1606
1816
|
int dicLogSize;
|
|
1607
1817
|
for (
|
|
@@ -1609,18 +1819,29 @@ namespace SevenZip.Compression.LZMA
|
|
|
1609
1819
|
dicLogSize < (UInt32)kDicLogSizeMaxCompress;
|
|
1610
1820
|
dicLogSize++
|
|
1611
1821
|
)
|
|
1822
|
+
{
|
|
1612
1823
|
if (dictionarySize <= ((UInt32)(1) << dicLogSize))
|
|
1824
|
+
{
|
|
1613
1825
|
break;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1614
1829
|
_distTableSize = (UInt32)dicLogSize * 2;
|
|
1615
1830
|
break;
|
|
1616
1831
|
}
|
|
1617
1832
|
case CoderPropID.PosStateBits:
|
|
1618
1833
|
{
|
|
1619
1834
|
if (!(prop is Int32))
|
|
1835
|
+
{
|
|
1620
1836
|
throw new InvalidParamException();
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1621
1839
|
Int32 v = (Int32)prop;
|
|
1622
1840
|
if (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)
|
|
1841
|
+
{
|
|
1623
1842
|
throw new InvalidParamException();
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1624
1845
|
_posStateBits = (int)v;
|
|
1625
1846
|
_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;
|
|
1626
1847
|
break;
|
|
@@ -1628,20 +1849,31 @@ namespace SevenZip.Compression.LZMA
|
|
|
1628
1849
|
case CoderPropID.LitPosBits:
|
|
1629
1850
|
{
|
|
1630
1851
|
if (!(prop is Int32))
|
|
1852
|
+
{
|
|
1631
1853
|
throw new InvalidParamException();
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1632
1856
|
Int32 v = (Int32)prop;
|
|
1633
1857
|
if (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)
|
|
1858
|
+
{
|
|
1634
1859
|
throw new InvalidParamException();
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1635
1862
|
_numLiteralPosStateBits = (int)v;
|
|
1636
1863
|
break;
|
|
1637
1864
|
}
|
|
1638
1865
|
case CoderPropID.LitContextBits:
|
|
1639
1866
|
{
|
|
1640
1867
|
if (!(prop is Int32))
|
|
1868
|
+
{
|
|
1641
1869
|
throw new InvalidParamException();
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1642
1872
|
Int32 v = (Int32)prop;
|
|
1643
1873
|
if (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)
|
|
1874
|
+
{
|
|
1644
1875
|
throw new InvalidParamException();
|
|
1876
|
+
}
|
|
1645
1877
|
;
|
|
1646
1878
|
_numLiteralContextBits = (int)v;
|
|
1647
1879
|
break;
|
|
@@ -1649,7 +1881,10 @@ namespace SevenZip.Compression.LZMA
|
|
|
1649
1881
|
case CoderPropID.EndMarker:
|
|
1650
1882
|
{
|
|
1651
1883
|
if (!(prop is Boolean))
|
|
1884
|
+
{
|
|
1652
1885
|
throw new InvalidParamException();
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1653
1888
|
SetWriteEndMarkerMode((Boolean)prop);
|
|
1654
1889
|
break;
|
|
1655
1890
|
}
|