@@ -48,8 +48,7 @@ public static IAlgmEncoded<string, IAlgmEncoded<int, Dictionary<char, int>>> Enc
4848 {
4949 List < Symbol > codes = GetSymbolsRanges ( source ) ;
5050 decimal HighRange = 1 , LowRange = 0 , h , l ;
51-
52- //List<char> TheImmutablePart = new List<char>();
51+
5352 StringBuilder TheImmutablePart = new StringBuilder ( ) ;
5453
5554 foreach ( char c in source )
@@ -87,8 +86,6 @@ public static IAlgmEncoded<string, IAlgmEncoded<int, Dictionary<char, int>>> Enc
8786 }
8887 answer . Clear ( ) ;
8988 answer . Append ( TheImmutablePart ) ;
90- //foreach (char c in TheImmutablePart)
91- // answer += c;
9289 for ( int i = 0 ; i < k ; i ++ )
9390 answer . Append ( number [ i ] . ToString ( ) ) ;
9491 }
@@ -101,23 +98,17 @@ private static void DiscardTheImmutablePart(ref StringBuilder theImmutablePart,
10198 {
10299 string lr = lowRange . ToString ( ) ;
103100 string hr = highRange . ToString ( ) ;
104- int i = 0 , cnt = 0 ;
101+ int i = 0 ;
105102 while ( i < lr . Length && i < hr . Length && lr [ i ] == hr [ i ] )
106103 {
107104 if ( ! ( ( i == 0 && lr [ i ] == '0' ) || lr [ i ] == ',' ) )
108105 {
109106 theImmutablePart . Append ( lr [ i ] ) ;
110107 highRange *= 10 ; highRange -= ( int ) highRange % 10 ;
111108 lowRange *= 10 ; lowRange -= ( int ) lowRange % 10 ;
112- //cnt++;
113109 }
114-
115110 i ++ ;
116111 }
117- //highRange *= (decimal)Math.Pow(10, cnt);
118- //highRange -= (int)highRange;
119- //lowRange *= (decimal)Math.Pow(10, cnt);
120- //lowRange -= (int)lowRange;
121112 }
122113
123114 private static void DiscardTheImmutablePart ( ref decimal highRange , ref decimal lowRange , ref decimal code , ref int index , string encoded ,
@@ -134,34 +125,14 @@ private static void DiscardTheImmutablePart(ref decimal highRange, ref decimal l
134125 highRange *= 10 ; highRange -= ( int ) highRange % 10 ;
135126 lowRange *= 10 ; lowRange -= ( int ) lowRange % 10 ;
136127 code = Convert . ToDecimal ( "0," + ( index < encodedLength ? encoded . Substring ( index , Math . Min ( 28 , encodedLength - index ) ) : "0" ) ) ;
137- index ++ ;
138- //code *= 10; code -= (int)code % 10;
139- //if (index<encodedLength)
140- //{
141- // if (encoded[index]=='0')
142- // {
143- // CntOfZero++; index++;
144- // thePreviousDigitIsZero = true;
145- // }
146- // else
147- // {
148-
149- // if (thePreviousDigitIsZero)
150- // {
151- // code += (decimal)(int.Parse(encoded[index++].ToString()) / Math.Pow(10, c.Length - 2+CntOfZero));
152- // }
153- // else
154-
155- // }
156- //}
128+ index ++ ;
157129 }
158130 i ++ ;
159131 }
160132 }
161133
162134 private static string convertToString ( int [ ] number , int index )
163135 {
164- //if (index > 28) index = 28;
165136 string str = "0," ;
166137 for ( int i = 0 ; i < index ; i ++ )
167138 str += number [ i ] . ToString ( ) ;
@@ -196,7 +167,11 @@ public static IAlgmEncoded<string> Decode(Dictionary<char, int> frequencies, str
196167 }
197168 private static double CalculateCompressionRatio ( string sourceString , string compressionString )
198169 {
199- return Math . Round ( ( double ) ( ( sourceString . Length * 8 ) / Convert . ToString ( compressionString . Length , 2 ) . Length ) , 3 ) ;
170+ //byte[] BigIArray = System.Numerics.BigInteger.Parse(compressionString).ToByteArray();
171+ //string BinaryCode = string.Concat(BigIArray.Select(b => Convert.ToString(b, 2).PadLeft(8, '0')).Reverse());
172+ //var k = Math.Round(Convert.ToDouble(((decimal)sourceString.Length * 8 / (decimal)BinaryCode.ToString().TrimStart('0').Length).ToString()), 3);
173+ return 0 ;
174+ //return Math.Round((double)((sourceString.Length * 8) / Convert.ToString(compressionString.Length, 2).Length), 3);
200175 }
201176 }
202177}
0 commit comments