示例#1
0
 public EnhancedParsingTable(IEnumerable <string> titles, ulong defaultValue)
 {
     foreach (var v in titles)
     {
         this[v] = new CompressionList <ulong>(defaultValue);
     }
 }
示例#2
0
        public static CompressionList <T> GetBestCompressionOf <T>(List <T> listToCompress, int sizeOfTStructure)
        {
            CompressionList <T> best = GetCompressionClass <T>(CompressionType.NoCompression);

            best.Compress(listToCompress);

            CompressionList <T> contender1 = GetCompressionClass <T>(CompressionType.ConstantCompression);

            contender1.Compress(listToCompress);

            if (contender1.GetApproxSizeInBytes(sizeOfTStructure) < best.GetApproxSizeInBytes(sizeOfTStructure))
            {
                best = contender1;
            }

            CompressionList <T> contender2 = GetCompressionClass <T>(CompressionType.LinearCompression);

            contender2.Compress(listToCompress);

            if (contender2.GetApproxSizeInBytes(sizeOfTStructure) < best.GetApproxSizeInBytes(sizeOfTStructure))
            {
                best = contender2;
            }

            //Console.WriteLine("Best compression method: " + best.GetType().Name + ", "
            //	+ (sizeOfTStructure * listToCompress.Count) + " to " + best.GetApproxSizeInBytes(sizeOfTStructure));

            return(best);
        }
示例#3
0
        /* utility methods */
        public byte[] GetBytes()
        {
            byte[] result = new byte[this.GetLength()];
            int    offset = 0;

            System.Buffer.BlockCopy(version.GetBytes(), 0, result, offset, version.Length);
            offset += version.Length;

            System.Buffer.BlockCopy(random.GetBytes(), 0, result, offset, RandomUnit.Length);
            offset += RandomUnit.Length;

            System.Buffer.BlockCopy(sid.ToBytes(), 0, result, offset, sid.Length == 0 ? 1 : 0);
            offset += sid.Length == 0 ? 1 : 0;

            byte[] length = BitConverter.GetBytes((ushort)(2 * CipherSuites.Length));
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(length);
            }

            System.Buffer.BlockCopy(length, 0, result, offset, 2);
            offset += 2;

            System.Buffer.BlockCopy(CipherSuites.GetSupportedSuitesInBytes(), 0, result, offset, (CipherSuites.Length * 2));
            offset += CipherSuites.Length * 2;

            System.Buffer.BlockCopy(CompressionList.ToBytes(), 0, result, offset, 1 + CompressionList.Length);
            offset += 1 + CompressionList.Length;

            return(result);
        }