public static void WriteDictionary(FrequencyDictionary <int> toWrite, BitWriter writerOut)
        {
            writerOut.WriteLong(toWrite.ContainedElements.Count, 16);
            int largestBitsNumerator = 0;
            int largestBitsSymbol    = 0;

            foreach (FrequencyStorage <int> storage in toWrite.ContainedElements)
            {
                int numeratorBits = CalculateContainedBits(storage.Frequency);
                if (numeratorBits > largestBitsNumerator)
                {
                    largestBitsNumerator = numeratorBits;
                }
                int symbolBits = CalculateContainedBits(storage.ContainedObject);
                if (symbolBits > largestBitsSymbol)
                {
                    largestBitsSymbol = symbolBits;
                }
            }
            writerOut.WriteLong(largestBitsNumerator - 1, 7);
            writerOut.WriteLong(largestBitsSymbol - 1, 7);
            foreach (FrequencyStorage <int> storage in toWrite.ContainedElements)
            {
                writerOut.WriteLong(storage.ContainedObject, (byte)largestBitsSymbol);
                writerOut.WriteLong(storage.Frequency, (byte)largestBitsNumerator);
            }
        }
        public static FrequencyDictionary <int> ReadDictionary(BitReader readerIn)
        {
            FrequencyDictionary <int> ret = new FrequencyDictionary <int>();
            int numElements          = readerIn.ReadInt(16);
            int largestNumeratorBits = readerIn.ReadInt(7) + 1;
            int largestSymbolBits    = readerIn.ReadInt(7) + 1;

            for (int i = 0; i < numElements; i++)
            {
                int symbol    = readerIn.ReadInt(largestSymbolBits);
                int frequency = readerIn.ReadInt(largestNumeratorBits);
                for (int j = 0; j < frequency; j++)
                {
                    ret.AddData(symbol);
                }
            }
            return(ret);
        }