aboutsummaryrefslogtreecommitdiffstats
path: root/src/Huffman/HuffmanNode.cs
blob: d163bfcc5c1e02b2dfade79883144344599db39d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System;
using System.Collections;
using PriorityQueue;


namespace Huffman
{
    public class HuffmanNode<TElement, TPriority> : INode<TPriority>, IComparable<INode<TPriority>> 
        where TPriority : IComparable<TPriority>
    {
        public HuffmanNode<TElement, TPriority> Left { get; set; }
        public HuffmanNode<TElement, TPriority> Right { get; set; }

        public TElement Element { get; set; }
        public TPriority Key { get; set; }

        public HuffmanNode(TPriority key) =>
            Key = key;

        public HuffmanNode(TPriority key, TElement element) : this(key) =>
            Element = element;

        public int CompareTo(INode<TPriority> node) =>
            Key.CompareTo(node.Key);

        public static implicit operator HuffmanNode<TElement, TPriority>(DictionaryEntry item) =>
            new HuffmanNode<TElement, TPriority>((TPriority)item.Value, (TElement)item.Key);
    }
}