This commit is contained in:
Igor Pavlov
2017-04-30 00:00:00 +00:00
committed by Kornel
parent 603abd5528
commit 2efa10565a
442 changed files with 15479 additions and 8525 deletions

View File

@@ -11,11 +11,11 @@ struct CMtf8Encoder
{
Byte Buf[256];
unsigned FindAndMove(Byte v)
unsigned FindAndMove(Byte v) throw()
{
unsigned pos;
size_t pos;
for (pos = 0; Buf[pos] != v; pos++);
unsigned resPos = pos;
unsigned resPos = (unsigned)pos;
for (; pos >= 8; pos -= 8)
{
Buf[pos] = Buf[pos - 1];
@@ -39,9 +39,10 @@ struct CMtf8Decoder
{
Byte Buf[256];
void Init(int) {};
void StartInit() { memset(Buf, 0, sizeof(Buf)); }
void Add(unsigned pos, Byte val) { Buf[pos] = val; }
Byte GetHead() const { return Buf[0]; }
Byte GetAndMove(int pos)
Byte GetAndMove(unsigned pos)
{
Byte res = Buf[pos];
for (; pos >= 8; pos -= 8)
@@ -64,11 +65,11 @@ struct CMtf8Decoder
*/
#ifdef MY_CPU_64BIT
typedef UInt64 CMtfVar;
#define MTF_MOVS 3
typedef UInt64 CMtfVar;
#define MTF_MOVS 3
#else
typedef UInt32 CMtfVar;
#define MTF_MOVS 2
typedef UInt32 CMtfVar;
#define MTF_MOVS 2
#endif
#define MTF_MASK ((1 << MTF_MOVS) - 1)
@@ -81,13 +82,18 @@ struct CMtf8Decoder
void StartInit() { memset(Buf, 0, sizeof(Buf)); }
void Add(unsigned pos, Byte val) { Buf[pos >> MTF_MOVS] |= ((CMtfVar)val << ((pos & MTF_MASK) << 3)); }
Byte GetHead() const { return (Byte)Buf[0]; }
Byte GetAndMove(unsigned pos)
MY_FORCE_INLINE
Byte GetAndMove(unsigned pos) throw()
{
UInt32 lim = ((UInt32)pos >> MTF_MOVS);
pos = (pos & MTF_MASK) << 3;
CMtfVar prev = (Buf[lim] >> pos) & 0xFF;
UInt32 i = 0;
/*
if ((lim & 1) != 0)
{
CMtfVar next = Buf[0];
@@ -104,6 +110,16 @@ struct CMtf8Decoder
Buf[i + 1] = (n1 << 8) | (n0 >> (MTF_MASK << 3));
prev = (n1 >> (MTF_MASK << 3));
}
*/
for (; i < lim; i++)
{
CMtfVar n0 = Buf[i];
Buf[i ] = (n0 << 8) | prev;
prev = (n0 >> (MTF_MASK << 3));
}
CMtfVar next = Buf[i];
CMtfVar mask = (((CMtfVar)0x100 << pos) - 1);
Buf[i] = (next & ~mask) | (((next << 8) | prev) & mask);
@@ -117,7 +133,7 @@ class CMtf8Decoder
{
Byte SmallBuffer[kSmallSize];
int SmallSize;
Byte Counts[16];
int Counts[16];
int Size;
public:
Byte Buf[256];
@@ -140,6 +156,11 @@ public:
}
}
void Add(unsigned pos, Byte val)
{
Buf[pos] = val;
}
Byte GetAndMove(int pos)
{
if (pos < SmallSize)