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); } }
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; }