49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using StgSharp.Data;
|
|
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Text;
|
|
|
|
namespace StgSharpDataEncoder
|
|
{
|
|
internal class Program
|
|
{
|
|
static unsafe void Main(string[] args)
|
|
{
|
|
byte[] array = CodeSeparator.SeparateCode<byte>(
|
|
Encoding.UTF8.GetBytes(
|
|
"this is an example of a huffman tree"));
|
|
List<(byte, ulong)> list = CodeSeparator.CountCodeFrequency(array);
|
|
foreach (var i in list)
|
|
{
|
|
Console.WriteLine($"{i.Item1}\t{i.Item2}");
|
|
}
|
|
|
|
Console.WriteLine();
|
|
Console.WriteLine();
|
|
|
|
HuffmanTree<byte> tree = HuffmanTree<byte>.BuildHuffmanTree(list);
|
|
foreach (var i in tree.LeafList)
|
|
{
|
|
Console.WriteLine($"{i.Value}\t{i.frequency}\t" +
|
|
$"{(i.Left == null ? 0 : i.Left.frequency)}\t" +
|
|
$"{(i.Right == null ? 0 : i.Right.frequency)}");
|
|
}
|
|
|
|
Console.WriteLine();
|
|
Console.WriteLine();
|
|
|
|
Dictionary<byte, HuffmanKey<byte>> encodeDictionary
|
|
= tree.BuildHuffmanDictionary();
|
|
foreach (var item in encodeDictionary)
|
|
{
|
|
Console.WriteLine(
|
|
$"{item.Key}\t" +
|
|
$"{item.Value.Value}"
|
|
);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|