public IHuffmanTree CreateHuffmanTree(CNode root, IHashTable hTable) { return(new CHuffmanTree { Root = root, HashTable = hTable }); }
public IHuffmanTree CreateRoot( ) { var nodes = Frequency.Select(symbol => new CNode { Symbol = symbol.Key, Frequency = symbol.Value }).ToList(); while ( nodes.Count > 1 ) { var orderedNodes = nodes.OrderBy( node => node.Frequency ).ToList(); if (orderedNodes.Count < 2) continue; var child = orderedNodes.Take( 2 ).ToList(); var parent = new CNode { Symbol = 0x20, Frequency = child[0].Frequency + child[1].Frequency, Left = child[0], Right = child[1] }; nodes.Remove( child[0] ); nodes.Remove( child[1] ); nodes.Add( parent ); } IHashTable hash = new CHashTable(); var firstOrDefault = nodes.FirstOrDefault(); if (firstOrDefault != null) firstOrDefault.MakeHash( new List<bool>(), hash ); return new CHuffmanTree { Root = nodes.FirstOrDefault(), HashTable = hash }; }
public IHuffmanTree CreateHuffmanTree( CNode root, IHashTable hTable ) { return new CHuffmanTree { Root = root, HashTable = hTable }; }
public CNode Decode(bool bit) { if ( bit ) { if ( Current.Right != null ) { Current = Current.Right; } } else { if ( Current.Left != null ) { Current = Current.Left; } } return Current; }
public CNode Decode(bool bit) { if (bit) { if (Current.Right != null) { Current = Current.Right; } } else { if (Current.Left != null) { Current = Current.Left; } } return(Current); }
public IHuffmanTree CreateRoot( ) { var nodes = Frequency.Select(symbol => new CNode { Symbol = symbol.Key, Frequency = symbol.Value }).ToList(); while (nodes.Count > 1) { var orderedNodes = nodes.OrderBy(node => node.Frequency).ToList(); if (orderedNodes.Count < 2) { continue; } var child = orderedNodes.Take(2).ToList(); var parent = new CNode { Symbol = 0x20, Frequency = child[0].Frequency + child[1].Frequency, Left = child[0], Right = child[1] }; nodes.Remove(child[0]); nodes.Remove(child[1]); nodes.Add(parent); } IHashTable hash = new CHashTable(); var firstOrDefault = nodes.FirstOrDefault(); if (firstOrDefault != null) { firstOrDefault.MakeHash(new List <bool>(), hash); } return(new CHuffmanTree { Root = nodes.FirstOrDefault(), HashTable = hash }); }
public void Set(CNode node) { Current = node; }
private static bool IsLeaf(CNode node) { return(node.Left == null && node.Right == null); }
public void Set( CNode node ) { Current = node; }