Skip to content

Commit b02e2cc

Browse files
committed
Bool for Zavod
1 parent d065800 commit b02e2cc

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

AlgorithmsLibrary/LZ77Algm/LZ77Algm.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace AlgorithmsLibrary
99
{
1010
public static class LZ77Algm
1111
{
12+
static bool Zavod = false;
1213
/// <summary>
1314
/// String compression using the LZ77 algorithm
1415
/// </summary>
@@ -57,7 +58,7 @@ public static IAlgmEncoded<List<CodeBlock>> Encode(string inputString)
5758
establishingBuffer.Remove(0, 1);
5859

5960
var codeblock = new CodeBlock(0, 0, nextChar);
60-
//Console.WriteLine(searchBuffer.ToString() + "\t\t " + establishingBuffer.ToString() + "\t\t " + codeblock);
61+
if (Zavod) Console.WriteLine(searchBuffer.ToString() + "\t\t " + establishingBuffer.ToString() + "\t\t " + codeblock);
6162
result.Add(codeblock); //указываем на него метку
6263
}
6364
else
@@ -76,7 +77,7 @@ public static IAlgmEncoded<List<CodeBlock>> Encode(string inputString)
7677
searchBuffer.Append(subInEstablish);
7778

7879
var codeblock = new CodeBlock(offset, length, nextChar);
79-
//Console.WriteLine(searchBuffer.ToString() + "\t\t " + establishingBuffer.ToString() + "\t\t " + codeblock);
80+
if (Zavod) Console.WriteLine(searchBuffer.ToString() + "\t\t " + establishingBuffer.ToString() + "\t\t " + codeblock);
8081
result.Add(codeblock);
8182
}
8283

AlgorithmsLibrary/LZ78Algm/LZ78Algm.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace AlgorithmsLibrary
1212
/// </summary>
1313
public static class LZ78Algm
1414
{
15+
static bool Zavod = false;
1516
public static IAlgmEncoded<List<LZ78CodeBlock>> Encode(string source)
1617
{
1718
string Buffer = ""; //строка для формирования ключа для словаря
@@ -26,8 +27,11 @@ public static IAlgmEncoded<List<LZ78CodeBlock>> Encode(string source)
2627
else
2728
{
2829
var codeblock = new LZ78CodeBlock(Dictionary[Buffer], source[i]);
29-
//char c = Buffer.Length == 0 ? source[i] : Buffer[0];
30-
//Console.WriteLine(c + " " + codeblock);
30+
if (Zavod)
31+
{
32+
char c = Buffer.Length == 0 ? source[i] : Buffer[0];
33+
Console.WriteLine(c + " " + codeblock);
34+
}
3135
EncodedString.Add(codeblock); // добавляем пару в ответ
3236
Dictionary.Add(Buffer + source[i], Dictionary.Count); // добавляем слово в словарь
3337
Buffer = string.Empty;
@@ -39,7 +43,7 @@ public static IAlgmEncoded<List<LZ78CodeBlock>> Encode(string source)
3943
if (Dictionary.ContainsKey(Buffer))
4044
{
4145
var codeblock = new LZ78CodeBlock(Dictionary[Buffer], '$');
42-
//Console.WriteLine('$' + " " + codeblock);
46+
if (Zavod) Console.WriteLine('$' + " " + codeblock);
4347
EncodedString.Add(codeblock);
4448
}
4549
else
@@ -48,15 +52,16 @@ public static IAlgmEncoded<List<LZ78CodeBlock>> Encode(string source)
4852
Buffer = Buffer.Remove(Buffer.Length - 1); // удаляем последний символ из буфера
4953

5054
var codeblock = new LZ78CodeBlock(Dictionary[Buffer], last_ch);
51-
//Console.WriteLine(Buffer[0] + " " + codeblock);
55+
if (Zavod) Console.WriteLine(Buffer[0] + " " + codeblock);
5256
EncodedString.Add(codeblock); // добавляем пару в ответ
5357
}
5458
}
5559

56-
//foreach (var item in Dictionary)
57-
//{
58-
// Console.WriteLine(item.Key + " " + item.Value);
59-
//}
60+
if (Zavod)
61+
foreach (var item in Dictionary)
62+
{
63+
Console.WriteLine(item.Key + " " + item.Value);
64+
}
6065

6166
return new EncodedMessage<List<LZ78CodeBlock>>(EncodedString, CalculateCompressionRatio(source, EncodedString));
6267
}

0 commit comments

Comments
 (0)