예제 #1
0
        protected List <Pair <char, int> > GetListOfPairs(string text)
        {
            var res     = new List <Pair <char, int> >();
            var root    = new LzNode(0);
            var curNode = root;
            var index   = 0;
            var nodeCnt = 1;

            while (index < text.Length)
            {
                if (curNode.ContainsNextSymbol(text[index]))
                {
                    curNode = curNode[text[index]];
                    index++;
                    continue;
                }

                res.Add(new Pair <char, int>(text[index], curNode.NodeNumber));

                if (nodeCnt < DictionaryCapacity)
                {
                    curNode.Add(text[index], new LzNode(nodeCnt));
                    nodeCnt++;
                }

                index++;
                curNode = root;
            }
            res.Add(new Pair <char, int>('\0', curNode.NodeNumber));

            return(res);
        }
예제 #2
0
        void UnpackLz(byte[] output)
        {
            var tree       = new LzNode[0x10000];
            int node_count = 0;
            int dst        = 0;
            int ctl        = 1;

            while (dst < output.Length)
            {
                if (1 == ctl)
                {
                    ctl = m_input.ReadUInt8() | 0x100;
                }
                int count = 0;
                if ((ctl & 1) != 0)
                {
                    int index;
                    if (node_count < 0x100)
                    {
                        index = m_input.ReadUInt8();
                    }
                    else
                    {
                        index = m_input.ReadUInt16();
                    }

                    count = tree[index].Length;
                    Buffer.BlockCopy(output, tree[index].Offset, output, dst, count);
                }
                int symbol = m_input.ReadByte();
                if (-1 == symbol)
                {
                    break;
                }
                output[dst + count++] = (byte)symbol;
                if (node_count < tree.Length)
                {
                    tree[node_count].Offset = dst;
                    tree[node_count].Length = count;
                    ++node_count;
                }
                dst  += count;
                ctl >>= 1;
            }
        }
예제 #3
0
 public void Add(char symbol, LzNode node)
 {
     _nextLzNodes.Add(symbol, node);
 }