public void CompressTick(TickBinary tick, MemoryStream memory)
        {
            tickIO.Inject(tick);
            byte[] output = memory.GetBuffer();
            int    length = (int)memory.Length;

            CompareTick(tickIO);
            if (count < 100)
            {
                CopyMemory(output, out length);
            }
            else
            {
                CalculateDifference(current.Bytes, previous.Bytes, current.Length);
                WriteMemory(output, out length);

                if (shortValueCompression)
                {
                    // Frequency of individual short values
                    for (int i = 0; i < length - 1; i++)
                    {
                        int       intValue = (int)(output[i] | (output[i + 1] << 8));
                        ByteCount bc       = shortValueCounts[intValue];
                        shortValueCounts[intValue] = new ByteCount(intValue, bc.Count + 1);
                    }
                }
            }
            SwapBuffers();
            count++;
            if (count % 100 == 0)
            {
                CreateSignature(); ResetCounters();
            }
        }
 public TickImpl DecompressTick(BinaryReader reader)
 {
     if (count < 100)
     {
         CompareTick(reader);
     }
     else
     {
         ReadMemory(reader);
         current.Reset();
         ReverseDifference(current.Bytes, previous.Bytes, previous.Length);
         CompareMemory(current.Bytes, previous.Bytes, previous.Length);
         CompareTick(current.Reader);
         if (shortValueCompression)
         {
             // Frequency of individual short values
             for (int i = 0; i < previous.Length; i++)
             {
                 int       intValue = (int)(current.Bytes[i] | (current.Bytes[i + 1] << 8));
                 ByteCount bc       = shortValueCounts[intValue];
                 shortValueCounts[intValue] = new ByteCount(intValue, bc.Count + 1);
             }
         }
     }
     SwapBuffers();
     count++;
     if (count % 100 == 0)
     {
         CreateSignature(); ResetCounters();
     }
     return(currentTick);
 }
        private void CompareMemory(byte[] memory, byte[] previous, long length)
        {
            int counter = 0;

            for (int i = 0; i < length; i++)
            {
                if (memory[i] != previous[i])
                {
                    ByteCount value;
                    if (byteCounts.TryGetValue(i, out value))
                    {
                        byteCounts[i] = new ByteCount(i, byteCounts[i].Count + 1);
                    }
                    else
                    {
                        byteCounts.Add(i, new ByteCount(i, 1));
                    }
                    counter++;
                }
            }
            maxLength = (int)Math.Max(maxLength, length);
        }