コード例 #1
0
        //public void SaveToFile(string FileName)
        //{
        //    int counter = 0;
        //    foreach (int key in TermIndex.Keys)
        //    {
        //        string comma = (counter == TermIndex.Count - 1) ? "" : ",";
        //        counter++;
        //        File.AppendAllText(FileName, String.Format("({0},{1}){2}", key, TermIndex[key], comma));
        //    }
        //}

        public string ToStringWithCompress()
        {
            GammaEliasCoding.BufferEncoder encoder = new GammaEliasCoding.BufferEncoder();

            ForwardConversion(TermIndex.Keys.ToList()).ForEach(d => encoder.Append(d));
            TermIndex.Values.ToList().ForEach(d => encoder.Append(d));

            byte [] bytes = encoder.GetByteArray();
            string  s     = bytes.ToList().Select(b => Convert.ToChar(b).ToString()).Aggregate((l, r) => l + r);

            s = bytes.Length + ":" + s;

            return(s);
        }
コード例 #2
0
        public void SaveCompressedToFile(FileStream fs)
        {
            GammaEliasCoding.BufferEncoder encoder = new GammaEliasCoding.BufferEncoder();

            ForwardConversion(TermIndex.Keys.ToList()).ForEach(d => encoder.Append(d));
            TermIndex.Values.ToList().ForEach(d => encoder.Append(d));

            byte [] bytes = encoder.GetByteArray();

            Encoding.UTF8.GetBytes(bytes.Length.ToString()).ToList().ForEach(ch => fs.WriteByte(Convert.ToByte(ch)));

            fs.WriteByte(Convert.ToByte(':'));

            foreach (byte b in bytes)
            {
                fs.WriteByte(b);
            }
        }