2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2026-04-04 04:18:22 +00:00

Huffman base2/3

This commit is contained in:
2023-03-27 15:12:40 +03:00
parent 60738d01b4
commit 9a74a01bdf
8 changed files with 268 additions and 96 deletions

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Esiur.Analysis.Coding
{
public struct CodeWord<T>
{
public T[] Word;
int hashCode;
public override bool Equals(object obj)
{
if (obj is CodeWord<T>)
return Word.SequenceEqual(((CodeWord<T>)obj).Word);
return false;
}
public override int GetHashCode()
{
return ToString().GetHashCode();
}
public static CodeWord<Base2> FromByte(byte b)
{
var word = new Base2[8];
for(var i = 0; i < 8; i++)
{
word[i] = (b & (0x1 << i)) > 0 ? Base2.One : Base2.Zero;
}
return new CodeWord<Base2>() { Word = word };
}
public override string ToString()
{
return String.Join(" ", Word);
}
}
public class Symbol<T>
{
public double Probability { get; set; }
public CodeWord<T> Word { get; set; }
}
}