imgtools/imglib/compress/byte_pair.h
author Mike Kinghan <mikek@symbian.org>
Wed, 01 Dec 2010 12:02:41 +0000
changeset 42 cf609178ac39
parent 2 39c28ec933dd
permissions -rwxr-xr-x
1) fix_tools_exports.pl need only be run on Windows hosts; was run unnecessarily on Linux too. 2) Need to export modload.pm on Linux as well as Windows hosts.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
     1
/*
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
     2
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
     3
* All rights reserved.
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
     4
* This component and the accompanying materials are made available
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
     6
* which accompanies this distribution, and is available
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
     8
*
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
     9
* Initial Contributors:
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    11
*
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    12
* Contributors:
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    13
*
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    14
* Description: 
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    15
*
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    16
*/
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    17
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    18
#ifndef BYTE_PAIR_H
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    19
#define BYTE_PAIR_H
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    20
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    21
#ifdef __VC32__
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    22
 #ifdef __MSVCDOTNET__
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    23
  #include <strstream>
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    24
  #include <iomanip>
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    25
 #else //!__MSVCDOTNET__
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    26
  #include <strstrea.h>
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    27
  #include <iomanip.h>
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    28
 #endif //__MSVCDOTNET__
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    29
#else // !__VC32__
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    30
#ifdef __TOOLS2__ 
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    31
#include <sstream>
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    32
#include <iomanip>
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    33
#include <iostream>
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    34
using namespace std;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    35
#else
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    36
 #include <strstream.h>
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    37
 #include <iomanip.h>
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    38
 #endif
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    39
#endif // __VC32__
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    40
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    41
//#include <myassert.h>
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    42
//#define DEBUG_ASSERT
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    43
#ifdef DEBUG_ASSERT
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    44
void myassert(int c);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    45
#else
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    46
#define myassert(c) 
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    47
#endif
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    48
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    49
#include <e32cmn.h> 
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    50
typedef struct {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    51
    TUint16 Count;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    52
    TUint16 Index; 
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    53
} TPairCountIndex;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    54
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    55
typedef struct {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    56
    TUint16 Pair;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    57
    TUint16 Next;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    58
    TUint16 Prev;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    59
    TUint16 Pos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    60
} TPair;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    61
typedef struct {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    62
    TUint16 Pos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    63
    TUint16 Next;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    64
} TPos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    65
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    66
const TInt MaxBlockSize = 0x1000;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    67
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    68
const TUint16 PosEnd = 0xffff;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    69
const TUint16 PosHead = 0xfffe;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    70
const TUint8 ByteRemoved = 'R';
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    71
const TUint8 ByteMarked = 'M';
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    72
const TUint8 ByteHead = 'H';
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    73
const TUint8 ByteTail = 'T';
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    74
const TUint8 ByteNew = 'N';
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    75
class CBytePair {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    76
    private:
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    77
        TBool   iFastCompress;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    78
        TInt    marker;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    79
        TUint8  Mask[MaxBlockSize];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    80
        TUint16 ByteCount[0x100];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    81
        TUint16 ByteIndex[0x100];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    82
        TUint16 BytePos[MaxBlockSize];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    83
        TPairCountIndex PairCount[0x10000];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    84
        TPair   PairBuffer[MaxBlockSize*2];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    85
        TInt    PairBufferNext;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    86
        TPos    PairPos[MaxBlockSize*3];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    87
        TUint16 PairPosNext;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    88
        TUint16 PairLists[MaxBlockSize/2+2];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    89
        TInt    PairListHigh;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    90
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    91
        void CountBytes(TUint8* data, TInt size) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    92
            TUint32 *p;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    93
            p = (TUint32*)ByteCount;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    94
            while (p < (TUint32*)ByteCount + sizeof(ByteCount)/4) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    95
                *p++ = 0;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    96
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    97
            p = (TUint32*)ByteIndex;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    98
            while (p < (TUint32*)ByteIndex + sizeof(ByteIndex)/4) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
    99
                *p++ = 0xffffffff;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   100
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   101
            p = (TUint32*)BytePos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   102
            while (p< (TUint32*)BytePos + sizeof(BytePos)/4) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   103
                *p++ = 0xffffffff;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   104
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   105
            TUint8* dataEnd = data+size;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   106
            int pos = 0;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   107
            while(data<dataEnd) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   108
                BytePos[pos] = ByteIndex[*data];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   109
                ByteIndex[*data] = (TUint16)pos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   110
                pos ++;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   111
                ++ByteCount[*data++];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   112
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   113
        }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   114
        inline void ByteUsed(TInt b) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   115
            ByteCount[b] = 0xffff;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   116
        }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   117
        int TieBreak(int b1,int b2) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   118
            return -ByteCount[b1]-ByteCount[b2];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   119
        }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   120
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   121
        void Initialize(TUint8* data, TInt size);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   122
        TInt MostCommonPair(TInt& pair);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   123
        TInt LeastCommonByte(TInt& byte);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   124
        inline void InsertPair(const TUint16 pair, const TUint16 pos) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   125
            //ClockInsert1 = clock();
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   126
            //cout << "Pair:" << hex << setw(4) << setfill ('0') << pair << endl;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   127
            TUint16 count = PairCount[pair].Count;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   128
            if (0==count) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   129
                PairCount[pair].Index = (TUint16)PairBufferNext;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   130
                if (PairLists[1] != PosEnd) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   131
                    PairBuffer[PairLists[1]].Prev = (TUint16)PairBufferNext;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   132
                }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   133
                PairBuffer[PairBufferNext].Next = PairLists[1];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   134
                PairBuffer[PairBufferNext].Prev = PosHead;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   135
                PairLists[1] = (TUint16)PairBufferNext;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   136
                PairBuffer[PairBufferNext].Pair = pair;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   137
                PairBuffer[PairBufferNext].Pos = PairPosNext;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   138
                PairBufferNext ++;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   139
                myassert(PairBufferNext < MaxBlockSize*2);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   140
                PairPos[PairPosNext].Pos = pos; 
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   141
                PairPos[PairPosNext].Next = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   142
            } else {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   143
                TUint16 index = PairCount[pair].Index;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   144
               
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   145
                if (PairBuffer[index].Next == PosEnd){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   146
                    if (PairBuffer[index].Prev == PosHead){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   147
                        PairLists[count] = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   148
                    } else {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   149
                        PairBuffer[PairBuffer[index].Prev].Next = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   150
                    }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   151
                } else {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   152
                    if (PairBuffer[index].Prev == PosHead){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   153
                        PairLists[count] = PairBuffer[index].Next;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   154
                        PairBuffer[PairBuffer[index].Next].Prev = PosHead;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   155
                    } else {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   156
                        PairBuffer[PairBuffer[index].Prev].Next = PairBuffer[index].Next;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   157
                        PairBuffer[PairBuffer[index].Next].Prev = PairBuffer[index].Prev;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   158
                    }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   159
                }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   160
                
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   161
                if (PairLists[count+1] != PosEnd){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   162
                    PairBuffer[PairLists[count+1]].Prev = index;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   163
                    PairBuffer[index].Next = PairLists[count+1];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   164
                    PairBuffer[index].Prev = PosHead;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   165
                    PairLists[count+1] = index;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   166
                }else{
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   167
                    PairLists[count+1] = index;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   168
                    PairBuffer[index].Next = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   169
                    PairBuffer[index].Prev = PosHead;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   170
                }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   171
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   172
                PairPos[PairPosNext].Pos = pos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   173
                PairPos[PairPosNext].Next = PairBuffer[index].Pos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   174
                PairBuffer[index].Pos = PairPosNext;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   175
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   176
            PairPosNext ++;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   177
            
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   178
            myassert(PairPosNext < MaxBlockSize*3);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   179
            PairCount[pair].Count ++;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   180
            if (PairCount[pair].Count > PairListHigh) 
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   181
                PairListHigh = PairCount[pair].Count; 
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   182
        }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   183
        inline void RemovePair(const TUint16 pair, const TUint16 pos){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   184
            //ClockRemove1 = clock();
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   185
            TUint16 count = PairCount[pair].Count;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   186
            TUint16 index = PairCount[pair].Index;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   187
            if (count == 1 ) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   188
                PairCount[pair].Count = 0;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   189
                PairCount[pair].Index = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   190
                return;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   191
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   192
            
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   193
            myassert(index != PosEnd);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   194
            TUint16 *posnextp = &PairBuffer[index].Pos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   195
            while (*posnextp != PosEnd){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   196
                if (PairPos[*posnextp].Pos == pos)
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   197
                    break;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   198
                posnextp = &PairPos[*posnextp].Next;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   199
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   200
            myassert(*posnextp != PosEnd);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   201
            *posnextp = PairPos[*posnextp].Next;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   202
            
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   203
            if (PairBuffer[index].Next == PosEnd){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   204
                if (PairBuffer[index].Prev == PosHead){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   205
                    PairLists[count] = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   206
                } else {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   207
                    PairBuffer[PairBuffer[index].Prev].Next = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   208
                }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   209
            } else {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   210
                if (PairBuffer[index].Prev == PosHead){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   211
                    PairLists[count] = PairBuffer[index].Next;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   212
                    PairBuffer[PairBuffer[index].Next].Prev = PosHead;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   213
                } else {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   214
                    PairBuffer[PairBuffer[index].Prev].Next = PairBuffer[index].Next;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   215
                    PairBuffer[PairBuffer[index].Next].Prev = PairBuffer[index].Prev;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   216
                }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   217
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   218
            myassert(PairCount[pair].Count > 0);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   219
            PairCount[pair].Count --;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   220
            if (PairCount[pair].Count == 0)
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   221
                PairCount[pair].Index = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   222
            
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   223
            count = PairCount[pair].Count;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   224
            if (count > 0) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   225
                if (PairLists[count] != PosEnd){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   226
                    PairBuffer[PairLists[count]].Prev = index;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   227
                    PairBuffer[index].Next = PairLists[count];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   228
                    PairBuffer[index].Prev = PosHead;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   229
                    PairLists[count] = index;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   230
                }else{
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   231
                    PairLists[count] = index;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   232
                    PairBuffer[index].Next = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   233
                    PairBuffer[index].Prev = PosHead;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   234
                }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   235
            }            
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   236
            while (PairLists[PairListHigh] == PosEnd) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   237
                PairListHigh --;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   238
            }             
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   239
        }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   240
        inline void GetPairBackward (TUint8 *data, TUint16 pos, TUint16 &pairpos, TUint16 &pair) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   241
            myassert(pos <MaxBlockSize);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   242
            myassert(Mask[pos] != ByteMarked);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   243
            myassert(Mask[pos] != ByteRemoved);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   244
            TUint8 b = data[pos];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   245
            if (pos == 0) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   246
                pair = 0;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   247
                pairpos = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   248
                return;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   249
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   250
            pos --;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   251
            while ((pos>0) && (Mask[pos] == ByteRemoved)){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   252
                pos --;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   253
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   254
            if ((Mask[pos] == ByteRemoved) || (Mask[pos] == ByteMarked)) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   255
                pair = 0;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   256
                pairpos = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   257
            } else {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   258
                pair = (TUint16)((b << 8) | data[pos]);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   259
                pairpos = pos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   260
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   261
        }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   262
        
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   263
        inline void GetPairForward (TUint8 *data, TUint16 pos, TInt size, TUint16 &pairpos, TUint16 &pair) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   264
            myassert(Mask[pos] != ByteMarked);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   265
            myassert(Mask[pos] != ByteRemoved);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   266
            myassert(pos < size);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   267
            TUint8 b = data[pos];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   268
            pairpos = pos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   269
            pos ++;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   270
            while ((pos < size) && (Mask[pos] == ByteRemoved))
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   271
                pos++;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   272
            if ((pos == size) || (Mask[pos] == ByteMarked)) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   273
                pair = 0;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   274
                pairpos = PosEnd;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   275
            } else {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   276
                pair = (TUint16)(b | (data[pos] << 8));
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   277
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   278
        }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   279
#ifdef  __TOOLS2__        
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   280
        void DumpList(TUint8 *data, TInt size) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   281
            int i, j;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   282
            cout << "src: " << dec << size << " bytes"<< endl;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   283
            for (i=0;i<size;i+=16){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   284
                cout << endl;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   285
                cout << hex;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   286
                cout << setfill('0') << setw(4) << right << i << " ";
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   287
                for (j=0;j<16;j++) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   288
                    cout << setfill ('0') << setw(2) << right << (unsigned int)data[i+j] << " ";
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   289
                }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   290
                cout << "    ";
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   291
                for (j=0;j<16;j++) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   292
                    char c = isgraph(data[i+j]) ? data[i+j]:'.';
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   293
                    cout << c;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   294
                }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   295
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   296
            cout << endl;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   297
            
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   298
            for (i=0;i<256;i+=16){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   299
                cout << endl << hex << setfill('0') << setw(2) <<right <<i << " ";
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   300
                for (j=0;j<16;j++) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   301
                    cout << setfill ('0') << setw(4) << right << (unsigned int)ByteIndex[i+j] << " ";
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   302
                }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   303
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   304
            cout << endl;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   305
            for (i=0;i<256;i++){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   306
                cout << "Byte: <" << i << "> Count: " << ByteCount[i];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   307
                TUint16 pos = ByteIndex[i];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   308
                int j = 0;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   309
                while (pos != PosEnd){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   310
                    if (j++ % 16 == 0)
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   311
                        cout << endl << "    ";
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   312
                    cout << hex << setw(4) << setfill('0') << pos << " ";
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   313
                    pos = BytePos[pos];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   314
                }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   315
                cout << endl;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   316
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   317
            cout << "buffer lists" << endl;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   318
            for (i=PairListHigh; i>=0; i--){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   319
                TUint16 index = PairLists[i];
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   320
                if (index == PosEnd)
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   321
                    continue;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   322
                cout << dec;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   323
                cout << "List " << i << endl;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   324
                while (index != PosEnd){ 
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   325
                    char b0 = (char)PairBuffer[index].Pair;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   326
                    char b1 = (char)(PairBuffer[index].Pair >> 8);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   327
                    cout << "    " << setw(4) << setfill('0') << hex << PairBuffer[index].Pair << " " << "<" << (isgraph(b1)? b1:'.') << (isgraph(b0) ? b0 : '.') << ">";  
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   328
                    TUint16 pos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   329
                    pos = PairBuffer[index].Pos;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   330
                    int k = 0;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   331
                    while (pos != PosEnd){
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   332
                        if (k%16 ==0) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   333
                            cout << endl << "        ";
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   334
                        };
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   335
                        cout << setw(4) << setfill('0') << PairPos[pos].Pos << " ";
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   336
                        k ++;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   337
                        pos = PairPos[pos].Next;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   338
                    }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   339
                    cout << endl;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   340
                    index = PairBuffer[index].Next;
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   341
                }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   342
                
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   343
            }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   344
        }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   345
#endif
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   346
	public:
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   347
        CBytePair(TBool fastCompress) {
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   348
            iFastCompress = fastCompress; 
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   349
        }
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   350
        TInt Compress(TUint8* dst, TUint8* src, TInt size);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   351
        TInt Decompress(TUint8* dst, TInt dstSize, TUint8* src, TInt srcSize, TUint8*& srcNext);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   352
};
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   353
TInt BytePairCompress(TUint8* dst, TUint8* src, TInt size, CBytePair *aBPE);
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   354
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   355
#endif
39c28ec933dd Removing all prior files. Adding a complete branch of the 'build' package with fixes
mikek
parents:
diff changeset
   356