# HG changeset patch # User gnumuthu # Date 1160410535 0 # Node ID d2a6ba4f9e96d72c9677872ecd8c7c3101b9d622 # Parent 0e554b247bbd52ca651ba8d43f84c34d5631b7c5 huffmandict updated to perform as wanted in the mailing list: with code-words for zero probability symbols, eventhough I wouldnt do it myself, and moreover its 'canonical huffman' which I think warrants this diff -r 0e554b247bbd -r d2a6ba4f9e96 main/comm/inst/huffmandict.m --- a/main/comm/inst/huffmandict.m Mon Oct 09 16:06:33 2006 +0000 +++ b/main/comm/inst/huffmandict.m Mon Oct 09 16:15:35 2006 +0000 @@ -88,8 +88,11 @@ % %need to find & eliminate the zero-probability code words. %in practice we donot need to assign anything to them. Reasoning - %being that if it doesnt occur why bother saving its vale anyway? - % + %being that if_ it doesnt occur why bother saving its value anyway? + %--(Oct 9) Actually some experts in the area dont agree to this, + %and being a generic implementation we should stick to generating + %CW's for_ zero symbols. Why impose a bad implementation? --Muthu + % origsource_prob=source_prob; @@ -112,15 +115,6 @@ end end - %index - %source_prob - - idx=find(source_prob==0); - if(not(isempty(idx))) - source_prob=source_prob(1:idx(1)-1); - end - clear idx; - stage_list={}; cw_list{1:L}=[]; @@ -234,4 +228,5 @@ %! %!assert(huffmandict(1:4,[0.5 0.25 0.15 0.1],1), {[0],[1 0],[1 1 1],[1 1 0]},0) %!assert(huffmandict(1:4,0.25*ones(1,4),1),{[1 1],[1 0],[0 1],[0 0]},0) +%!assert(huffmandict(1:4,[1 0 0 0 ]),{[1],[0 1],[0 0 0],[0 0 1]},0) %!