コード例 #1
0
        public void Encode(byte value)
        {
            if (currentNode.ContainsValue(value))
            {
                currentNode = currentNode.GetChild(value);
            }
            else
            {
                LZWNode child = new LZWNode(value, nextNodeValue);
                currentNode.AddChild(child);
                allNodes[nextNodeValue] = child;
                encoder.Encode(currentNode.identifier);
                currentNode.AddUsage();
                encoder.AddValue(nextNodeValue);
                IncreaseNextNodeValue();

                currentNode = root.GetChild(value);
            }
        }
コード例 #2
0
        public LZW(IEncoder encoder)
        {
            this.encoder = encoder;
            this.root    = new LZWNode(0, 0);
            this.buffer  = new Stack <byte>();
            allNodes     = new Dictionary <long, LZWNode>();

            for (int i = 0; i <= 255; i++)
            {
                LZWNode child = new LZWNode((byte)i, i);
                root.AddChild(child);
                allNodes[i] = child;
            }
            currentNode = this.root;
        }