Skip to content

Commit ae7444f

Browse files
committed
min fix
1 parent 782ccf4 commit ae7444f

4 files changed

Lines changed: 39 additions & 9 deletions

File tree

AlgorithmsLibrary/ArithmeticCodingAlgm/ArithmeticCodingAlgm.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ private static List<Symbol> GetSymbolsRanges(Dictionary<char, int> frequencies,
3232
decimal frequencyOfOneSymbol = (decimal)1 / CountOfAllSymbols;
3333
var nodes = frequencies.Select(x => new Symbol(x.Key, x.Value * frequencyOfOneSymbol)).ToList();
3434

35-
nodes.Sort();
36-
nodes.Reverse();
35+
//закомментировал чтобы было как у Завода
36+
//nodes.Sort();
37+
//nodes.Reverse();
3738

3839
decimal current = 0;
3940
foreach (var item in nodes)

AlgorithmsLibrary/LZ77Algm/LZ77Algm.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ public static IAlgmEncoded<List<CodeBlock>> Encode(string inputString)
5656
searchBuffer.Append(nextChar);
5757
establishingBuffer.Remove(0, 1);
5858

59-
result.Add(new CodeBlock(0, 0, nextChar)); //указываем на него метку
59+
var codeblock = new CodeBlock(0, 0, nextChar);
60+
//Console.WriteLine(searchBuffer.ToString() + "\t\t " + establishingBuffer.ToString() + "\t\t " + codeblock);
61+
result.Add(codeblock); //указываем на него метку
6062
}
6163
else
6264
{
@@ -73,7 +75,9 @@ public static IAlgmEncoded<List<CodeBlock>> Encode(string inputString)
7375
establishingBuffer.Remove(0, length + 1);
7476
searchBuffer.Append(subInEstablish);
7577

76-
result.Add(new CodeBlock(offset, length, nextChar));
78+
var codeblock = new CodeBlock(offset, length, nextChar);
79+
//Console.WriteLine(searchBuffer.ToString() + "\t\t " + establishingBuffer.ToString() + "\t\t " + codeblock);
80+
result.Add(codeblock);
7781
}
7882

7983
currentLengthSubString = 0;

AlgorithmsLibrary/LZ78Algm/LZ78Algm.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,39 @@ public static IAlgmEncoded<List<LZ78CodeBlock>> Encode(string source)
2525
}
2626
else
2727
{
28-
EncodedString.Add(new LZ78CodeBlock(Dictionary[Buffer], source[i])); // добавляем пару в ответ
28+
var codeblock = new LZ78CodeBlock(Dictionary[Buffer], source[i]);
29+
//char c = Buffer.Length == 0 ? source[i] : Buffer[0];
30+
//Console.WriteLine(c + " " + codeblock);
31+
EncodedString.Add(codeblock); // добавляем пару в ответ
2932
Dictionary.Add(Buffer + source[i], Dictionary.Count); // добавляем слово в словарь
3033
Buffer = string.Empty;
3134
}
3235
}
3336
// если буффер не пуст - этот код уже был, нужно его добавить в конец словаря
3437
if (!Buffer.Equals(string.Empty))
3538
{
36-
var last_ch = Buffer.Last(); // берем последний символ буффера, как "новый" символ
37-
Buffer = Buffer.Remove(Buffer.Length - 1); // удаляем последний символ из буфера
38-
EncodedString.Add(new LZ78CodeBlock(Dictionary[Buffer], last_ch)); // добавляем пару в ответ
39+
if (Dictionary.ContainsKey(Buffer))
40+
{
41+
var codeblock = new LZ78CodeBlock(Dictionary[Buffer], '$');
42+
//Console.WriteLine('$' + " " + codeblock);
43+
EncodedString.Add(codeblock);
44+
}
45+
else
46+
{
47+
var last_ch = Buffer.Last(); // берем последний символ буффера, как "новый" символ
48+
Buffer = Buffer.Remove(Buffer.Length - 1); // удаляем последний символ из буфера
49+
50+
var codeblock = new LZ78CodeBlock(Dictionary[Buffer], last_ch);
51+
//Console.WriteLine(Buffer[0] + " " + codeblock);
52+
EncodedString.Add(codeblock); // добавляем пару в ответ
53+
}
3954
}
4055

56+
//foreach (var item in Dictionary)
57+
//{
58+
// Console.WriteLine(item.Key + " " + item.Value);
59+
//}
60+
4161
return new EncodedMessage<List<LZ78CodeBlock>>(EncodedString, CalculateCompressionRatio(source, EncodedString));
4262
}
4363

AlgorithmsLibrary/Testing.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace AlgorithmsLibrary
1+
using System;
2+
3+
namespace AlgorithmsLibrary
24
{
35
internal class Program
46
{
@@ -7,6 +9,9 @@ static void Main(string[] args)
79
//Для того чтобы здесь, что то работало необходимо переключить тип проекта
810
//на консольное приложение
911
//я понимаю что это не правильно так делать но пофиг
12+
LZ78Algm.Encode("жужжит_жужелица,_жужжит,_да_не_кружится");
13+
14+
Console.ReadKey();
1015
}
1116
}
1217
}

0 commit comments

Comments
 (0)