public void Compress()
        {
            int  run = 0;
            bool old = false;

            while (!input.IsEmpty)
            {
                bool b = input.ReadBoolean();
                if (b != old)
                {
                    output.Write(run, LG_R);
                    run = 1;
                    old = !old;
                }
                else
                {
                    if (run == R - 1)
                    {
                        output.Write(run, LG_R);
                        run = 0;
                        output.Write(run, LG_R);
                    }
                    run++;
                }
            }
            output.Write(run, LG_R);
            output.Close();
        }
Example #2
0
        public void Compress()
        {
            string s = input.ReadString();
            int    N = s.Length;

            output.Write(N);

            // Write two-bit code for char.
            for (int i = 0; i < N; i++)
            {
                int d = Alphabet.Dna.ToIndex(s[i]);
                output.Write(d, 2);
            }
            output.Close();
            input.Close();
        }