Skip to content

Commit ef1f6ce

Browse files
committed
Add a program icon, remove debugging classes and methods.
1 parent 5b49cf7 commit ef1f6ce

File tree

6 files changed

+32
-78
lines changed

6 files changed

+32
-78
lines changed

CompressionTest.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

Compressor/Compressor.cs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace HuffmanCompression
1111
{
12-
1312
public class Compressor
1413
{
1514
public static readonly string CompressedFileExtension = ".comp";
@@ -74,26 +73,7 @@ public static string GetCompressionSummary(long originalFileSize, long compresse
7473
return $"\noriginal size: {originalFileSize} bytes.\nCompressed size: {compressedFileSize} bytes.\nReduced by {percentage}%";
7574
}
7675

77-
// Only for debugging purposes.
78-
static void WriteCompressionInfo(string beforeWritingToBytes, byte[] afterWritingToBytes, Dictionary<char, string> dict)
79-
{
80-
Console.WriteLine("Dictionary:");
81-
int j = 0;
82-
foreach (var pair in dict)
83-
Console.WriteLine(++j + " { '" + (pair.Key == '\n' ? "[new line]" : "" + pair.Key) + "', \"" + pair.Value + "\" },");
84-
85-
Console.Write("Bits before writing to bytes: ");
86-
IOUtils.PrintFirst48Chars(beforeWritingToBytes);
87-
88-
Console.Write("\nBits after writing to bytes: ");
89-
IOUtils.PrintFirst48Bits(afterWritingToBytes);
90-
91-
Console.Write($"\nAmount of redundant zeros: {afterWritingToBytes.Length * 8 - beforeWritingToBytes.Length}");
92-
93-
Console.Write("\n\n\n");
94-
}
95-
96-
static bool CodesAreTooLong(Dictionary<char, string> codes)
76+
private static bool CodesAreTooLong(Dictionary<char, string> codes)
9777
{
9878
foreach (var pair in codes)
9979
if (pair.Value.Length > MaxCodeLength)
@@ -102,7 +82,7 @@ static bool CodesAreTooLong(Dictionary<char, string> codes)
10282
}
10383

10484
// [1][length][as encoded bits][code] OR [0][code]
105-
static string AddTreeInfoAndReplaceCharsWithCode(string text, Dictionary<char, string> dict)
85+
private static string AddTreeInfoAndReplaceCharsWithCode(string text, Dictionary<char, string> dict)
10686
{
10787
var textCopy = new StringBuilder(text);
10888
var usedChars = new List<char>();
@@ -140,7 +120,7 @@ static string AddTreeInfoAndReplaceCharsWithCode(string text, Dictionary<char, s
140120
return textCopy.ToString();
141121
}
142122

143-
static string CorrectCodeLength(string codeLength)
123+
private static string CorrectCodeLength(string codeLength)
144124
{
145125
int difference = AmountOfBitsToRepresentCodeLength - codeLength.Length;
146126

@@ -151,7 +131,7 @@ static string CorrectCodeLength(string codeLength)
151131
return codeLength;
152132
}
153133

154-
static byte EncodeCharacter(char character)
134+
private static byte EncodeCharacter(char character)
155135
{
156136
var bytes = TextEncoding.GetBytes(new char[] { character });
157137

@@ -162,15 +142,15 @@ static byte EncodeCharacter(char character)
162142
}
163143

164144
// Character | the character's representation code.
165-
static Dictionary<char, string> CreateCodesDictionary((int occurence, char character)[] occurences)
145+
private static Dictionary<char, string> CreateCodesDictionary((int occurence, char character)[] occurences)
166146
{
167147
var codes = new Dictionary<char, string>();
168148
BoxCharacters(occurences).ForEach(x => codes.Add(x.Character, FindCharacterCode(x)));
169149

170150
return codes;
171151
}
172152

173-
static string FindCharacterCode(CharacterBox box)
153+
private static string FindCharacterCode(CharacterBox box)
174154
{
175155
string code = "";
176156

@@ -182,8 +162,8 @@ static string FindCharacterCode(CharacterBox box)
182162
return code.Reverse();
183163
}
184164

185-
// Correct.
186-
static List<CharacterBox> BoxCharacters((int occurence, char character)[] occurences)
165+
// Correct.
166+
private static List<CharacterBox> BoxCharacters((int occurence, char character)[] occurences)
187167
{
188168
var CharacterList = new List<CharacterBox>();
189169
var tree = new List<Box>();
@@ -212,8 +192,8 @@ static List<CharacterBox> BoxCharacters((int occurence, char character)[] occure
212192
return CharacterList;
213193
}
214194

215-
// Correct.
216-
static void InsertAtAppropriatePlace(List<Box> tree, Box boxToInsert)
195+
// Correct.
196+
private static void InsertAtAppropriatePlace(List<Box> tree, Box boxToInsert)
217197
{
218198
if (tree.Count == 0 || boxToInsert.Sum > tree.Last().Sum || (boxToInsert.Sum == tree.Last().Sum && tree.Last().Depth < boxToInsert.Depth))
219199
{
@@ -235,9 +215,8 @@ static void InsertAtAppropriatePlace(List<Box> tree, Box boxToInsert)
235215
throw new Exception($"Could not insert box with sum {boxToInsert.Sum} to a tree with count {tree.Count} and highest sum {tree.Last().Sum}.");
236216
}
237217

238-
239-
// Correct.
240-
static (int occurence, char character)[] GetCharactersOccurence(string text)
218+
// Correct.
219+
private static (int occurence, char character)[] GetCharactersOccurence(string text)
241220
{
242221
var set = new HashSet<(int occurence, char character)>();
243222
foreach (char ch in text)

Decompressor/Decompressor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace HuffmanCompression
88
{
99
internal class Decompressor
1010
{
11-
const char EmptyChar = '\0';
11+
private const char EmptyChar = '\0';
1212

1313
public static string Decompress(byte[] compressedAsBytes)
1414
{
@@ -43,7 +43,7 @@ public static void DecompressFile(string path)
4343
File.WriteAllText(pathToDecompressedFile, decompressedText);
4444
}
4545

46-
static void RemoveBeginningZeros(StringBuilder text)
46+
private static void RemoveBeginningZeros(StringBuilder text)
4747
{
4848
for (int i = 0; i < IOUtils.BitsInByte; ++i)
4949
if (text[i] != '0')
@@ -53,7 +53,7 @@ static void RemoveBeginningZeros(StringBuilder text)
5353
}
5454
}
5555

56-
static (string code, char character) ExtractInfoCodeNotEncountered(StringBuilder compressed)
56+
private static (string code, char character) ExtractInfoCodeNotEncountered(StringBuilder compressed)
5757
{
5858
string codeLengthAsBinary = compressed.ToString(0, Compressor.AmountOfBitsToRepresentCodeLength);
5959
int codeLength = Convert.ToInt32(codeLengthAsBinary, 2);
@@ -69,7 +69,7 @@ static void RemoveBeginningZeros(StringBuilder text)
6969
return (code, charDecoded);
7070
}
7171

72-
static (string code, char character) TryRecognizeCode(StringBuilder bits, Dictionary<string, char> dict)
72+
private static (string code, char character) TryRecognizeCode(StringBuilder bits, Dictionary<string, char> dict)
7373
{
7474
string unfinishedBits = "";
7575

HuffmanCompression.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
77
<ProjectGuid>{15C28BC2-6294-4BE6-A46C-D075D51EB3CF}</ProjectGuid>
88
<OutputType>Exe</OutputType>
9-
<RootNamespace>HuffmanTree</RootNamespace>
10-
<AssemblyName>HuffmanTree</AssemblyName>
9+
<RootNamespace>HuffmanCompression</RootNamespace>
10+
<AssemblyName>HuffmanCompression</AssemblyName>
1111
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
@@ -53,6 +53,9 @@
5353
<PropertyGroup>
5454
<LangVersion>latest</LangVersion>
5555
</PropertyGroup>
56+
<PropertyGroup>
57+
<ApplicationIcon>Resources\icon.ico</ApplicationIcon>
58+
</PropertyGroup>
5659
<ItemGroup>
5760
<Reference Include="System" />
5861
<Reference Include="System.Core" />
@@ -64,7 +67,6 @@
6467
<Reference Include="System.Xml" />
6568
</ItemGroup>
6669
<ItemGroup>
67-
<Compile Include="CompressionTest.cs" />
6870
<Compile Include="Utils\IOUtils.cs" />
6971
<Compile Include="Compressor\TooManyCharactersException.cs" />
7072
<Compile Include="Compressor\TreeElements\Box.cs" />
@@ -91,7 +93,9 @@
9193
<Install>false</Install>
9294
</BootstrapperPackage>
9395
</ItemGroup>
94-
<ItemGroup />
96+
<ItemGroup>
97+
<Content Include="Resources\icon.ico" />
98+
</ItemGroup>
9599
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
96100
<PropertyGroup>
97101
<PreBuildEvent>

Program.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ namespace HuffmanCompression
66
{
77
public static class Program
88
{
9-
static readonly string NoArgumentErrorText = "You have not specified any files to compress/decompress.";
10-
static readonly string TooManyCharactersExceptionText = "The specified file has too many characters.";
11-
static readonly string UnexpectedErrorText = "There was an unexpected error. Skipping.";
12-
static readonly string WaitForKeypressText = "Press any button to close...";
13-
static readonly string ProcessDoneText = "Done.";
9+
private static readonly string NoArgumentErrorText = "You have not specified any files to compress/decompress.";
10+
private static readonly string TooManyCharactersExceptionText = "The specified file has too many characters.";
11+
private static readonly string UnexpectedErrorText = "There was an unexpected error. Skipping.";
12+
private static readonly string WaitForKeypressText = "Press any button to close...";
13+
private static readonly string ProcessDoneText = "Done.";
1414

15-
static void Main(string[] args)
15+
private static void Main(string[] args)
1616
{
1717
if (!args.Any())
1818
Console.WriteLine(NoArgumentErrorText);
@@ -22,13 +22,13 @@ static void Main(string[] args)
2222
WaitForKeyPress();
2323
}
2424

25-
static void WaitForKeyPress()
25+
private static void WaitForKeyPress()
2626
{
2727
Console.WriteLine(WaitForKeypressText);
2828
Console.ReadKey();
2929
}
3030

31-
static void DoActionsOnFiles(string[] paths)
31+
private static void DoActionsOnFiles(string[] paths)
3232
{
3333
foreach (string path in paths)
3434
{

Resources/icon.ico

106 KB
Binary file not shown.

0 commit comments

Comments
 (0)