@@ -37,23 +37,34 @@ public static IAlgmEncoded<List<RLECodeBlock>> Encode(string inputString)
3737 return new EncodedMessage < List < RLECodeBlock > > ( result , CalculateCompressionRatio ( inputString , result ) ) ;
3838 }
3939
40- public static IAlgmEncoded < string > Decode ( List < RLECodeBlock > encodedString )
40+ private static List < RLECodeBlock > ParseEncodedString ( string encodedString )
4141 {
42- if ( encodedString . Count < 2 )
42+ List < RLECodeBlock > encodedStringParsed = new List < RLECodeBlock > ( ) ;
43+
44+ return encodedStringParsed ;
45+ }
46+
47+ public static IAlgmEncoded < string > Decode ( string encodedString )
48+ {
49+ var encodedStringParsed = ParseEncodedString ( encodedString ) ;
50+
51+ //0 блок хранит номер строки в матрице BWT
52+ //1 блок хранит хотя бы один символ
53+ if ( encodedStringParsed . Count < 2 )
4354 {
4455 throw new ArgumentNullException ( "string for decoding is null or empty" ) ;
4556 }
4657
4758 StringBuilder decompressedString = new StringBuilder ( string . Empty ) ;
4859
49- for ( int i = 1 ; i < encodedString . Count ; i ++ )
60+ for ( int i = 1 ; i < encodedStringParsed . Count ; i ++ )
5061 {
51- for ( int j = 0 ; j < encodedString [ i ] . Repeats ; j ++ )
52- decompressedString . Append ( encodedString [ i ] . Symbol ) ;
62+ for ( int j = 0 ; j < encodedStringParsed [ i ] . Repeats ; j ++ )
63+ decompressedString . Append ( encodedStringParsed [ i ] . Symbol ) ;
5364 }
5465
55- var result = BurrowsWheelerTransform . Decode ( decompressedString . ToString ( ) , encodedString [ 0 ] . Repeats ) ;
56- return new EncodedMessage < string > ( result , CalculateCompressionRatio ( result , encodedString ) ) ;
66+ var result = BurrowsWheelerTransform . Decode ( decompressedString . ToString ( ) , encodedStringParsed [ 0 ] . Repeats ) ;
67+ return new EncodedMessage < string > ( result , CalculateCompressionRatio ( result , encodedStringParsed ) ) ;
5768 }
5869
5970 private static double CalculateCompressionRatio ( string sourceString , List < RLECodeBlock > compressionString )
0 commit comments