public void EncodeData(IFactory factory, IDataSource istream, IDataProccess ostream, IFreqTableBuilder table) { while (!istream.IsFinished()) { table.AddByte(istream.GetNext()); } istream.Reset(); var tree = table.Create(); var root = tree.CreateRoot(); ostream.OutString(tree.OutTable().ToString()); var list = factory.CreateEncode(); while (!istream.IsFinished()) { list = root.Encode(istream.GetNext()); while (list.Count() >= BYTELENGHT) { ostream.OutByte(list.ConverToByte(BYTELENGHT)); } } var listCount = ( byte )list.Count(); if (listCount == 0) { return; } ostream.OutByte(list.ConverToByte(listCount)); ostream.Reset(); ostream.OutString(listCount.ToString(CultureInfo.InvariantCulture)); }
public void Decode(bool bit, IDataProccess stream) { if (!IsLeaf(_current.Decode(bit))) { return; } stream.OutByte(_current.Get()); _current.Set(Root); }
public void EncodeData(IFactory factory, IDataSource istream, IDataProccess ostream, IFreqTableBuilder table) { while ( !istream.IsFinished() ) { table.AddByte( istream.GetNext() ); } istream.Reset(); var tree = table.Create(); var root = tree.CreateRoot(); ostream.OutString( tree.OutTable().ToString() ); var list = factory.CreateEncode(); while ( !istream.IsFinished() ) { list = root.Encode( istream.GetNext() ); while ( list.Count() >= BYTELENGHT ) ostream.OutByte( list.ConverToByte( BYTELENGHT ) ); } var listCount = ( byte ) list.Count(); if (listCount == 0) return; ostream.OutByte( list.ConverToByte( listCount ) ); ostream.Reset(); ostream.OutString( listCount.ToString(CultureInfo.InvariantCulture) ); }