Пример #1
0
 public AnsState(int capacity, ReversedMemoryStream outputStream, uint initialState)
 {
     Underlying = initialState;
     Capacity   = capacity;
     //Contained = Capacity;
     Output   = outputStream;
     BitStack = new BitStack();
 }
        private void WriteEncoding(int blockContentLength, AnsCodingTable blockTable)
        {
            ReversedMemoryStream reversedStream = new ReversedMemoryStream();
            uint     initialState = ConstructMask(blockTable.Denominator);
            AnsState stateIn      = new AnsState(MaskBits, reversedStream, initialState);

            for (int i = 0; i < blockContentLength; i++)
            {
                int row       = stateIn.ToInt();
                int symbol    = Block[i];
                var validRows = blockTable[symbol];
                while (!validRows.ContainsKey(row))
                {
                    stateIn.PopLower();
                    row = stateIn.ToInt();
                }
                stateIn.Underlying = (uint)validRows[row];
            }
            stateIn.Flush();
            reversedStream.ReadToStream(Output);
        }