mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-25 00:15:15 +00:00
Resharper code cleanup
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
internal class FreqData : Pointer
|
||||
@@ -18,16 +19,9 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal int SummFreq
|
||||
{
|
||||
get
|
||||
{
|
||||
return Utility.readShortLittleEndian(Memory, Address) & 0xffff;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address, (short)value);
|
||||
}
|
||||
get { return Utility.readShortLittleEndian(Memory, Address) & 0xffff; }
|
||||
|
||||
set { Utility.WriteLittleEndian(Memory, Address, (short) value); }
|
||||
}
|
||||
|
||||
internal FreqData Initialize(byte[] mem)
|
||||
@@ -37,7 +31,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal void IncrementSummFreq(int dSummFreq)
|
||||
{
|
||||
Utility.incShortLittleEndian(Memory, Address, (short)dSummFreq);
|
||||
Utility.incShortLittleEndian(Memory, Address, (short) dSummFreq);
|
||||
}
|
||||
|
||||
internal int GetStats()
|
||||
|
||||
@@ -17,156 +17,94 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
binSumm[i2] = new int[64];
|
||||
}
|
||||
}
|
||||
|
||||
public SubAllocator SubAlloc
|
||||
{
|
||||
get
|
||||
{
|
||||
return subAlloc;
|
||||
}
|
||||
|
||||
get { return subAlloc; }
|
||||
}
|
||||
virtual public SEE2Context DummySEE2Cont
|
||||
|
||||
public virtual SEE2Context DummySEE2Cont
|
||||
{
|
||||
get
|
||||
{
|
||||
return dummySEE2Cont;
|
||||
}
|
||||
|
||||
get { return dummySEE2Cont; }
|
||||
}
|
||||
virtual public int InitRL
|
||||
|
||||
public virtual int InitRL
|
||||
{
|
||||
get
|
||||
{
|
||||
return initRL;
|
||||
}
|
||||
|
||||
get { return initRL; }
|
||||
}
|
||||
virtual public int EscCount
|
||||
|
||||
public virtual int EscCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return escCount;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.escCount = value & 0xff;
|
||||
}
|
||||
get { return escCount; }
|
||||
|
||||
set { this.escCount = value & 0xff; }
|
||||
}
|
||||
virtual public int[] CharMask
|
||||
|
||||
public virtual int[] CharMask
|
||||
{
|
||||
get
|
||||
{
|
||||
return charMask;
|
||||
}
|
||||
|
||||
get { return charMask; }
|
||||
}
|
||||
virtual public int NumMasked
|
||||
|
||||
public virtual int NumMasked
|
||||
{
|
||||
get
|
||||
{
|
||||
return numMasked;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.numMasked = value;
|
||||
}
|
||||
get { return numMasked; }
|
||||
|
||||
set { this.numMasked = value; }
|
||||
}
|
||||
virtual public int PrevSuccess
|
||||
|
||||
public virtual int PrevSuccess
|
||||
{
|
||||
get
|
||||
{
|
||||
return prevSuccess;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.prevSuccess = value & 0xff;
|
||||
}
|
||||
get { return prevSuccess; }
|
||||
|
||||
set { this.prevSuccess = value & 0xff; }
|
||||
}
|
||||
virtual public int InitEsc
|
||||
|
||||
public virtual int InitEsc
|
||||
{
|
||||
get
|
||||
{
|
||||
return initEsc;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.initEsc = value;
|
||||
}
|
||||
get { return initEsc; }
|
||||
|
||||
set { this.initEsc = value; }
|
||||
}
|
||||
virtual public int RunLength
|
||||
|
||||
public virtual int RunLength
|
||||
{
|
||||
get
|
||||
{
|
||||
return runLength;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.runLength = value;
|
||||
}
|
||||
get { return runLength; }
|
||||
|
||||
set { this.runLength = value; }
|
||||
}
|
||||
virtual public int HiBitsFlag
|
||||
|
||||
public virtual int HiBitsFlag
|
||||
{
|
||||
get
|
||||
{
|
||||
return hiBitsFlag;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.hiBitsFlag = value & 0xff;
|
||||
}
|
||||
get { return hiBitsFlag; }
|
||||
|
||||
set { this.hiBitsFlag = value & 0xff; }
|
||||
}
|
||||
virtual public int[][] BinSumm
|
||||
|
||||
public virtual int[][] BinSumm
|
||||
{
|
||||
get
|
||||
{
|
||||
return binSumm;
|
||||
}
|
||||
|
||||
get { return binSumm; }
|
||||
}
|
||||
|
||||
internal RangeCoder Coder
|
||||
{
|
||||
get
|
||||
{
|
||||
return coder;
|
||||
}
|
||||
|
||||
get { return coder; }
|
||||
}
|
||||
|
||||
internal State FoundState
|
||||
{
|
||||
get
|
||||
{
|
||||
return foundState;
|
||||
}
|
||||
|
||||
get { return foundState; }
|
||||
}
|
||||
virtual public byte[] Heap
|
||||
|
||||
public virtual byte[] Heap
|
||||
{
|
||||
get
|
||||
{
|
||||
return subAlloc.Heap;
|
||||
}
|
||||
|
||||
get { return subAlloc.Heap; }
|
||||
}
|
||||
virtual public int OrderFall
|
||||
|
||||
public virtual int OrderFall
|
||||
{
|
||||
get
|
||||
{
|
||||
return orderFall;
|
||||
}
|
||||
|
||||
get { return orderFall; }
|
||||
}
|
||||
|
||||
public const int MAX_O = 64; /* maximum allowed model order */
|
||||
|
||||
public const int INT_BITS = 7;
|
||||
@@ -213,7 +151,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
private SubAllocator subAlloc = new SubAllocator();
|
||||
|
||||
private static int[] InitBinEsc = new int[] { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051 };
|
||||
private static int[] InitBinEsc = new int[] {0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051};
|
||||
|
||||
// Temp fields
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'tempState1 '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
@@ -260,7 +198,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
minContext.NumStats = 256;
|
||||
minContext.FreqData.SummFreq = minContext.NumStats + 1;
|
||||
|
||||
addr = subAlloc.allocUnits(256 / 2);
|
||||
addr = subAlloc.allocUnits(256/2);
|
||||
foundState.Address = addr;
|
||||
minContext.FreqData.SetStats(addr);
|
||||
|
||||
@@ -270,7 +208,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
prevSuccess = 0;
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
state.Address = addr + i * State.Size;
|
||||
state.Address = addr + i*State.Size;
|
||||
state.Symbol = i;
|
||||
state.Freq = 1;
|
||||
state.SetSuccessor(0);
|
||||
@@ -282,7 +220,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
for (int m = 0; m < 64; m += 8)
|
||||
{
|
||||
binSumm[i][k + m] = BIN_SCALE - InitBinEsc[k] / (i + 2);
|
||||
binSumm[i][k + m] = BIN_SCALE - InitBinEsc[k]/(i + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,7 +228,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
for (int k = 0; k < 16; k++)
|
||||
{
|
||||
SEE2Cont[i][k].Initialize(5 * i + 10);
|
||||
SEE2Cont[i][k].Initialize(5*i + 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -344,7 +282,6 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal bool decodeInit(Unpack unpackRead, int escChar)
|
||||
{
|
||||
|
||||
int MaxOrder = unpackRead.Char & 0xff;
|
||||
bool reset = ((MaxOrder & 0x20) != 0);
|
||||
|
||||
@@ -371,7 +308,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
MaxOrder = (MaxOrder & 0x1f) + 1;
|
||||
if (MaxOrder > 16)
|
||||
{
|
||||
MaxOrder = 16 + (MaxOrder - 16) * 3;
|
||||
MaxOrder = 16 + (MaxOrder - 16)*3;
|
||||
}
|
||||
if (MaxOrder == 1)
|
||||
{
|
||||
@@ -408,7 +345,8 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
if (minContext.NumStats != 1)
|
||||
{
|
||||
if (minContext.FreqData.GetStats() <= subAlloc.PText || minContext.FreqData.GetStats() > subAlloc.HeapEnd)
|
||||
if (minContext.FreqData.GetStats() <= subAlloc.PText ||
|
||||
minContext.FreqData.GetStats() > subAlloc.HeapEnd)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
@@ -433,8 +371,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
while (minContext.NumStats == numMasked);
|
||||
} while (minContext.NumStats == numMasked);
|
||||
if (!minContext.decodeSymbol2(this))
|
||||
{
|
||||
return (-1);
|
||||
@@ -540,8 +477,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
do
|
||||
{
|
||||
p.IncrementAddress();
|
||||
}
|
||||
while (p.Symbol != foundState.Symbol);
|
||||
} while (p.Symbol != foundState.Symbol);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -556,8 +492,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
break;
|
||||
}
|
||||
ps[pps++] = p.Address;
|
||||
}
|
||||
while (pc.getSuffix() != 0);
|
||||
} while (pc.getSuffix() != 0);
|
||||
} // NO_LOOP:
|
||||
if (pps == 0)
|
||||
{
|
||||
@@ -579,13 +514,12 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
do
|
||||
{
|
||||
p.IncrementAddress();
|
||||
}
|
||||
while (p.Symbol != upState.Symbol);
|
||||
} while (p.Symbol != upState.Symbol);
|
||||
}
|
||||
int cf = p.Freq - 1;
|
||||
int s0 = pc.FreqData.SummFreq - pc.NumStats - cf;
|
||||
// UpState.Freq=1+((2*cf <= s0)?(5*cf > s0):((2*cf+3*s0-1)/(2*s0)));
|
||||
upState.Freq = 1 + ((2 * cf <= s0) ? (5 * cf > s0 ? 1 : 0) : ((2 * cf + 3 * s0 - 1) / (2 * s0)));
|
||||
upState.Freq = 1 + ((2*cf <= s0) ? (5*cf > s0 ? 1 : 0) : ((2*cf + 3*s0 - 1)/(2*s0)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -600,8 +534,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
while (pps != 0);
|
||||
} while (pps != 0);
|
||||
return pc.Address;
|
||||
}
|
||||
|
||||
@@ -625,7 +558,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
int ns1, ns, cf, sf, s0;
|
||||
pc.Address = minContext.getSuffix();
|
||||
if (fs.Freq < MAX_FREQ / 4 && pc.Address != 0)
|
||||
if (fs.Freq < MAX_FREQ/4 && pc.Address != 0)
|
||||
{
|
||||
if (pc.NumStats != 1)
|
||||
{
|
||||
@@ -635,8 +568,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
do
|
||||
{
|
||||
p.IncrementAddress();
|
||||
}
|
||||
while (p.Symbol != fs.Symbol);
|
||||
} while (p.Symbol != fs.Symbol);
|
||||
tempState.Address = p.Address - State.Size;
|
||||
if (p.Freq >= tempState.Freq)
|
||||
{
|
||||
@@ -671,7 +603,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
}
|
||||
return;
|
||||
}
|
||||
subAlloc.Heap[subAlloc.PText] = (byte)fs.Symbol;
|
||||
subAlloc.Heap[subAlloc.PText] = (byte) fs.Symbol;
|
||||
subAlloc.incPText();
|
||||
successor.Address = subAlloc.PText;
|
||||
if (subAlloc.PText >= subAlloc.FakeUnitsStart)
|
||||
@@ -728,7 +660,8 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
// int sum = ((2 * ns1 < ns) ? 1 : 0) +
|
||||
// 2 * ((4 * ((ns1 <= ns) ? 1 : 0)) & ((pc.getFreqData()
|
||||
// .getSummFreq() <= 8 * ns1) ? 1 : 0));
|
||||
int sum = ((2 * ns1 < ns) ? 1 : 0) + 2 * (((4 * ns1 <= ns) ? 1 : 0) & ((pc.FreqData.SummFreq <= 8 * ns1) ? 1 : 0));
|
||||
int sum = ((2*ns1 < ns) ? 1 : 0) +
|
||||
2*(((4*ns1 <= ns) ? 1 : 0) & ((pc.FreqData.SummFreq <= 8*ns1) ? 1 : 0));
|
||||
pc.FreqData.IncrementSummFreq(sum);
|
||||
}
|
||||
else
|
||||
@@ -741,7 +674,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
}
|
||||
p.SetValues(pc.getOneState());
|
||||
pc.FreqData.SetStats(p);
|
||||
if (p.Freq < MAX_FREQ / 4 - 1)
|
||||
if (p.Freq < MAX_FREQ/4 - 1)
|
||||
{
|
||||
p.IncrementFreq(p.Freq);
|
||||
}
|
||||
@@ -751,19 +684,19 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
}
|
||||
pc.FreqData.SummFreq = (p.Freq + initEsc + (ns > 3 ? 1 : 0));
|
||||
}
|
||||
cf = 2 * fs.Freq * (pc.FreqData.SummFreq + 6);
|
||||
cf = 2*fs.Freq*(pc.FreqData.SummFreq + 6);
|
||||
sf = s0 + pc.FreqData.SummFreq;
|
||||
if (cf < 6 * sf)
|
||||
if (cf < 6*sf)
|
||||
{
|
||||
cf = 1 + (cf > sf ? 1 : 0) + (cf >= 4 * sf ? 1 : 0);
|
||||
cf = 1 + (cf > sf ? 1 : 0) + (cf >= 4*sf ? 1 : 0);
|
||||
pc.FreqData.IncrementSummFreq(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
cf = 4 + (cf >= 9 * sf ? 1 : 0) + (cf >= 12 * sf ? 1 : 0) + (cf >= 15 * sf ? 1 : 0);
|
||||
cf = 4 + (cf >= 9*sf ? 1 : 0) + (cf >= 12*sf ? 1 : 0) + (cf >= 15*sf ? 1 : 0);
|
||||
pc.FreqData.IncrementSummFreq(cf);
|
||||
}
|
||||
p.Address = pc.FreqData.GetStats() + ns1 * State.Size;
|
||||
p.Address = pc.FreqData.GetStats() + ns1*State.Size;
|
||||
p.SetSuccessor(successor);
|
||||
p.Symbol = fs.Symbol;
|
||||
p.Freq = cf;
|
||||
@@ -867,11 +800,11 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
s.Address = minContext.FreqData.GetStats();
|
||||
int i;
|
||||
int count, hiCnt;
|
||||
if ((count = (int)decoder.GetThreshold((uint)minContext.FreqData.SummFreq)) < (hiCnt = s.Freq))
|
||||
if ((count = (int) decoder.GetThreshold((uint) minContext.FreqData.SummFreq)) < (hiCnt = s.Freq))
|
||||
{
|
||||
byte symbol;
|
||||
decoder.Decode(0, (uint)s.Freq);
|
||||
symbol = (byte)s.Symbol;
|
||||
decoder.Decode(0, (uint) s.Freq);
|
||||
symbol = (byte) s.Symbol;
|
||||
minContext.update1_0(this, s.Address);
|
||||
nextContext();
|
||||
return symbol;
|
||||
@@ -884,18 +817,17 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
if ((hiCnt += s.Freq) > count)
|
||||
{
|
||||
byte symbol;
|
||||
decoder.Decode((uint)(hiCnt - s.Freq), (uint)s.Freq);
|
||||
symbol = (byte)s.Symbol;
|
||||
decoder.Decode((uint) (hiCnt - s.Freq), (uint) s.Freq);
|
||||
symbol = (byte) s.Symbol;
|
||||
minContext.update1(this, s.Address);
|
||||
nextContext();
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
while (--i > 0);
|
||||
} while (--i > 0);
|
||||
if (count >= minContext.FreqData.SummFreq)
|
||||
return -2;
|
||||
hiBitsFlag = HB2Flag[foundState.Symbol];
|
||||
decoder.Decode((uint)hiCnt, (uint)(minContext.FreqData.SummFreq - hiCnt));
|
||||
decoder.Decode((uint) hiCnt, (uint) (minContext.FreqData.SummFreq - hiCnt));
|
||||
for (i = 0; i < 256; i++)
|
||||
charMask[i] = -1;
|
||||
charMask[s.Symbol] = 0;
|
||||
@@ -904,8 +836,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
s.DecrementAddress();
|
||||
charMask[s.Symbol] = 0;
|
||||
}
|
||||
while (--i > 0);
|
||||
} while (--i > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -915,12 +846,12 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
int off1 = rs.Freq - 1;
|
||||
int off2 = minContext.getArrayIndex(this, rs);
|
||||
int bs = binSumm[off1][off2];
|
||||
if (decoder.DecodeBit((uint)bs, 14) == 0)
|
||||
if (decoder.DecodeBit((uint) bs, 14) == 0)
|
||||
{
|
||||
byte symbol;
|
||||
binSumm[off1][off2] = (bs + INTERVAL - minContext.getMean(bs, PERIOD_BITS, 2)) & 0xFFFF;
|
||||
foundState.Address = rs.Address;
|
||||
symbol = (byte)rs.Symbol;
|
||||
symbol = (byte) rs.Symbol;
|
||||
rs.IncrementFreq((rs.Freq < 128) ? 1 : 0);
|
||||
prevSuccess = 1;
|
||||
incRunLength(1);
|
||||
@@ -949,8 +880,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
minContext.Address = minContext.getSuffix();
|
||||
if (minContext.Address <= subAlloc.PText || minContext.Address > subAlloc.HeapEnd)
|
||||
return -1;
|
||||
}
|
||||
while (minContext.NumStats == numMasked);
|
||||
} while (minContext.NumStats == numMasked);
|
||||
hiCnt = 0;
|
||||
s.Address = minContext.FreqData.GetStats();
|
||||
i = 0;
|
||||
@@ -962,36 +892,36 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
minContext.ps[i] = s.Address;
|
||||
s.IncrementAddress();
|
||||
i -= k;
|
||||
}
|
||||
while (i != num);
|
||||
} while (i != num);
|
||||
|
||||
see = minContext.makeEscFreq(this, numMasked, out freqSum);
|
||||
freqSum += hiCnt;
|
||||
count = (int)decoder.GetThreshold((uint)freqSum);
|
||||
count = (int) decoder.GetThreshold((uint) freqSum);
|
||||
|
||||
if (count < hiCnt)
|
||||
{
|
||||
byte symbol;
|
||||
State ps = tempState2.Initialize(Heap);
|
||||
for (hiCnt = 0, i = 0, ps.Address = minContext.ps[i]; (hiCnt += ps.Freq) <= count; i++, ps.Address = minContext.ps[i]);
|
||||
for (hiCnt = 0, i = 0, ps.Address = minContext.ps[i];
|
||||
(hiCnt += ps.Freq) <= count;
|
||||
i++, ps.Address = minContext.ps[i]) ;
|
||||
s.Address = ps.Address;
|
||||
decoder.Decode((uint)(hiCnt - s.Freq), (uint)s.Freq);
|
||||
decoder.Decode((uint) (hiCnt - s.Freq), (uint) s.Freq);
|
||||
see.update();
|
||||
symbol = (byte)s.Symbol;
|
||||
symbol = (byte) s.Symbol;
|
||||
minContext.update2(this, s.Address);
|
||||
updateModel();
|
||||
return symbol;
|
||||
}
|
||||
if (count >= freqSum)
|
||||
return -2;
|
||||
decoder.Decode((uint)hiCnt, (uint)(freqSum - hiCnt));
|
||||
decoder.Decode((uint) hiCnt, (uint) (freqSum - hiCnt));
|
||||
see.Summ = see.Summ + freqSum;
|
||||
do
|
||||
{
|
||||
s.Address = minContext.ps[--i];
|
||||
charMask[s.Symbol] = 0;
|
||||
}
|
||||
while (i != 0);
|
||||
} while (i != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
using System.Text;
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
internal class PPMContext : Pointer
|
||||
{
|
||||
internal FreqData FreqData
|
||||
{
|
||||
get
|
||||
{
|
||||
return freqData;
|
||||
}
|
||||
get { return freqData; }
|
||||
|
||||
set
|
||||
{
|
||||
this.freqData.SummFreq = value.SummFreq;
|
||||
this.freqData.SetStats(value.GetStats());
|
||||
}
|
||||
|
||||
}
|
||||
virtual public int NumStats
|
||||
|
||||
public virtual int NumStats
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -33,10 +31,9 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
this.numStats = value & 0xffff;
|
||||
if (Memory != null)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address, (short)value);
|
||||
Utility.WriteLittleEndian(Memory, Address, (short) value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'unionSize '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
@@ -61,7 +58,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
private int suffix; // pointer ppmcontext
|
||||
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'ExpEscape'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
public static readonly int[] ExpEscape = new int[] { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 };
|
||||
public static readonly int[] ExpEscape = new int[] {25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2};
|
||||
|
||||
// Temp fields
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'tempState1 '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
@@ -127,10 +124,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal override int Address
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Address;
|
||||
}
|
||||
get { return base.Address; }
|
||||
set
|
||||
{
|
||||
base.Address = value;
|
||||
@@ -203,20 +197,17 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
p1.SetValues(temp2);
|
||||
p1.DecrementAddress();
|
||||
temp3.Address = p1.Address - State.Size;
|
||||
}
|
||||
while (p1.Address != freqData.GetStats() && tmp.Freq > temp3.Freq);
|
||||
} while (p1.Address != freqData.GetStats() && tmp.Freq > temp3.Freq);
|
||||
p1.SetValues(tmp);
|
||||
}
|
||||
}
|
||||
while (--i != 0);
|
||||
} while (--i != 0);
|
||||
if (p.Freq == 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
i++;
|
||||
p.DecrementAddress();
|
||||
}
|
||||
while (p.Freq == 0);
|
||||
} while (p.Freq == 0);
|
||||
EscFreq += i;
|
||||
NumStats = NumStats - i;
|
||||
if (NumStats == 1)
|
||||
@@ -230,8 +221,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
// tmp.Freq-=(tmp.Freq >> 1)
|
||||
tmp.DecrementFreq(Utility.URShift(tmp.Freq, 1));
|
||||
EscFreq = Utility.URShift(EscFreq, 1);
|
||||
}
|
||||
while (EscFreq > 1);
|
||||
} while (EscFreq > 1);
|
||||
model.SubAlloc.freeUnits(freqData.GetStats(), Utility.URShift((OldNS + 1), 1));
|
||||
oneState.SetValues(tmp);
|
||||
model.FoundState.Address = oneState.Address;
|
||||
@@ -255,7 +245,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
int ret = 0;
|
||||
ret += Model.PrevSuccess;
|
||||
ret += Model.getNS2BSIndx()[tempSuffix.NumStats - 1];
|
||||
ret += Model.HiBitsFlag + 2 * Model.getHB2Flag()[rs.Symbol];
|
||||
ret += Model.HiBitsFlag + 2*Model.getHB2Flag()[rs.Symbol];
|
||||
ret += ((Utility.URShift(Model.RunLength, 26)) & 0x20);
|
||||
return ret;
|
||||
}
|
||||
@@ -335,7 +325,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
internal void update1_0(ModelPPM model, int p)
|
||||
{
|
||||
model.FoundState.Address = p;
|
||||
model.PrevSuccess = 2 * model.FoundState.Freq > freqData.SummFreq ? 1 : 0;
|
||||
model.PrevSuccess = 2*model.FoundState.Freq > freqData.SummFreq ? 1 : 0;
|
||||
model.incRunLength(model.PrevSuccess);
|
||||
freqData.IncrementSummFreq(4);
|
||||
model.FoundState.IncrementFreq(4);
|
||||
@@ -361,12 +351,10 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
do
|
||||
{
|
||||
p.IncrementAddress(); // p++;
|
||||
}
|
||||
while (model.CharMask[p.Symbol] == model.EscCount);
|
||||
} while (model.CharMask[p.Symbol] == model.EscCount);
|
||||
hiCnt += p.Freq;
|
||||
ps[pps++] = p.Address;
|
||||
}
|
||||
while (--i != 0);
|
||||
} while (--i != 0);
|
||||
coder.SubRange.incScale(hiCnt);
|
||||
count = coder.CurrentCount;
|
||||
if (count >= coder.SubRange.Scale)
|
||||
@@ -397,9 +385,8 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
temp.Address = ps[++pps]; // (*++pps)
|
||||
model.CharMask[temp.Symbol] = model.EscCount;
|
||||
}
|
||||
while (--i != 0);
|
||||
psee2c.incSumm((int)coder.SubRange.Scale);
|
||||
} while (--i != 0);
|
||||
psee2c.incSumm((int) coder.SubRange.Scale);
|
||||
model.NumMasked = NumStats;
|
||||
}
|
||||
return (true);
|
||||
@@ -431,8 +418,8 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
int idx1 = model.getNS2Indx()[Diff - 1];
|
||||
int idx2 = 0;
|
||||
idx2 += ((Diff < suff.NumStats - numStats) ? 1 : 0);
|
||||
idx2 += 2 * ((freqData.SummFreq < 11 * numStats) ? 1 : 0);
|
||||
idx2 += 4 * ((model.NumMasked > Diff) ? 1 : 0);
|
||||
idx2 += 2*((freqData.SummFreq < 11*numStats) ? 1 : 0);
|
||||
idx2 += 4*((model.NumMasked > Diff) ? 1 : 0);
|
||||
idx2 += model.HiBitsFlag;
|
||||
psee2c = model.getSEE2Cont()[idx1][idx2];
|
||||
model.Coder.SubRange.Scale = psee2c.Mean;
|
||||
@@ -457,8 +444,8 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
int idx1 = model.getNS2Indx()[nonMasked - 1];
|
||||
int idx2 = 0;
|
||||
idx2 += ((nonMasked < suff.NumStats - numStats) ? 1 : 0);
|
||||
idx2 += 2 * ((freqData.SummFreq < 11 * numStats) ? 1 : 0);
|
||||
idx2 += 4 * ((numMasked > nonMasked) ? 1 : 0);
|
||||
idx2 += 2*((freqData.SummFreq < 11*numStats) ? 1 : 0);
|
||||
idx2 += 4*((numMasked > nonMasked) ? 1 : 0);
|
||||
idx2 += model.HiBitsFlag;
|
||||
psee2c = model.getSEE2Cont()[idx1][idx2];
|
||||
escFreq = psee2c.Mean;
|
||||
@@ -473,7 +460,6 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal bool decodeSymbol1(ModelPPM model)
|
||||
{
|
||||
|
||||
RangeCoder coder = model.Coder;
|
||||
coder.SubRange.Scale = freqData.SummFreq;
|
||||
State p = new State(model.Heap);
|
||||
@@ -487,7 +473,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
if (count < (HiCnt = p.Freq))
|
||||
{
|
||||
coder.SubRange.HighCount = HiCnt;
|
||||
model.PrevSuccess = (2 * HiCnt > coder.SubRange.Scale) ? 1 : 0;
|
||||
model.PrevSuccess = (2*HiCnt > coder.SubRange.Scale) ? 1 : 0;
|
||||
model.incRunLength(model.PrevSuccess);
|
||||
HiCnt += 4;
|
||||
model.FoundState.Address = p.Address;
|
||||
@@ -523,8 +509,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
do
|
||||
{
|
||||
model.CharMask[p.DecrementAddress().Symbol] = model.EscCount;
|
||||
}
|
||||
while (--i != 0);
|
||||
} while (--i != 0);
|
||||
coder.SubRange.HighCount = coder.SubRange.Scale;
|
||||
return (true);
|
||||
}
|
||||
@@ -554,6 +539,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
buffer.Append("\n]");
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
static PPMContext()
|
||||
{
|
||||
unionSize = System.Math.Max(FreqData.Size, State.Size);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
internal abstract class Pointer
|
||||
@@ -11,17 +10,9 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
Memory = mem;
|
||||
}
|
||||
|
||||
internal byte[] Memory
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal byte[] Memory { get; private set; }
|
||||
|
||||
internal virtual int Address
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
internal virtual int Address { get; set; }
|
||||
|
||||
protected T Initialize<T>(byte[] mem)
|
||||
where T : Pointer
|
||||
|
||||
@@ -43,10 +43,9 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
get
|
||||
{
|
||||
range = (range / SubRange.Scale) & UintMask;
|
||||
return (int)((code - low) / (range));
|
||||
range = (range/SubRange.Scale) & UintMask;
|
||||
return (int) ((code - low)/(range));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private long Char
|
||||
@@ -59,26 +58,21 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
return stream.ReadByte();
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal SubRange SubRange
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal SubRange SubRange { get; private set; }
|
||||
|
||||
|
||||
internal long GetCurrentShiftCount(int SHIFT)
|
||||
{
|
||||
range = Utility.URShift(range, SHIFT);
|
||||
return ((code - low) / (range)) & UintMask;
|
||||
return ((code - low)/(range)) & UintMask;
|
||||
}
|
||||
|
||||
internal void Decode()
|
||||
{
|
||||
low = (low + (range * SubRange.LowCount)) & UintMask;
|
||||
range = (range * (SubRange.HighCount - SubRange.LowCount)) & UintMask;
|
||||
low = (low + (range*SubRange.LowCount)) & UintMask;
|
||||
range = (range*(SubRange.HighCount - SubRange.LowCount)) & UintMask;
|
||||
}
|
||||
|
||||
internal void AriDecNormalize()
|
||||
@@ -135,44 +129,23 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal long HighCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return highCount;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.highCount = value & RangeCoder.UintMask;
|
||||
}
|
||||
get { return highCount; }
|
||||
|
||||
set { this.highCount = value & RangeCoder.UintMask; }
|
||||
}
|
||||
|
||||
internal long LowCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return lowCount & RangeCoder.UintMask;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.lowCount = value & RangeCoder.UintMask;
|
||||
}
|
||||
get { return lowCount & RangeCoder.UintMask; }
|
||||
|
||||
set { this.lowCount = value & RangeCoder.UintMask; }
|
||||
}
|
||||
|
||||
internal long Scale
|
||||
{
|
||||
get
|
||||
{
|
||||
return scale;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.scale = value & RangeCoder.UintMask;
|
||||
}
|
||||
get { return scale; }
|
||||
|
||||
set { this.scale = value & RangeCoder.UintMask; }
|
||||
}
|
||||
|
||||
// Debug
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
internal class RarMemBlock : Pointer
|
||||
@@ -30,10 +29,9 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
this.stamp = value;
|
||||
if (Memory != null)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address, (short)value);
|
||||
Utility.WriteLittleEndian(Memory, Address, (short) value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal void InsertAt(RarMemBlock p)
|
||||
@@ -95,7 +93,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
NU = nu & 0xffff;
|
||||
if (Memory != null)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address + 2, (short)nu);
|
||||
Utility.WriteLittleEndian(Memory, Address + 2, (short) nu);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System.Text;
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
internal class SEE2Context
|
||||
{
|
||||
virtual public int Mean
|
||||
public virtual int Mean
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -11,47 +12,29 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
summ -= retVal;
|
||||
return retVal + ((retVal == 0) ? 1 : 0);
|
||||
}
|
||||
|
||||
}
|
||||
virtual public int Count
|
||||
|
||||
public virtual int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.count = value & 0xff;
|
||||
}
|
||||
get { return count; }
|
||||
|
||||
set { this.count = value & 0xff; }
|
||||
}
|
||||
virtual public int Shift
|
||||
|
||||
public virtual int Shift
|
||||
{
|
||||
get
|
||||
{
|
||||
return shift;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.shift = value & 0xff;
|
||||
}
|
||||
get { return shift; }
|
||||
|
||||
set { this.shift = value & 0xff; }
|
||||
}
|
||||
virtual public int Summ
|
||||
|
||||
public virtual int Summ
|
||||
{
|
||||
get
|
||||
{
|
||||
return summ;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.summ = value & 0xffff;
|
||||
}
|
||||
get { return summ; }
|
||||
|
||||
set { this.summ = value & 0xffff; }
|
||||
}
|
||||
|
||||
public const int size = 4;
|
||||
|
||||
// ushort Summ;
|
||||
|
||||
@@ -14,29 +14,16 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal int Symbol
|
||||
{
|
||||
get
|
||||
{
|
||||
return Memory[Address] & 0xff;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Memory[Address] = (byte)value;
|
||||
}
|
||||
get { return Memory[Address] & 0xff; }
|
||||
|
||||
set { Memory[Address] = (byte) value; }
|
||||
}
|
||||
|
||||
internal int Freq
|
||||
{
|
||||
get
|
||||
{
|
||||
return Memory[Address + 1] & 0xff;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Memory[Address + 1] = (byte)value;
|
||||
}
|
||||
get { return Memory[Address + 1] & 0xff; }
|
||||
|
||||
set { Memory[Address + 1] = (byte) value; }
|
||||
}
|
||||
|
||||
internal State Initialize(byte[] mem)
|
||||
@@ -46,7 +33,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal void IncrementFreq(int dFreq)
|
||||
{
|
||||
Memory[Address + 1] = (byte)(Memory[Address + 1] + dFreq);
|
||||
Memory[Address + 1] = (byte) (Memory[Address + 1] + dFreq);
|
||||
}
|
||||
|
||||
internal int GetSuccessor()
|
||||
|
||||
@@ -12,29 +12,16 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal int Symbol
|
||||
{
|
||||
get
|
||||
{
|
||||
return symbol;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.symbol = value & 0xff;
|
||||
}
|
||||
get { return symbol; }
|
||||
|
||||
set { this.symbol = value & 0xff; }
|
||||
}
|
||||
|
||||
internal int Freq
|
||||
{
|
||||
get
|
||||
{
|
||||
return freq;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.freq = value & 0xff;
|
||||
}
|
||||
get { return freq; }
|
||||
|
||||
set { this.freq = value & 0xff; }
|
||||
}
|
||||
|
||||
internal State Values
|
||||
|
||||
@@ -1,69 +1,46 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
internal class SubAllocator
|
||||
{
|
||||
virtual public int FakeUnitsStart
|
||||
public virtual int FakeUnitsStart
|
||||
{
|
||||
get
|
||||
{
|
||||
return fakeUnitsStart;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.fakeUnitsStart = value;
|
||||
}
|
||||
get { return fakeUnitsStart; }
|
||||
|
||||
set { this.fakeUnitsStart = value; }
|
||||
}
|
||||
virtual public int HeapEnd
|
||||
|
||||
public virtual int HeapEnd
|
||||
{
|
||||
get
|
||||
{
|
||||
return heapEnd;
|
||||
}
|
||||
|
||||
get { return heapEnd; }
|
||||
}
|
||||
virtual public int PText
|
||||
|
||||
public virtual int PText
|
||||
{
|
||||
get
|
||||
{
|
||||
return pText;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
pText = value;
|
||||
}
|
||||
get { return pText; }
|
||||
|
||||
set { pText = value; }
|
||||
}
|
||||
virtual public int UnitsStart
|
||||
|
||||
public virtual int UnitsStart
|
||||
{
|
||||
get
|
||||
{
|
||||
return unitsStart;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.unitsStart = value;
|
||||
}
|
||||
get { return unitsStart; }
|
||||
|
||||
set { this.unitsStart = value; }
|
||||
}
|
||||
virtual public byte[] Heap
|
||||
|
||||
public virtual byte[] Heap
|
||||
{
|
||||
get
|
||||
{
|
||||
return heap;
|
||||
}
|
||||
|
||||
get { return heap; }
|
||||
}
|
||||
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'N4 '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
public const int N1 = 4;
|
||||
public const int N2 = 4;
|
||||
public const int N3 = 4;
|
||||
public static readonly int N4 = (128 + 3 - 1 * N1 - 2 * N2 - 3 * N3) / 4;
|
||||
public static readonly int N4 = (128 + 3 - 1*N1 - 2*N2 - 3*N3)/4;
|
||||
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'N_INDEXES '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
public static readonly int N_INDEXES = N1 + N2 + N3 + N4;
|
||||
@@ -136,10 +113,11 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
private int U2B(int NU)
|
||||
{
|
||||
return UNIT_SIZE * NU;
|
||||
return UNIT_SIZE*NU;
|
||||
}
|
||||
|
||||
/* memblockptr */
|
||||
|
||||
private int MBPtr(int BasePtr, int Items)
|
||||
{
|
||||
return (BasePtr + U2B(Items));
|
||||
@@ -189,11 +167,11 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
return true;
|
||||
}
|
||||
stopSubAllocator();
|
||||
int allocSize = t / FIXED_UNIT_SIZE * UNIT_SIZE + UNIT_SIZE;
|
||||
int allocSize = t/FIXED_UNIT_SIZE*UNIT_SIZE + UNIT_SIZE;
|
||||
|
||||
// adding space for freelist (needed for poiters)
|
||||
// 1+ for null pointer
|
||||
int realAllocSize = 1 + allocSize + 4 * N_INDEXES;
|
||||
int realAllocSize = 1 + allocSize + 4*N_INDEXES;
|
||||
// adding space for an additional memblock
|
||||
tempMemBlockPos = realAllocSize;
|
||||
realAllocSize += RarMemBlock.size;
|
||||
@@ -295,7 +273,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
glueCount--;
|
||||
i = U2B(indx2Units[indx]);
|
||||
int j = FIXED_UNIT_SIZE * indx2Units[indx];
|
||||
int j = FIXED_UNIT_SIZE*indx2Units[indx];
|
||||
if (fakeUnitsStart - pText > j)
|
||||
{
|
||||
fakeUnitsStart -= j;
|
||||
@@ -304,8 +282,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
while (freeList[i].GetNext() == 0);
|
||||
} while (freeList[i].GetNext() == 0);
|
||||
int retVal = removeNode(i);
|
||||
splitBlock(retVal, i, indx);
|
||||
return retVal;
|
||||
@@ -398,14 +375,14 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
public virtual void initSubAllocator()
|
||||
{
|
||||
int i, k;
|
||||
Utility.Fill(heap, freeListPos, freeListPos + sizeOfFreeList(), (byte)0);
|
||||
Utility.Fill(heap, freeListPos, freeListPos + sizeOfFreeList(), (byte) 0);
|
||||
|
||||
pText = heapStart;
|
||||
|
||||
int size2 = FIXED_UNIT_SIZE * (subAllocatorSize / 8 / FIXED_UNIT_SIZE * 7);
|
||||
int realSize2 = size2 / FIXED_UNIT_SIZE * UNIT_SIZE;
|
||||
int size2 = FIXED_UNIT_SIZE*(subAllocatorSize/8/FIXED_UNIT_SIZE*7);
|
||||
int realSize2 = size2/FIXED_UNIT_SIZE*UNIT_SIZE;
|
||||
int size1 = subAllocatorSize - size2;
|
||||
int realSize1 = size1 / FIXED_UNIT_SIZE * UNIT_SIZE + size1 % FIXED_UNIT_SIZE;
|
||||
int realSize1 = size1/FIXED_UNIT_SIZE*UNIT_SIZE + size1%FIXED_UNIT_SIZE;
|
||||
hiUnit = heapStart + subAllocatorSize;
|
||||
loUnit = unitsStart = heapStart + realSize1;
|
||||
fakeUnitsStart = heapStart + size1;
|
||||
@@ -437,7 +414,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
private int sizeOfFreeList()
|
||||
{
|
||||
return freeList.Length * RarNode.size;
|
||||
return freeList.Length*RarNode.size;
|
||||
}
|
||||
|
||||
// Debug
|
||||
@@ -480,6 +457,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
buffer.Append("\n]");
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
static SubAllocator()
|
||||
{
|
||||
UNIT_SIZE = System.Math.Max(PPMContext.size, RarMemBlock.size);
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
#region Using
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
|
||||
/// Allocate a single, large array and then provide sections of this array to callers. Callers are provided with
|
||||
/// instances of <see cref="Pointer"/> (which simply contain a single address value, representing a location
|
||||
/// in the large array). Callers can then cast <see cref="Pointer"/> to one of the following structures (all
|
||||
@@ -14,13 +11,16 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
internal class Allocator
|
||||
{
|
||||
private const uint UnitSize = 12;
|
||||
private const uint LocalOffset = 4; // reserve the first four bytes for Pointer.Zero
|
||||
private const uint NodeOffset = LocalOffset + MemoryNode.Size; // reserve space for a single memory node
|
||||
private const uint HeapOffset = NodeOffset + IndexCount * MemoryNode.Size; // reserve space for the array of memory nodes
|
||||
private const uint LocalOffset = 4; // reserve the first four bytes for Pointer.Zero
|
||||
private const uint NodeOffset = LocalOffset + MemoryNode.Size; // reserve space for a single memory node
|
||||
|
||||
private const uint HeapOffset = NodeOffset + IndexCount*MemoryNode.Size;
|
||||
// reserve space for the array of memory nodes
|
||||
|
||||
private const uint N1 = 4;
|
||||
private const uint N2 = 4;
|
||||
private const uint N3 = 4;
|
||||
private const uint N4 = (128 + 3 - 1 * N1 - 2 * N2 - 3 * N3) / 4;
|
||||
private const uint N4 = (128 + 3 - 1*N1 - 2*N2 - 3*N3)/4;
|
||||
private const uint IndexCount = N1 + N2 + N3 + N4;
|
||||
|
||||
private static readonly byte[] indexToUnits;
|
||||
@@ -53,16 +53,16 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
indexToUnits = new byte[IndexCount];
|
||||
|
||||
for (index = 0, unitCount = 1; index < N1; index++, unitCount += 1)
|
||||
indexToUnits[index] = (byte)unitCount;
|
||||
indexToUnits[index] = (byte) unitCount;
|
||||
|
||||
for (unitCount++; index < N1 + N2; index++, unitCount += 2)
|
||||
indexToUnits[index] = (byte)unitCount;
|
||||
indexToUnits[index] = (byte) unitCount;
|
||||
|
||||
for (unitCount++; index < N1 + N2 + N3; index++, unitCount += 3)
|
||||
indexToUnits[index] = (byte)unitCount;
|
||||
indexToUnits[index] = (byte) unitCount;
|
||||
|
||||
for (unitCount++; index < N1 + N2 + N3 + N4; index++, unitCount += 4)
|
||||
indexToUnits[index] = (byte)unitCount;
|
||||
indexToUnits[index] = (byte) unitCount;
|
||||
|
||||
// Construct the static units to index lookup array. It will contain the following values.
|
||||
//
|
||||
@@ -75,8 +75,8 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
for (unitCount = index = 0; unitCount < 128; unitCount++)
|
||||
{
|
||||
index += (uint)((indexToUnits[index] < unitCount + 1) ? 1 : 0);
|
||||
unitsToIndex[unitCount] = (byte)index;
|
||||
index += (uint) ((indexToUnits[index] < unitCount + 1) ? 1 : 0);
|
||||
unitsToIndex[unitCount] = (byte) index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
for (int index = 0; index < IndexCount; index++)
|
||||
{
|
||||
MemoryNodes[index] = new MemoryNode((uint)(NodeOffset + index * MemoryNode.Size), Memory);
|
||||
MemoryNodes[index] = new MemoryNode((uint) (NodeOffset + index*MemoryNode.Size), Memory);
|
||||
MemoryNodes[index].Stamp = 0;
|
||||
MemoryNodes[index].Next = MemoryNode.Zero;
|
||||
MemoryNodes[index].UnitCount = 0;
|
||||
@@ -103,7 +103,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
Text = Heap;
|
||||
|
||||
uint difference = UnitSize * (AllocatorSize / 8 / UnitSize * 7);
|
||||
uint difference = UnitSize*(AllocatorSize/8/UnitSize*7);
|
||||
|
||||
HighUnit = Heap + AllocatorSize;
|
||||
LowUnit = HighUnit - difference;
|
||||
@@ -121,12 +121,12 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <param name="allocatorSize"></param>
|
||||
public void Start(int allocatorSize)
|
||||
{
|
||||
uint size = (uint)allocatorSize;
|
||||
uint size = (uint) allocatorSize;
|
||||
if (AllocatorSize != size)
|
||||
{
|
||||
Stop();
|
||||
Memory = new byte[HeapOffset + size]; // the single, large array of bytes
|
||||
Heap = new Pointer(HeapOffset, Memory); // reserve bytes in the range 0 .. HeapOffset - 1
|
||||
Memory = new byte[HeapOffset + size]; // the single, large array of bytes
|
||||
Heap = new Pointer(HeapOffset, Memory); // reserve bytes in the range 0 .. HeapOffset - 1
|
||||
AllocatorSize = size;
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
uint memoryUsed = AllocatorSize - (HighUnit - LowUnit) - (BaseUnit - Text);
|
||||
for (uint index = 0; index < IndexCount; index++)
|
||||
memoryUsed -= UnitSize * indexToUnits[index] * MemoryNodes[index].Stamp;
|
||||
memoryUsed -= UnitSize*indexToUnits[index]*MemoryNodes[index].Stamp;
|
||||
return memoryUsed;
|
||||
}
|
||||
|
||||
@@ -173,11 +173,11 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
return MemoryNodes[index].Remove();
|
||||
|
||||
Pointer allocatedBlock = LowUnit;
|
||||
LowUnit += indexToUnits[index] * UnitSize;
|
||||
LowUnit += indexToUnits[index]*UnitSize;
|
||||
if (LowUnit <= HighUnit)
|
||||
return allocatedBlock;
|
||||
|
||||
LowUnit -= indexToUnits[index] * UnitSize;
|
||||
LowUnit -= indexToUnits[index]*UnitSize;
|
||||
return AllocateUnitsRare(index);
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
uint index = unitsToIndex[unitCount - 1];
|
||||
|
||||
if (oldPointer > BaseUnit + 16 * 1024 || oldPointer > MemoryNodes[index].Next)
|
||||
if (oldPointer > BaseUnit + 16*1024 || oldPointer > MemoryNodes[index].Next)
|
||||
return oldPointer;
|
||||
|
||||
Pointer pointer = MemoryNodes[index].Remove();
|
||||
@@ -289,7 +289,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
if (oldPointer != BaseUnit)
|
||||
MemoryNodes[index].Insert(oldPointer, unitCount);
|
||||
else
|
||||
BaseUnit += unitCount * UnitSize;
|
||||
BaseUnit += unitCount*UnitSize;
|
||||
|
||||
return pointer;
|
||||
}
|
||||
@@ -344,7 +344,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
if (++oldIndex == IndexCount)
|
||||
{
|
||||
GlueCount--;
|
||||
oldIndex = indexToUnits[index] * UnitSize;
|
||||
oldIndex = indexToUnits[index]*UnitSize;
|
||||
return (BaseUnit - Text > oldIndex) ? (BaseUnit -= oldIndex) : Pointer.Zero;
|
||||
}
|
||||
} while (!MemoryNodes[oldIndex].Available);
|
||||
@@ -356,15 +356,15 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
private void SplitBlock(Pointer pointer, uint oldIndex, uint newIndex)
|
||||
{
|
||||
uint unitCountDifference = (uint)(indexToUnits[oldIndex] - indexToUnits[newIndex]);
|
||||
Pointer newPointer = pointer + indexToUnits[newIndex] * UnitSize;
|
||||
uint unitCountDifference = (uint) (indexToUnits[oldIndex] - indexToUnits[newIndex]);
|
||||
Pointer newPointer = pointer + indexToUnits[newIndex]*UnitSize;
|
||||
|
||||
uint index = unitsToIndex[unitCountDifference - 1];
|
||||
if (indexToUnits[index] != unitCountDifference)
|
||||
{
|
||||
uint unitCount = indexToUnits[--index];
|
||||
MemoryNodes[index].Insert(newPointer, unitCount);
|
||||
newPointer += unitCount * UnitSize;
|
||||
newPointer += unitCount*UnitSize;
|
||||
unitCountDifference -= unitCount;
|
||||
}
|
||||
|
||||
@@ -421,7 +421,8 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
if (indexToUnits[index] != unitCount)
|
||||
{
|
||||
uint unitCountDifference = unitCount - indexToUnits[--index];
|
||||
MemoryNodes[unitCountDifference - 1].Insert(memoryNode0 + (unitCount - unitCountDifference), unitCountDifference);
|
||||
MemoryNodes[unitCountDifference - 1].Insert(memoryNode0 + (unitCount - unitCountDifference),
|
||||
unitCountDifference);
|
||||
}
|
||||
|
||||
MemoryNodes[index].Insert(memoryNode0, indexToUnits[index]);
|
||||
@@ -454,4 +455,4 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,8 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
public void RangeEncoderNormalize(Stream stream)
|
||||
{
|
||||
while ((low ^ (low + range)) < RangeTop || range < RangeBottom && ((range = (uint) -low & (RangeBottom - 1)) != 0 || true))
|
||||
while ((low ^ (low + range)) < RangeTop ||
|
||||
range < RangeBottom && ((range = (uint) -low & (RangeBottom - 1)) != 0 || true))
|
||||
{
|
||||
stream.WriteByte((byte) (low >> 24));
|
||||
range <<= 8;
|
||||
@@ -44,13 +45,13 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
public void RangeEncodeSymbol()
|
||||
{
|
||||
low += LowCount * (range /= Scale);
|
||||
low += LowCount*(range /= Scale);
|
||||
range *= HighCount - LowCount;
|
||||
}
|
||||
|
||||
public void RangeShiftEncodeSymbol(int rangeShift)
|
||||
{
|
||||
low += LowCount * (range >>= rangeShift);
|
||||
low += LowCount*(range >>= rangeShift);
|
||||
range *= HighCount - LowCount;
|
||||
}
|
||||
|
||||
@@ -74,7 +75,8 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
public void RangeDecoderNormalize(Stream stream)
|
||||
{
|
||||
while ((low ^ (low + range)) < RangeTop || range < RangeBottom && ((range = (uint) -low & (RangeBottom - 1)) != 0 || true))
|
||||
while ((low ^ (low + range)) < RangeTop ||
|
||||
range < RangeBottom && ((range = (uint) -low & (RangeBottom - 1)) != 0 || true))
|
||||
{
|
||||
code = (code << 8) | (byte) stream.ReadByte();
|
||||
range <<= 8;
|
||||
@@ -84,18 +86,18 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
public uint RangeGetCurrentCount()
|
||||
{
|
||||
return (code - low) / (range /= Scale);
|
||||
return (code - low)/(range /= Scale);
|
||||
}
|
||||
|
||||
public uint RangeGetCurrentShiftCount(int rangeShift)
|
||||
{
|
||||
return (code - low) / (range >>= rangeShift);
|
||||
return (code - low)/(range >>= rangeShift);
|
||||
}
|
||||
|
||||
public void RangeRemoveSubrange()
|
||||
{
|
||||
low += range * LowCount;
|
||||
low += range*LowCount;
|
||||
range *= HighCount - LowCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,11 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// </summary>
|
||||
public uint Stamp
|
||||
{
|
||||
get { return ((uint) Memory[Address]) | ((uint) Memory[Address + 1]) << 8 | ((uint) Memory[Address + 2]) << 16 | ((uint) Memory[Address + 3]) << 24; }
|
||||
get
|
||||
{
|
||||
return ((uint) Memory[Address]) | ((uint) Memory[Address + 1]) << 8 | ((uint) Memory[Address + 2]) << 16 |
|
||||
((uint) Memory[Address + 3]) << 24;
|
||||
}
|
||||
set
|
||||
{
|
||||
Memory[Address] = (byte) value;
|
||||
@@ -63,7 +67,13 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// </summary>
|
||||
public MemoryNode Next
|
||||
{
|
||||
get { return new MemoryNode(((uint) Memory[Address + 4]) | ((uint) Memory[Address + 5]) << 8 | ((uint) Memory[Address + 6]) << 16 | ((uint) Memory[Address + 7]) << 24, Memory); }
|
||||
get
|
||||
{
|
||||
return
|
||||
new MemoryNode(
|
||||
((uint) Memory[Address + 4]) | ((uint) Memory[Address + 5]) << 8 |
|
||||
((uint) Memory[Address + 6]) << 16 | ((uint) Memory[Address + 7]) << 24, Memory);
|
||||
}
|
||||
set
|
||||
{
|
||||
Memory[Address + 4] = (byte) value.Address;
|
||||
@@ -78,7 +88,11 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// </summary>
|
||||
public uint UnitCount
|
||||
{
|
||||
get { return ((uint) Memory[Address + 8]) | ((uint) Memory[Address + 9]) << 8 | ((uint) Memory[Address + 10]) << 16 | ((uint) Memory[Address + 11]) << 24; }
|
||||
get
|
||||
{
|
||||
return ((uint) Memory[Address + 8]) | ((uint) Memory[Address + 9]) << 8 |
|
||||
((uint) Memory[Address + 10]) << 16 | ((uint) Memory[Address + 11]) << 24;
|
||||
}
|
||||
set
|
||||
{
|
||||
Memory[Address + 8] = (byte) value;
|
||||
@@ -157,7 +171,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static MemoryNode operator +(MemoryNode memoryNode, int offset)
|
||||
{
|
||||
memoryNode.Address = (uint) (memoryNode.Address + offset * Size);
|
||||
memoryNode.Address = (uint) (memoryNode.Address + offset*Size);
|
||||
return memoryNode;
|
||||
}
|
||||
|
||||
@@ -169,7 +183,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static MemoryNode operator +(MemoryNode memoryNode, uint offset)
|
||||
{
|
||||
memoryNode.Address += offset * Size;
|
||||
memoryNode.Address += offset*Size;
|
||||
return memoryNode;
|
||||
}
|
||||
|
||||
@@ -181,7 +195,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static MemoryNode operator -(MemoryNode memoryNode, int offset)
|
||||
{
|
||||
memoryNode.Address = (uint) (memoryNode.Address - offset * Size);
|
||||
memoryNode.Address = (uint) (memoryNode.Address - offset*Size);
|
||||
return memoryNode;
|
||||
}
|
||||
|
||||
@@ -193,7 +207,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static MemoryNode operator -(MemoryNode memoryNode, uint offset)
|
||||
{
|
||||
memoryNode.Address -= offset * Size;
|
||||
memoryNode.Address -= offset*Size;
|
||||
return memoryNode;
|
||||
}
|
||||
|
||||
@@ -243,4 +257,4 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
return Address.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using System.IO;
|
||||
|
||||
// This is a port of Dmitry Shkarin's PPMd Variant I Revision 1.
|
||||
// Ported by Michael Bone (mjbone03@yahoo.com.au).
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
/// <summary>
|
||||
@@ -16,7 +17,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
public const uint Signature = 0x84acaf8fU;
|
||||
public const char Variant = 'I';
|
||||
public const int MaximumOrder = 16; // maximum allowed model order
|
||||
public const int MaximumOrder = 16; // maximum allowed model order
|
||||
|
||||
private const byte UpperFrequency = 5;
|
||||
private const byte IntervalBitCount = 7;
|
||||
@@ -30,7 +31,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
private See2Context[,] see2Contexts;
|
||||
private See2Context emptySee2Context;
|
||||
private PpmContext maximumContext;
|
||||
private ushort[,] binarySummary = new ushort[25, 64]; // binary SEE-contexts
|
||||
private ushort[,] binarySummary = new ushort[25,64]; // binary SEE-contexts
|
||||
private byte[] numberStatisticsToBinarySummaryIndex = new byte[256];
|
||||
private byte[] probabilities = new byte[260];
|
||||
private byte[] characterMask = new byte[256];
|
||||
@@ -43,7 +44,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
private byte previousSuccess;
|
||||
private byte numberMasked;
|
||||
private ModelRestorationMethod method;
|
||||
private PpmState foundState; // found next state transition
|
||||
private PpmState foundState; // found next state transition
|
||||
|
||||
private Allocator Allocator;
|
||||
private Coder Coder;
|
||||
@@ -51,8 +52,13 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
private byte numberStatistics;
|
||||
private PpmState[] decodeStates = new PpmState[256];
|
||||
|
||||
private static readonly ushort[] InitialBinaryEscapes = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051 };
|
||||
private static readonly byte[] ExponentialEscapes = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 };
|
||||
private static readonly ushort[] InitialBinaryEscapes =
|
||||
{
|
||||
0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632,
|
||||
0x6051
|
||||
};
|
||||
|
||||
private static readonly byte[] ExponentialEscapes = {25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2};
|
||||
|
||||
#region Public Methods
|
||||
|
||||
@@ -69,12 +75,12 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
// 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
|
||||
// 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
|
||||
|
||||
numberStatisticsToBinarySummaryIndex[0] = 2 * 0;
|
||||
numberStatisticsToBinarySummaryIndex[1] = 2 * 1;
|
||||
numberStatisticsToBinarySummaryIndex[0] = 2*0;
|
||||
numberStatisticsToBinarySummaryIndex[1] = 2*1;
|
||||
for (int index = 2; index < 11; index++)
|
||||
numberStatisticsToBinarySummaryIndex[index] = 2 * 2;
|
||||
numberStatisticsToBinarySummaryIndex[index] = 2*2;
|
||||
for (int index = 11; index < 256; index++)
|
||||
numberStatisticsToBinarySummaryIndex[index] = 2 * 3;
|
||||
numberStatisticsToBinarySummaryIndex[index] = 2*3;
|
||||
|
||||
// Construct the probability table. Initially it will contain the following values (depending on the value of
|
||||
// the upper frequency).
|
||||
@@ -94,11 +100,11 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
uint probability = UpperFrequency;
|
||||
|
||||
for (int index = 0; index < UpperFrequency; index++)
|
||||
probabilities[index] = (byte)index;
|
||||
probabilities[index] = (byte) index;
|
||||
|
||||
for (int index = UpperFrequency; index < 260; index++)
|
||||
{
|
||||
probabilities[index] = (byte)probability;
|
||||
probabilities[index] = (byte) probability;
|
||||
count--;
|
||||
if (count == 0)
|
||||
{
|
||||
@@ -110,7 +116,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
// Create the context array.
|
||||
|
||||
see2Contexts = new See2Context[24, 32];
|
||||
see2Contexts = new See2Context[24,32];
|
||||
for (int index1 = 0; index1 < 24; index1++)
|
||||
for (int index2 = 0; index2 < 32; index2++)
|
||||
see2Contexts[index1, index2] = new See2Context();
|
||||
@@ -118,9 +124,9 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
// Set the signature (identifying the algorithm).
|
||||
|
||||
emptySee2Context = new See2Context();
|
||||
emptySee2Context.Summary = (ushort)(Signature & 0x0000ffff);
|
||||
emptySee2Context.Shift = (byte)((Signature >> 16) & 0x000000ff);
|
||||
emptySee2Context.Count = (byte)(Signature >> 24);
|
||||
emptySee2Context.Summary = (ushort) (Signature & 0x0000ffff);
|
||||
emptySee2Context.Shift = (byte) ((Signature >> 16) & 0x000000ff);
|
||||
emptySee2Context.Count = (byte) (Signature >> 24);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -183,7 +189,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
Coder.RangeEncodeSymbol();
|
||||
}
|
||||
|
||||
if (orderFall == 0 && (Pointer)foundState.Successor >= Allocator.BaseUnit)
|
||||
if (orderFall == 0 && (Pointer) foundState.Successor >= Allocator.BaseUnit)
|
||||
{
|
||||
maximumContext = foundState.Successor;
|
||||
}
|
||||
@@ -197,7 +203,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
Coder.RangeEncoderNormalize(target);
|
||||
}
|
||||
|
||||
StopEncoding:
|
||||
StopEncoding:
|
||||
Coder.RangeEncoderFlush(target);
|
||||
}
|
||||
|
||||
@@ -266,7 +272,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
offset++;
|
||||
total++;
|
||||
|
||||
if (orderFall == 0 && (Pointer)foundState.Successor >= Allocator.BaseUnit)
|
||||
if (orderFall == 0 && (Pointer) foundState.Successor >= Allocator.BaseUnit)
|
||||
{
|
||||
maximumContext = foundState.Successor;
|
||||
}
|
||||
@@ -282,7 +288,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
Coder.RangeDecoderNormalize(source);
|
||||
}
|
||||
|
||||
StopDecoding:
|
||||
StopDecoding:
|
||||
return total;
|
||||
}
|
||||
|
||||
@@ -322,14 +328,15 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
maximumContext = Allocator.AllocateContext();
|
||||
maximumContext.Suffix = PpmContext.Zero;
|
||||
maximumContext.NumberStatistics = 255;
|
||||
maximumContext.SummaryFrequency = (ushort)(maximumContext.NumberStatistics + 2);
|
||||
maximumContext.Statistics = Allocator.AllocateUnits(256 / 2); // allocates enough space for 256 PPM states (each is 6 bytes)
|
||||
maximumContext.SummaryFrequency = (ushort) (maximumContext.NumberStatistics + 2);
|
||||
maximumContext.Statistics = Allocator.AllocateUnits(256/2);
|
||||
// allocates enough space for 256 PPM states (each is 6 bytes)
|
||||
|
||||
previousSuccess = 0;
|
||||
for (int index = 0; index < 256; index++)
|
||||
{
|
||||
PpmState state = maximumContext.Statistics[index];
|
||||
state.Symbol = (byte)index;
|
||||
state.Symbol = (byte) index;
|
||||
state.Frequency = 1;
|
||||
state.Successor = PpmContext.Zero;
|
||||
}
|
||||
@@ -340,7 +347,8 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
while (probabilities[index1] == probability)
|
||||
index1++;
|
||||
for (int index2 = 0; index2 < 8; index2++)
|
||||
binarySummary[probability, index2] = (ushort)(BinaryScale - InitialBinaryEscapes[index2] / (index1 + 1));
|
||||
binarySummary[probability, index2] =
|
||||
(ushort) (BinaryScale - InitialBinaryEscapes[index2]/(index1 + 1));
|
||||
for (int index2 = 8; index2 < 64; index2 += 8)
|
||||
for (int index3 = 0; index3 < 8; index3++)
|
||||
binarySummary[probability, index2 + index3] = binarySummary[probability, index3];
|
||||
@@ -352,7 +360,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
while (probabilities[index1 + 3] == probability + 3)
|
||||
index1++;
|
||||
for (int index2 = 0; index2 < 32; index2++)
|
||||
see2Contexts[probability, index2].Initialize(2 * index1 + 5);
|
||||
see2Contexts[probability, index2].Initialize(2*index1 + 5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,7 +382,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
PpmContext foundStateSuccessor = foundState.Successor;
|
||||
PpmContext context = minimumContext.Suffix;
|
||||
|
||||
if ((foundStateFrequency < MaximumFrequency / 4) && (context != PpmContext.Zero))
|
||||
if ((foundStateFrequency < MaximumFrequency/4) && (context != PpmContext.Zero))
|
||||
{
|
||||
if (context.NumberStatistics != 0)
|
||||
{
|
||||
@@ -392,14 +400,14 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
state--;
|
||||
}
|
||||
}
|
||||
cf = (uint)((state.Frequency < MaximumFrequency - 9) ? 2 : 0);
|
||||
state.Frequency += (byte)cf;
|
||||
context.SummaryFrequency += (byte)cf;
|
||||
cf = (uint) ((state.Frequency < MaximumFrequency - 9) ? 2 : 0);
|
||||
state.Frequency += (byte) cf;
|
||||
context.SummaryFrequency += (byte) cf;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = context.FirstState;
|
||||
state.Frequency += (byte)((state.Frequency < 32) ? 1 : 0);
|
||||
state.Frequency += (byte) ((state.Frequency < 32) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,7 +454,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
numberStatistics = minimumContext.NumberStatistics;
|
||||
s0 = minimumContext.SummaryFrequency - numberStatistics - foundStateFrequency;
|
||||
flag = (byte)((foundStateSymbol >= 0x40) ? 0x08 : 0x00);
|
||||
flag = (byte) ((foundStateSymbol >= 0x40) ? 0x08 : 0x00);
|
||||
for (; currentContext != minimumContext; currentContext = currentContext.Suffix)
|
||||
{
|
||||
ns1 = currentContext.NumberStatistics;
|
||||
@@ -459,7 +467,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
goto RestartModel;
|
||||
currentContext.Statistics = state;
|
||||
}
|
||||
currentContext.SummaryFrequency += (ushort)((3 * ns1 + 1 < numberStatistics) ? 1 : 0);
|
||||
currentContext.SummaryFrequency += (ushort) ((3*ns1 + 1 < numberStatistics) ? 1 : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -468,38 +476,39 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
goto RestartModel;
|
||||
Copy(state, currentContext.FirstState);
|
||||
currentContext.Statistics = state;
|
||||
if (state.Frequency < MaximumFrequency / 4 - 1)
|
||||
if (state.Frequency < MaximumFrequency/4 - 1)
|
||||
state.Frequency += state.Frequency;
|
||||
else
|
||||
state.Frequency = (byte)(MaximumFrequency - 4);
|
||||
currentContext.SummaryFrequency = (ushort)(state.Frequency + initialEscape + ((numberStatistics > 2) ? 1 : 0));
|
||||
state.Frequency = (byte) (MaximumFrequency - 4);
|
||||
currentContext.SummaryFrequency =
|
||||
(ushort) (state.Frequency + initialEscape + ((numberStatistics > 2) ? 1 : 0));
|
||||
}
|
||||
|
||||
cf = (uint)(2 * foundStateFrequency * (currentContext.SummaryFrequency + 6));
|
||||
cf = (uint) (2*foundStateFrequency*(currentContext.SummaryFrequency + 6));
|
||||
sf = s0 + currentContext.SummaryFrequency;
|
||||
|
||||
if (cf < 6 * sf)
|
||||
if (cf < 6*sf)
|
||||
{
|
||||
cf = (uint)(1 + ((cf > sf) ? 1 : 0) + ((cf >= 4 * sf) ? 1 : 0));
|
||||
cf = (uint) (1 + ((cf > sf) ? 1 : 0) + ((cf >= 4*sf) ? 1 : 0));
|
||||
currentContext.SummaryFrequency += 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
cf = (uint)(4 + ((cf > 9 * sf) ? 1 : 0) + ((cf > 12 * sf) ? 1 : 0) + ((cf > 15 * sf) ? 1 : 0));
|
||||
currentContext.SummaryFrequency += (ushort)cf;
|
||||
cf = (uint) (4 + ((cf > 9*sf) ? 1 : 0) + ((cf > 12*sf) ? 1 : 0) + ((cf > 15*sf) ? 1 : 0));
|
||||
currentContext.SummaryFrequency += (ushort) cf;
|
||||
}
|
||||
|
||||
state = currentContext.Statistics + (++currentContext.NumberStatistics);
|
||||
state.Successor = Successor;
|
||||
state.Symbol = foundStateSymbol;
|
||||
state.Frequency = (byte)cf;
|
||||
state.Frequency = (byte) cf;
|
||||
currentContext.Flags |= flag;
|
||||
}
|
||||
|
||||
maximumContext = foundStateSuccessor;
|
||||
return;
|
||||
|
||||
RestartModel:
|
||||
RestartModel:
|
||||
RestoreModel(currentContext, minimumContext, foundStateSuccessor);
|
||||
}
|
||||
|
||||
@@ -545,17 +554,18 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
state++;
|
||||
} while (temporary != symbol);
|
||||
}
|
||||
temporary = (byte)((state.Frequency < MaximumFrequency - 9) ? 1 : 0);
|
||||
temporary = (byte) ((state.Frequency < MaximumFrequency - 9) ? 1 : 0);
|
||||
state.Frequency += temporary;
|
||||
context.SummaryFrequency += temporary;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = context.FirstState;
|
||||
state.Frequency += (byte)(((context.Suffix.NumberStatistics == 0) ? 1 : 0) & ((state.Frequency < 24) ? 1 : 0));
|
||||
state.Frequency +=
|
||||
(byte) (((context.Suffix.NumberStatistics == 0) ? 1 : 0) & ((state.Frequency < 24) ? 1 : 0));
|
||||
}
|
||||
|
||||
LoopEntry:
|
||||
LoopEntry:
|
||||
if (state.Successor != upBranch)
|
||||
{
|
||||
context = state.Successor;
|
||||
@@ -564,17 +574,17 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
states[stateIndex++] = state;
|
||||
} while (context.Suffix != PpmContext.Zero);
|
||||
|
||||
NoLoop:
|
||||
NoLoop:
|
||||
if (stateIndex == 0)
|
||||
return context;
|
||||
|
||||
byte localNumberStatistics = 0;
|
||||
byte localFlags = (byte)((symbol >= 0x40) ? 0x10 : 0x00);
|
||||
byte localFlags = (byte) ((symbol >= 0x40) ? 0x10 : 0x00);
|
||||
symbol = upBranch.NumberStatistics;
|
||||
byte localSymbol = symbol;
|
||||
byte localFrequency;
|
||||
PpmContext localSuccessor = ((Pointer)upBranch) + 1;
|
||||
localFlags |= (byte)((symbol >= 0x40) ? 0x08 : 0x00);
|
||||
PpmContext localSuccessor = ((Pointer) upBranch) + 1;
|
||||
localFlags |= (byte) ((symbol >= 0x40) ? 0x08 : 0x00);
|
||||
|
||||
if (context.NumberStatistics != 0)
|
||||
{
|
||||
@@ -588,9 +598,9 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
state++;
|
||||
} while (temporary != symbol);
|
||||
}
|
||||
uint cf = (uint)(state.Frequency - 1);
|
||||
uint s0 = (uint)(context.SummaryFrequency - context.NumberStatistics - cf);
|
||||
localFrequency = (byte)(1 + ((2 * cf <= s0) ? (uint)((5 * cf > s0) ? 1 : 0) : ((cf + 2 * s0 - 3) / s0)));
|
||||
uint cf = (uint) (state.Frequency - 1);
|
||||
uint s0 = (uint) (context.SummaryFrequency - context.NumberStatistics - cf);
|
||||
localFrequency = (byte) (1 + ((2*cf <= s0) ? (uint) ((5*cf > s0) ? 1 : 0) : ((cf + 2*s0 - 3)/s0)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -670,17 +680,17 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
state++;
|
||||
} while (temporary != symbol);
|
||||
}
|
||||
temporary = (byte)((state.Frequency < MaximumFrequency - 9) ? 2 : 0);
|
||||
temporary = (byte) ((state.Frequency < MaximumFrequency - 9) ? 2 : 0);
|
||||
state.Frequency += temporary;
|
||||
context.SummaryFrequency += temporary;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = context.FirstState;
|
||||
state.Frequency += (byte)((state.Frequency < 32) ? 1 : 0);
|
||||
state.Frequency += (byte) ((state.Frequency < 32) ? 1 : 0);
|
||||
}
|
||||
|
||||
LoopEntry:
|
||||
LoopEntry:
|
||||
if (state.Successor != PpmContext.Zero)
|
||||
break;
|
||||
states[stateIndex++] = state;
|
||||
@@ -725,30 +735,32 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
if (--currentContext.NumberStatistics == 0)
|
||||
{
|
||||
currentContext.Flags = (byte)((currentContext.Flags & 0x10) + ((currentContext.Statistics.Symbol >= 0x40) ? 0x08 : 0x00));
|
||||
currentContext.Flags =
|
||||
(byte)
|
||||
((currentContext.Flags & 0x10) + ((currentContext.Statistics.Symbol >= 0x40) ? 0x08 : 0x00));
|
||||
PpmState state = currentContext.Statistics;
|
||||
Copy(currentContext.FirstState, state);
|
||||
Allocator.SpecialFreeUnits(state);
|
||||
currentContext.FirstStateFrequency = (byte)((currentContext.FirstStateFrequency + 11) >> 3);
|
||||
currentContext.FirstStateFrequency = (byte) ((currentContext.FirstStateFrequency + 11) >> 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
Refresh((uint)((currentContext.NumberStatistics + 3) >> 1), false, currentContext);
|
||||
Refresh((uint) ((currentContext.NumberStatistics + 3) >> 1), false, currentContext);
|
||||
}
|
||||
}
|
||||
|
||||
for (; currentContext != minimumContext; currentContext = currentContext.Suffix)
|
||||
{
|
||||
if (currentContext.NumberStatistics == 0)
|
||||
currentContext.FirstStateFrequency -= (byte)(currentContext.FirstStateFrequency >> 1);
|
||||
else if ((currentContext.SummaryFrequency += 4) > 128 + 4 * currentContext.NumberStatistics)
|
||||
Refresh((uint)((currentContext.NumberStatistics + 2) >> 1), true, currentContext);
|
||||
currentContext.FirstStateFrequency -= (byte) (currentContext.FirstStateFrequency >> 1);
|
||||
else if ((currentContext.SummaryFrequency += 4) > 128 + 4*currentContext.NumberStatistics)
|
||||
Refresh((uint) ((currentContext.NumberStatistics + 2) >> 1), true, currentContext);
|
||||
}
|
||||
|
||||
if (method > ModelRestorationMethod.Freeze)
|
||||
{
|
||||
maximumContext = foundStateSuccessor;
|
||||
Allocator.GlueCount += (uint)(((Allocator.MemoryNodes[1].Stamp & 1) == 0) ? 1 : 0);
|
||||
Allocator.GlueCount += (uint) (((Allocator.MemoryNodes[1].Stamp & 1) == 0) ? 1 : 0);
|
||||
}
|
||||
else if (method == ModelRestorationMethod.Freeze)
|
||||
{
|
||||
@@ -756,11 +768,12 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
maximumContext = maximumContext.Suffix;
|
||||
|
||||
RemoveBinaryContexts(0, maximumContext);
|
||||
method = (ModelRestorationMethod)(method + 1);
|
||||
method = (ModelRestorationMethod) (method + 1);
|
||||
Allocator.GlueCount = 0;
|
||||
orderFall = modelOrder;
|
||||
}
|
||||
else if (method == ModelRestorationMethod.Restart || Allocator.GetMemoryUsed() < (Allocator.AllocatorSize >> 1))
|
||||
else if (method == ModelRestorationMethod.Restart ||
|
||||
Allocator.GetMemoryUsed() < (Allocator.AllocatorSize >> 1))
|
||||
{
|
||||
StartModel(modelOrder, method);
|
||||
escapeCount = 0;
|
||||
@@ -774,7 +787,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
CutOff(0, maximumContext);
|
||||
Allocator.ExpandText();
|
||||
} while (Allocator.GetMemoryUsed() > 3 * (Allocator.AllocatorSize >> 2));
|
||||
} while (Allocator.GetMemoryUsed() > 3*(Allocator.AllocatorSize >> 2));
|
||||
|
||||
Allocator.GlueCount = 0;
|
||||
orderFall = modelOrder;
|
||||
@@ -816,4 +829,4 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,4 +26,4 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// </summary>
|
||||
Freeze = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,18 +45,18 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (Address == 0)
|
||||
throw new InvalidOperationException("The pointer being indexed is a null pointer.");
|
||||
#endif
|
||||
#endif
|
||||
return Memory[Address + offset];
|
||||
}
|
||||
set
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (Address == 0)
|
||||
throw new InvalidOperationException("The pointer being indexed is a null pointer.");
|
||||
#endif
|
||||
#endif
|
||||
Memory[Address + offset] = value;
|
||||
}
|
||||
}
|
||||
@@ -99,10 +99,10 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static Pointer operator +(Pointer pointer, int offset)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (pointer.Address == 0)
|
||||
throw new InvalidOperationException("The pointer is a null pointer.");
|
||||
#endif
|
||||
#endif
|
||||
pointer.Address = (uint) (pointer.Address + offset);
|
||||
return pointer;
|
||||
}
|
||||
@@ -115,10 +115,10 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static Pointer operator +(Pointer pointer, uint offset)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (pointer.Address == 0)
|
||||
throw new InvalidOperationException("The pointer is a null pointer.");
|
||||
#endif
|
||||
#endif
|
||||
pointer.Address += offset;
|
||||
return pointer;
|
||||
}
|
||||
@@ -130,10 +130,10 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static Pointer operator ++(Pointer pointer)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (pointer.Address == 0)
|
||||
throw new InvalidOperationException("The pointer being incremented is a null pointer.");
|
||||
#endif
|
||||
#endif
|
||||
pointer.Address++;
|
||||
return pointer;
|
||||
}
|
||||
@@ -146,10 +146,10 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static Pointer operator -(Pointer pointer, int offset)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (pointer.Address == 0)
|
||||
throw new InvalidOperationException("The pointer is a null pointer.");
|
||||
#endif
|
||||
#endif
|
||||
pointer.Address = (uint) (pointer.Address - offset);
|
||||
return pointer;
|
||||
}
|
||||
@@ -162,10 +162,10 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static Pointer operator -(Pointer pointer, uint offset)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (pointer.Address == 0)
|
||||
throw new InvalidOperationException("The pointer is a null pointer.");
|
||||
#endif
|
||||
#endif
|
||||
pointer.Address -= offset;
|
||||
return pointer;
|
||||
}
|
||||
@@ -177,10 +177,10 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static Pointer operator --(Pointer pointer)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (pointer.Address == 0)
|
||||
throw new InvalidOperationException("The pointer being decremented is a null pointer.");
|
||||
#endif
|
||||
#endif
|
||||
pointer.Address--;
|
||||
return pointer;
|
||||
}
|
||||
@@ -193,12 +193,14 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns>The number of bytes between the two pointers.</returns>
|
||||
public static uint operator -(Pointer pointer1, Pointer pointer2)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (pointer1.Address == 0)
|
||||
throw new InvalidOperationException("The pointer to the left of the subtraction operator is a null pointer.");
|
||||
throw new InvalidOperationException(
|
||||
"The pointer to the left of the subtraction operator is a null pointer.");
|
||||
if (pointer2.Address == 0)
|
||||
throw new InvalidOperationException("The pointer to the right of the subtraction operator is a null pointer.");
|
||||
#endif
|
||||
throw new InvalidOperationException(
|
||||
"The pointer to the right of the subtraction operator is a null pointer.");
|
||||
#endif
|
||||
return pointer1.Address - pointer2.Address;
|
||||
}
|
||||
|
||||
@@ -210,12 +212,14 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static bool operator <(Pointer pointer1, Pointer pointer2)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (pointer1.Address == 0)
|
||||
throw new InvalidOperationException("The pointer to the left of the less than operator is a null pointer.");
|
||||
throw new InvalidOperationException(
|
||||
"The pointer to the left of the less than operator is a null pointer.");
|
||||
if (pointer2.Address == 0)
|
||||
throw new InvalidOperationException("The pointer to the right of the less than operator is a null pointer.");
|
||||
#endif
|
||||
throw new InvalidOperationException(
|
||||
"The pointer to the right of the less than operator is a null pointer.");
|
||||
#endif
|
||||
return pointer1.Address < pointer2.Address;
|
||||
}
|
||||
|
||||
@@ -227,12 +231,14 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static bool operator <=(Pointer pointer1, Pointer pointer2)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (pointer1.Address == 0)
|
||||
throw new InvalidOperationException("The pointer to the left of the less than or equal to operator is a null pointer.");
|
||||
throw new InvalidOperationException(
|
||||
"The pointer to the left of the less than or equal to operator is a null pointer.");
|
||||
if (pointer2.Address == 0)
|
||||
throw new InvalidOperationException("The pointer to the right of the less than or equal to operator is a null pointer.");
|
||||
#endif
|
||||
throw new InvalidOperationException(
|
||||
"The pointer to the right of the less than or equal to operator is a null pointer.");
|
||||
#endif
|
||||
return pointer1.Address <= pointer2.Address;
|
||||
}
|
||||
|
||||
@@ -244,12 +250,14 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static bool operator >(Pointer pointer1, Pointer pointer2)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (pointer1.Address == 0)
|
||||
throw new InvalidOperationException("The pointer to the left of the greater than operator is a null pointer.");
|
||||
throw new InvalidOperationException(
|
||||
"The pointer to the left of the greater than operator is a null pointer.");
|
||||
if (pointer2.Address == 0)
|
||||
throw new InvalidOperationException("The pointer to the right of the greater than operator is a null pointer.");
|
||||
#endif
|
||||
throw new InvalidOperationException(
|
||||
"The pointer to the right of the greater than operator is a null pointer.");
|
||||
#endif
|
||||
return pointer1.Address > pointer2.Address;
|
||||
}
|
||||
|
||||
@@ -261,12 +269,14 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static bool operator >=(Pointer pointer1, Pointer pointer2)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
if (pointer1.Address == 0)
|
||||
throw new InvalidOperationException("The pointer to the left of the greater than or equal to operator is a null pointer.");
|
||||
throw new InvalidOperationException(
|
||||
"The pointer to the left of the greater than or equal to operator is a null pointer.");
|
||||
if (pointer2.Address == 0)
|
||||
throw new InvalidOperationException("The pointer to the right of the greater than or equal to operator is a null pointer.");
|
||||
#endif
|
||||
throw new InvalidOperationException(
|
||||
"The pointer to the right of the greater than or equal to operator is a null pointer.");
|
||||
#endif
|
||||
return pointer1.Address >= pointer2.Address;
|
||||
}
|
||||
|
||||
@@ -316,4 +326,4 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
return Address.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
#region Using
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.I1
|
||||
@@ -60,11 +58,11 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// </summary>
|
||||
public ushort SummaryFrequency
|
||||
{
|
||||
get { return (ushort)(((ushort)Memory[Address + 2]) | ((ushort)Memory[Address + 3]) << 8); }
|
||||
get { return (ushort) (((ushort) Memory[Address + 2]) | ((ushort) Memory[Address + 3]) << 8); }
|
||||
set
|
||||
{
|
||||
Memory[Address + 2] = (byte)value;
|
||||
Memory[Address + 3] = (byte)(value >> 8);
|
||||
Memory[Address + 2] = (byte) value;
|
||||
Memory[Address + 3] = (byte) (value >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,13 +71,19 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// </summary>
|
||||
public PpmState Statistics
|
||||
{
|
||||
get { return new PpmState(((uint)Memory[Address + 4]) | ((uint)Memory[Address + 5]) << 8 | ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); }
|
||||
get
|
||||
{
|
||||
return
|
||||
new PpmState(
|
||||
((uint) Memory[Address + 4]) | ((uint) Memory[Address + 5]) << 8 |
|
||||
((uint) Memory[Address + 6]) << 16 | ((uint) Memory[Address + 7]) << 24, Memory);
|
||||
}
|
||||
set
|
||||
{
|
||||
Memory[Address + 4] = (byte)value.Address;
|
||||
Memory[Address + 5] = (byte)(value.Address >> 8);
|
||||
Memory[Address + 6] = (byte)(value.Address >> 16);
|
||||
Memory[Address + 7] = (byte)(value.Address >> 24);
|
||||
Memory[Address + 4] = (byte) value.Address;
|
||||
Memory[Address + 5] = (byte) (value.Address >> 8);
|
||||
Memory[Address + 6] = (byte) (value.Address >> 16);
|
||||
Memory[Address + 7] = (byte) (value.Address >> 24);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,13 +92,19 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// </summary>
|
||||
public PpmContext Suffix
|
||||
{
|
||||
get { return new PpmContext(((uint)Memory[Address + 8]) | ((uint)Memory[Address + 9]) << 8 | ((uint)Memory[Address + 10]) << 16 | ((uint)Memory[Address + 11]) << 24, Memory); }
|
||||
get
|
||||
{
|
||||
return
|
||||
new PpmContext(
|
||||
((uint) Memory[Address + 8]) | ((uint) Memory[Address + 9]) << 8 |
|
||||
((uint) Memory[Address + 10]) << 16 | ((uint) Memory[Address + 11]) << 24, Memory);
|
||||
}
|
||||
set
|
||||
{
|
||||
Memory[Address + 8] = (byte)value.Address;
|
||||
Memory[Address + 9] = (byte)(value.Address >> 8);
|
||||
Memory[Address + 10] = (byte)(value.Address >> 16);
|
||||
Memory[Address + 11] = (byte)(value.Address >> 24);
|
||||
Memory[Address + 8] = (byte) value.Address;
|
||||
Memory[Address + 9] = (byte) (value.Address >> 8);
|
||||
Memory[Address + 10] = (byte) (value.Address >> 16);
|
||||
Memory[Address + 11] = (byte) (value.Address >> 24);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +143,8 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// information can be obtained using the Symbol property on the PPM state provided by the
|
||||
/// <see cref="FirstState"/> property.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "The property getter is provided for completeness.")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode",
|
||||
Justification = "The property getter is provided for completeness.")]
|
||||
public byte FirstStateSymbol
|
||||
{
|
||||
get { return Memory[Address + 2]; }
|
||||
@@ -155,16 +166,23 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// Gets or sets the successor of the first PPM state. This is provided for convenience. The same
|
||||
/// information can be obtained using the Successor property on the PPM state provided by the
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "The property getter is provided for completeness.")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode",
|
||||
Justification = "The property getter is provided for completeness.")]
|
||||
public PpmContext FirstStateSuccessor
|
||||
{
|
||||
get { return new PpmContext(((uint)Memory[Address + 4]) | ((uint)Memory[Address + 5]) << 8 | ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); }
|
||||
get
|
||||
{
|
||||
return
|
||||
new PpmContext(
|
||||
((uint) Memory[Address + 4]) | ((uint) Memory[Address + 5]) << 8 |
|
||||
((uint) Memory[Address + 6]) << 16 | ((uint) Memory[Address + 7]) << 24, Memory);
|
||||
}
|
||||
set
|
||||
{
|
||||
Memory[Address + 4] = (byte)value.Address;
|
||||
Memory[Address + 5] = (byte)(value.Address >> 8);
|
||||
Memory[Address + 6] = (byte)(value.Address >> 16);
|
||||
Memory[Address + 7] = (byte)(value.Address >> 24);
|
||||
Memory[Address + 4] = (byte) value.Address;
|
||||
Memory[Address + 5] = (byte) (value.Address >> 8);
|
||||
Memory[Address + 6] = (byte) (value.Address >> 16);
|
||||
Memory[Address + 7] = (byte) (value.Address >> 24);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +204,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static PpmContext operator +(PpmContext context, int offset)
|
||||
{
|
||||
context.Address = (uint)(context.Address + offset * Size);
|
||||
context.Address = (uint) (context.Address + offset*Size);
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -198,7 +216,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static PpmContext operator -(PpmContext context, int offset)
|
||||
{
|
||||
context.Address = (uint)(context.Address - offset * Size);
|
||||
context.Address = (uint) (context.Address - offset*Size);
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -255,7 +273,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
if (obj is PpmContext)
|
||||
{
|
||||
PpmContext context = (PpmContext)obj;
|
||||
PpmContext context = (PpmContext) obj;
|
||||
return context.Address == Address;
|
||||
}
|
||||
return base.Equals(obj);
|
||||
@@ -275,22 +293,24 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
PpmState state = context.FirstState;
|
||||
int index1 = probabilities[state.Frequency - 1];
|
||||
int index2 = numberStatisticsToBinarySummaryIndex[context.Suffix.NumberStatistics] + previousSuccess + context.Flags + ((runLength >> 26) & 0x20);
|
||||
int index2 = numberStatisticsToBinarySummaryIndex[context.Suffix.NumberStatistics] + previousSuccess +
|
||||
context.Flags + ((runLength >> 26) & 0x20);
|
||||
|
||||
if (state.Symbol == symbol)
|
||||
{
|
||||
foundState = state;
|
||||
state.Frequency += (byte)((state.Frequency < 196) ? 1 : 0);
|
||||
state.Frequency += (byte) ((state.Frequency < 196) ? 1 : 0);
|
||||
Coder.LowCount = 0;
|
||||
Coder.HighCount = binarySummary[index1, index2];
|
||||
binarySummary[index1, index2] += (ushort)(Interval - Mean(binarySummary[index1, index2], PeriodBitCount, 2));
|
||||
binarySummary[index1, index2] +=
|
||||
(ushort) (Interval - Mean(binarySummary[index1, index2], PeriodBitCount, 2));
|
||||
previousSuccess = 1;
|
||||
runLength++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Coder.LowCount = binarySummary[index1, index2];
|
||||
binarySummary[index1, index2] -= (ushort)Mean(binarySummary[index1, index2], PeriodBitCount, 2);
|
||||
binarySummary[index1, index2] -= (ushort) Mean(binarySummary[index1, index2], PeriodBitCount, 2);
|
||||
Coder.HighCount = BinaryScale;
|
||||
initialEscape = ExponentialEscapes[binarySummary[index1, index2] >> 10];
|
||||
characterMask[state.Symbol] = escapeCount;
|
||||
@@ -309,7 +329,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
if (index == symbol)
|
||||
{
|
||||
Coder.HighCount = state.Frequency;
|
||||
previousSuccess = (byte)((2 * Coder.HighCount >= Coder.Scale) ? 1 : 0);
|
||||
previousSuccess = (byte) ((2*Coder.HighCount >= Coder.Scale) ? 1 : 0);
|
||||
foundState = state;
|
||||
foundState.Frequency += 4;
|
||||
context.SummaryFrequency += 4;
|
||||
@@ -350,7 +370,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
See2Context see2Context = MakeEscapeFrequency(context);
|
||||
uint currentSymbol;
|
||||
uint lowCount = 0;
|
||||
uint index = (uint)(context.NumberStatistics - numberMasked);
|
||||
uint index = (uint) (context.NumberStatistics - numberMasked);
|
||||
PpmState state = context.Statistics - 1;
|
||||
|
||||
do
|
||||
@@ -369,15 +389,15 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
Coder.LowCount = lowCount;
|
||||
Coder.Scale += Coder.LowCount;
|
||||
Coder.HighCount = Coder.Scale;
|
||||
see2Context.Summary += (ushort)Coder.Scale;
|
||||
see2Context.Summary += (ushort) Coder.Scale;
|
||||
numberMasked = context.NumberStatistics;
|
||||
return;
|
||||
|
||||
SymbolFound:
|
||||
SymbolFound:
|
||||
Coder.LowCount = lowCount;
|
||||
lowCount += state.Frequency;
|
||||
Coder.HighCount = lowCount;
|
||||
for (PpmState p1 = state; --index != 0; )
|
||||
for (PpmState p1 = state; --index != 0;)
|
||||
{
|
||||
do
|
||||
{
|
||||
@@ -395,22 +415,24 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
PpmState state = context.FirstState;
|
||||
int index1 = probabilities[state.Frequency - 1];
|
||||
int index2 = numberStatisticsToBinarySummaryIndex[context.Suffix.NumberStatistics] + previousSuccess + context.Flags + ((runLength >> 26) & 0x20);
|
||||
int index2 = numberStatisticsToBinarySummaryIndex[context.Suffix.NumberStatistics] + previousSuccess +
|
||||
context.Flags + ((runLength >> 26) & 0x20);
|
||||
|
||||
if (Coder.RangeGetCurrentShiftCount(TotalBitCount) < binarySummary[index1, index2])
|
||||
{
|
||||
foundState = state;
|
||||
state.Frequency += (byte)((state.Frequency < 196) ? 1 : 0);
|
||||
state.Frequency += (byte) ((state.Frequency < 196) ? 1 : 0);
|
||||
Coder.LowCount = 0;
|
||||
Coder.HighCount = binarySummary[index1, index2];
|
||||
binarySummary[index1, index2] += (ushort)(Interval - Mean(binarySummary[index1, index2], PeriodBitCount, 2));
|
||||
binarySummary[index1, index2] +=
|
||||
(ushort) (Interval - Mean(binarySummary[index1, index2], PeriodBitCount, 2));
|
||||
previousSuccess = 1;
|
||||
runLength++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Coder.LowCount = binarySummary[index1, index2];
|
||||
binarySummary[index1, index2] -= (ushort)Mean(binarySummary[index1, index2], PeriodBitCount, 2);
|
||||
binarySummary[index1, index2] -= (ushort) Mean(binarySummary[index1, index2], PeriodBitCount, 2);
|
||||
Coder.HighCount = BinaryScale;
|
||||
initialEscape = ExponentialEscapes[binarySummary[index1, index2] >> 10];
|
||||
characterMask[state.Symbol] = escapeCount;
|
||||
@@ -432,10 +454,10 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
if (count < highCount)
|
||||
{
|
||||
Coder.HighCount = highCount;
|
||||
previousSuccess = (byte)((2 * Coder.HighCount >= Coder.Scale) ? 1 : 0);
|
||||
previousSuccess = (byte) ((2*Coder.HighCount >= Coder.Scale) ? 1 : 0);
|
||||
foundState = state;
|
||||
highCount += 4;
|
||||
foundState.Frequency = (byte)highCount;
|
||||
foundState.Frequency = (byte) highCount;
|
||||
context.SummaryFrequency += 4;
|
||||
runLength += previousSuccess;
|
||||
if (highCount > MaximumFrequency)
|
||||
@@ -474,7 +496,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
uint currentSymbol;
|
||||
uint count;
|
||||
uint highCount = 0;
|
||||
uint index = (uint)(context.NumberStatistics - numberMasked);
|
||||
uint index = (uint) (context.NumberStatistics - numberMasked);
|
||||
uint stateIndex = 0;
|
||||
PpmState state = context.Statistics - 1;
|
||||
|
||||
@@ -486,7 +508,8 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
state++;
|
||||
} while (characterMask[currentSymbol] == escapeCount);
|
||||
highCount += state.Frequency;
|
||||
decodeStates[stateIndex++] = state; // note that decodeStates is a static array that is re-used on each call to this method (for performance reasons)
|
||||
decodeStates[stateIndex++] = state;
|
||||
// note that decodeStates is a static array that is re-used on each call to this method (for performance reasons)
|
||||
} while (--index != 0);
|
||||
|
||||
Coder.Scale += highCount;
|
||||
@@ -507,14 +530,14 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
{
|
||||
Coder.LowCount = highCount;
|
||||
Coder.HighCount = Coder.Scale;
|
||||
index = (uint)(context.NumberStatistics - numberMasked);
|
||||
index = (uint) (context.NumberStatistics - numberMasked);
|
||||
numberMasked = context.NumberStatistics;
|
||||
do
|
||||
{
|
||||
characterMask[decodeStates[stateIndex].Symbol] = escapeCount;
|
||||
stateIndex++;
|
||||
} while (--index != 0);
|
||||
see2Context.Summary += (ushort)Coder.Scale;
|
||||
see2Context.Summary += (ushort) Coder.Scale;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,7 +568,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
private See2Context MakeEscapeFrequency(PpmContext context)
|
||||
{
|
||||
uint numberStatistics = (uint)2 * context.NumberStatistics;
|
||||
uint numberStatistics = (uint) 2*context.NumberStatistics;
|
||||
See2Context see2Context;
|
||||
|
||||
if (context.NumberStatistics != 0xff)
|
||||
@@ -555,7 +578,8 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
numberStatistics = context.Suffix.NumberStatistics;
|
||||
int index1 = probabilities[context.NumberStatistics + 2] - 3;
|
||||
int index2 = ((context.SummaryFrequency > 11 * (context.NumberStatistics + 1)) ? 1 : 0) + ((2 * context.NumberStatistics < numberStatistics + numberMasked) ? 2 : 0) + context.Flags;
|
||||
int index2 = ((context.SummaryFrequency > 11*(context.NumberStatistics + 1)) ? 1 : 0) +
|
||||
((2*context.NumberStatistics < numberStatistics + numberMasked) ? 2 : 0) + context.Flags;
|
||||
see2Context = see2Contexts[index1, index2];
|
||||
Coder.Scale = see2Context.Mean();
|
||||
}
|
||||
@@ -586,15 +610,15 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
state.Frequency += 4;
|
||||
context.SummaryFrequency += 4;
|
||||
escapeFrequency = (uint)(context.SummaryFrequency - state.Frequency);
|
||||
escapeFrequency = (uint) (context.SummaryFrequency - state.Frequency);
|
||||
adder = (orderFall != 0 || method > ModelRestorationMethod.Freeze) ? 1 : 0;
|
||||
state.Frequency = (byte)((state.Frequency + adder) >> 1);
|
||||
state.Frequency = (byte) ((state.Frequency + adder) >> 1);
|
||||
context.SummaryFrequency = state.Frequency;
|
||||
|
||||
do
|
||||
{
|
||||
escapeFrequency -= (++state).Frequency;
|
||||
state.Frequency = (byte)((state.Frequency + adder) >> 1);
|
||||
state.Frequency = (byte) ((state.Frequency + adder) >> 1);
|
||||
context.SummaryFrequency += state.Frequency;
|
||||
if (state[0].Frequency > state[-1].Frequency)
|
||||
{
|
||||
@@ -620,38 +644,39 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
} while ((--state).Frequency == 0);
|
||||
|
||||
escapeFrequency += index;
|
||||
oldUnitCount = (uint)((context.NumberStatistics + 2) >> 1);
|
||||
context.NumberStatistics -= (byte)index;
|
||||
oldUnitCount = (uint) ((context.NumberStatistics + 2) >> 1);
|
||||
context.NumberStatistics -= (byte) index;
|
||||
if (context.NumberStatistics == 0)
|
||||
{
|
||||
localSymbol = context.Statistics.Symbol;
|
||||
localFrequency = context.Statistics.Frequency;
|
||||
localSuccessor = context.Statistics.Successor;
|
||||
localFrequency = (byte)((2 * localFrequency + escapeFrequency - 1) / escapeFrequency);
|
||||
if (localFrequency > MaximumFrequency / 3)
|
||||
localFrequency = (byte)(MaximumFrequency / 3);
|
||||
localFrequency = (byte) ((2*localFrequency + escapeFrequency - 1)/escapeFrequency);
|
||||
if (localFrequency > MaximumFrequency/3)
|
||||
localFrequency = (byte) (MaximumFrequency/3);
|
||||
Allocator.FreeUnits(context.Statistics, oldUnitCount);
|
||||
context.FirstStateSymbol = localSymbol;
|
||||
context.FirstStateFrequency = localFrequency;
|
||||
context.FirstStateSuccessor = localSuccessor;
|
||||
context.Flags = (byte)((context.Flags & 0x10) + ((localSymbol >= 0x40) ? 0x08 : 0x00));
|
||||
context.Flags = (byte) ((context.Flags & 0x10) + ((localSymbol >= 0x40) ? 0x08 : 0x00));
|
||||
foundState = context.FirstState;
|
||||
return;
|
||||
}
|
||||
|
||||
context.Statistics = Allocator.ShrinkUnits(context.Statistics, oldUnitCount, (uint)((context.NumberStatistics + 2) >> 1));
|
||||
context.Statistics = Allocator.ShrinkUnits(context.Statistics, oldUnitCount,
|
||||
(uint) ((context.NumberStatistics + 2) >> 1));
|
||||
context.Flags &= 0xf7;
|
||||
index = context.NumberStatistics;
|
||||
state = context.Statistics;
|
||||
context.Flags |= (byte)((state.Symbol >= 0x40) ? 0x08 : 0x00);
|
||||
context.Flags |= (byte) ((state.Symbol >= 0x40) ? 0x08 : 0x00);
|
||||
do
|
||||
{
|
||||
context.Flags |= (byte)(((++state).Symbol >= 0x40) ? 0x08 : 0x00);
|
||||
context.Flags |= (byte) (((++state).Symbol >= 0x40) ? 0x08 : 0x00);
|
||||
} while (--index != 0);
|
||||
}
|
||||
|
||||
escapeFrequency -= (escapeFrequency >> 1);
|
||||
context.SummaryFrequency += (ushort)escapeFrequency;
|
||||
context.SummaryFrequency += (ushort) escapeFrequency;
|
||||
context.Flags |= 0x04;
|
||||
foundState = context.Statistics;
|
||||
}
|
||||
@@ -662,23 +687,24 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
int escapeFrequency;
|
||||
int scaleValue = (scale ? 1 : 0);
|
||||
|
||||
context.Statistics = Allocator.ShrinkUnits(context.Statistics, oldUnitCount, (uint)((index + 2) >> 1));
|
||||
context.Statistics = Allocator.ShrinkUnits(context.Statistics, oldUnitCount, (uint) ((index + 2) >> 1));
|
||||
PpmState statistics = context.Statistics;
|
||||
context.Flags = (byte)((context.Flags & (0x10 + (scale ? 0x04 : 0x00))) + ((statistics.Symbol >= 0x40) ? 0x08 : 0x00));
|
||||
context.Flags =
|
||||
(byte) ((context.Flags & (0x10 + (scale ? 0x04 : 0x00))) + ((statistics.Symbol >= 0x40) ? 0x08 : 0x00));
|
||||
escapeFrequency = context.SummaryFrequency - statistics.Frequency;
|
||||
statistics.Frequency = (byte)((statistics.Frequency + scaleValue) >> scaleValue);
|
||||
statistics.Frequency = (byte) ((statistics.Frequency + scaleValue) >> scaleValue);
|
||||
context.SummaryFrequency = statistics.Frequency;
|
||||
|
||||
do
|
||||
{
|
||||
escapeFrequency -= (++statistics).Frequency;
|
||||
statistics.Frequency = (byte)((statistics.Frequency + scaleValue) >> scaleValue);
|
||||
statistics.Frequency = (byte) ((statistics.Frequency + scaleValue) >> scaleValue);
|
||||
context.SummaryFrequency += statistics.Frequency;
|
||||
context.Flags |= (byte)((statistics.Symbol >= 0x40) ? 0x08 : 0x00);
|
||||
context.Flags |= (byte) ((statistics.Symbol >= 0x40) ? 0x08 : 0x00);
|
||||
} while (--index != 0);
|
||||
|
||||
escapeFrequency = (escapeFrequency + scaleValue) >> scaleValue;
|
||||
context.SummaryFrequency += (ushort)escapeFrequency;
|
||||
context.SummaryFrequency += (ushort) escapeFrequency;
|
||||
}
|
||||
|
||||
private PpmContext CutOff(int order, PpmContext context)
|
||||
@@ -689,7 +715,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
if (context.NumberStatistics == 0)
|
||||
{
|
||||
state = context.FirstState;
|
||||
if ((Pointer)state.Successor >= Allocator.BaseUnit)
|
||||
if ((Pointer) state.Successor >= Allocator.BaseUnit)
|
||||
{
|
||||
if (order < modelOrder)
|
||||
state.Successor = CutOff(order + 1, state.Successor);
|
||||
@@ -711,7 +737,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
}
|
||||
}
|
||||
|
||||
uint unitCount = (uint)((context.NumberStatistics + 2) >> 1);
|
||||
uint unitCount = (uint) ((context.NumberStatistics + 2) >> 1);
|
||||
context.Statistics = Allocator.MoveUnitsUp(context.Statistics, unitCount);
|
||||
index = context.NumberStatistics;
|
||||
for (state = context.Statistics + index; state >= context.Statistics; state--)
|
||||
@@ -729,7 +755,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
if (index != context.NumberStatistics && order != 0)
|
||||
{
|
||||
context.NumberStatistics = (byte)index;
|
||||
context.NumberStatistics = (byte) index;
|
||||
state = context.Statistics;
|
||||
if (index < 0)
|
||||
{
|
||||
@@ -739,14 +765,14 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
}
|
||||
else if (index == 0)
|
||||
{
|
||||
context.Flags = (byte)((context.Flags & 0x10) + ((state.Symbol >= 0x40) ? 0x08 : 0x00));
|
||||
context.Flags = (byte) ((context.Flags & 0x10) + ((state.Symbol >= 0x40) ? 0x08 : 0x00));
|
||||
Copy(context.FirstState, state);
|
||||
Allocator.FreeUnits(state, unitCount);
|
||||
context.FirstStateFrequency = (byte)((context.FirstStateFrequency + 11) >> 3);
|
||||
context.FirstStateFrequency = (byte) ((context.FirstStateFrequency + 11) >> 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
Refresh(unitCount, context.SummaryFrequency > 16 * index, context);
|
||||
Refresh(unitCount, context.SummaryFrequency > 16*index, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -758,11 +784,12 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
if (context.NumberStatistics == 0)
|
||||
{
|
||||
PpmState state = context.FirstState;
|
||||
if ((Pointer)state.Successor >= Allocator.BaseUnit && order < modelOrder)
|
||||
if ((Pointer) state.Successor >= Allocator.BaseUnit && order < modelOrder)
|
||||
state.Successor = RemoveBinaryContexts(order + 1, state.Successor);
|
||||
else
|
||||
state.Successor = PpmContext.Zero;
|
||||
if ((state.Successor == PpmContext.Zero) && (context.Suffix.NumberStatistics == 0 || context.Suffix.Flags == 0xff))
|
||||
if ((state.Successor == PpmContext.Zero) &&
|
||||
(context.Suffix.NumberStatistics == 0 || context.Suffix.Flags == 0xff))
|
||||
{
|
||||
Allocator.FreeUnits(context, 1);
|
||||
return PpmContext.Zero;
|
||||
@@ -775,7 +802,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
|
||||
for (PpmState state = context.Statistics + context.NumberStatistics; state >= context.Statistics; state--)
|
||||
{
|
||||
if ((Pointer)state.Successor >= Allocator.BaseUnit && order < modelOrder)
|
||||
if ((Pointer) state.Successor >= Allocator.BaseUnit && order < modelOrder)
|
||||
state.Successor = RemoveBinaryContexts(order + 1, state.Successor);
|
||||
else
|
||||
state.Successor = PpmContext.Zero;
|
||||
@@ -784,4 +811,4 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
return context;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,13 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// </summary>
|
||||
public Model.PpmContext Successor
|
||||
{
|
||||
get { return new Model.PpmContext(((uint) Memory[Address + 2]) | ((uint) Memory[Address + 3]) << 8 | ((uint) Memory[Address + 4]) << 16 | ((uint) Memory[Address + 5]) << 24, Memory); }
|
||||
get
|
||||
{
|
||||
return
|
||||
new Model.PpmContext(
|
||||
((uint) Memory[Address + 2]) | ((uint) Memory[Address + 3]) << 8 |
|
||||
((uint) Memory[Address + 4]) << 16 | ((uint) Memory[Address + 5]) << 24, Memory);
|
||||
}
|
||||
set
|
||||
{
|
||||
Memory[Address + 2] = (byte) value.Address;
|
||||
@@ -76,7 +82,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public PpmState this[int offset]
|
||||
{
|
||||
get { return new PpmState((uint) (Address + offset * Size), Memory); }
|
||||
get { return new PpmState((uint) (Address + offset*Size), Memory); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -97,7 +103,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static PpmState operator +(PpmState state, int offset)
|
||||
{
|
||||
state.Address = (uint) (state.Address + offset * Size);
|
||||
state.Address = (uint) (state.Address + offset*Size);
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -120,7 +126,7 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
/// <returns></returns>
|
||||
public static PpmState operator -(PpmState state, int offset)
|
||||
{
|
||||
state.Address = (uint) (state.Address - offset * Size);
|
||||
state.Address = (uint) (state.Address - offset*Size);
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -203,4 +209,4 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
return Address.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,4 +52,4 @@ namespace SharpCompress.Compressor.PPMd.I1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ namespace SharpCompress.Compressor.PPMd
|
||||
ushort props = BitConverter.ToUInt16(properties, 0);
|
||||
AllocatorSize = (((props >> 4) & 0xff) + 1) << 20;
|
||||
ModelOrder = (props & 0x0f) + 1;
|
||||
ModelRestorationMethod = (I1.ModelRestorationMethod)(props >> 12);
|
||||
ModelRestorationMethod = (I1.ModelRestorationMethod) (props >> 12);
|
||||
}
|
||||
else if (properties.Length == 5)
|
||||
{
|
||||
@@ -54,10 +54,7 @@ namespace SharpCompress.Compressor.PPMd
|
||||
|
||||
public int AllocatorSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return allocatorSize;
|
||||
}
|
||||
get { return allocatorSize; }
|
||||
set
|
||||
{
|
||||
allocatorSize = value;
|
||||
@@ -74,8 +71,11 @@ namespace SharpCompress.Compressor.PPMd
|
||||
{
|
||||
get
|
||||
{
|
||||
return BitConverter.GetBytes((ushort)((ModelOrder - 1) + (((AllocatorSize >> 20) - 1) << 4) + ((ushort)ModelRestorationMethod << 12)));
|
||||
return
|
||||
BitConverter.GetBytes(
|
||||
(ushort)
|
||||
((ModelOrder - 1) + (((AllocatorSize >> 20) - 1) << 4) + ((ushort) ModelRestorationMethod << 12)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,14 +84,8 @@ namespace SharpCompress.Compressor.PPMd
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return position;
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
get { return position; }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
@@ -106,7 +100,7 @@ namespace SharpCompress.Compressor.PPMd
|
||||
int c;
|
||||
while (size < count && (c = modelH.decodeChar()) >= 0)
|
||||
{
|
||||
buffer[offset++] = (byte)c;
|
||||
buffer[offset++] = (byte) c;
|
||||
size++;
|
||||
}
|
||||
}
|
||||
@@ -115,7 +109,7 @@ namespace SharpCompress.Compressor.PPMd
|
||||
int c;
|
||||
while (size < count && (c = modelH.decodeChar(decoder)) >= 0)
|
||||
{
|
||||
buffer[offset++] = (byte)c;
|
||||
buffer[offset++] = (byte) c;
|
||||
size++;
|
||||
}
|
||||
}
|
||||
@@ -139,4 +133,4 @@ namespace SharpCompress.Compressor.PPMd
|
||||
model.EncodeBlock(stream, new MemoryStream(buffer, offset, count), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user