June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -9,3 +9,23 @@ sub huffman (%frequencies) {
|
|||
}
|
||||
@queue[0].value;
|
||||
}
|
||||
|
||||
# Testing
|
||||
|
||||
for huffman 'this is an example for huffman encoding'.comb.Bag {
|
||||
say "'{.key}' : {.value}";
|
||||
}
|
||||
|
||||
# To demonstrate that the table can do a round trip:
|
||||
|
||||
say '';
|
||||
my $original = 'this is an example for huffman encoding';
|
||||
|
||||
my %encode-key = huffman $original.comb.Bag;
|
||||
my %decode-key = %encode-key.invert;
|
||||
my @codes = %decode-key.keys;
|
||||
|
||||
my $encoded = $original.subst: /./, { %encode-key{$_} }, :g;
|
||||
my $decoded = $encoded .subst: /@codes/, { %decode-key{$_} }, :g;
|
||||
|
||||
.say for $original, $encoded, $decoded;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue