Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
38
Task/Huffman-coding/SETL/huffman-coding.setl
Normal file
38
Task/Huffman-coding/SETL/huffman-coding.setl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
var forest := {}, encTab := {};
|
||||
|
||||
plaintext := 'this is an example for huffman encoding';
|
||||
|
||||
ft := {};
|
||||
(for c in plaintext)
|
||||
ft(c) +:= 1;
|
||||
end;
|
||||
|
||||
forest := {[f, c]: [c, f] in ft};
|
||||
(while 1 < #forest)
|
||||
[f1, n1] := getLFN();
|
||||
[f2, n2] := getLFN();
|
||||
forest with:= [f1+f2, [n1,n2]];
|
||||
end;
|
||||
addToTable('', arb range forest);
|
||||
|
||||
(for e = encTab(c))
|
||||
print(c, ft(c), e);
|
||||
end;
|
||||
|
||||
print(+/ [encTab(c): c in plaintext]);
|
||||
|
||||
proc addToTable(prefix, node);
|
||||
if is_tuple node then
|
||||
addToTable(prefix + '0', node(1));
|
||||
addToTable(prefix + '1', node(2));
|
||||
else
|
||||
encTab(node) := prefix;
|
||||
end;
|
||||
end proc;
|
||||
|
||||
proc getLFN();
|
||||
f := min/ domain forest;
|
||||
n := arb forest{f};
|
||||
forest less:= [f, n];
|
||||
return [f, n];
|
||||
end proc;
|
||||
Loading…
Add table
Add a link
Reference in a new issue