Arithmetic coding/As a generalized change of radix: Difference between revisions

m
Minor simplifications
m (→‎{{header|Sidef}}: fix precedence issue)
m (Minor simplifications)
Line 258:
# frequencies of all previously occurring symbols
foreach my $c (@chars) {
my $x =L->bmuladd($base, $cf{$c}*$pf);
$L->bmuladd($base, $x * $pf);
$pf->bmul($freq{$c});
}
Line 278 ⟶ 277:
$enc *= $radix**$pow;
 
# Base
my $base = Math::BigInt->new(0);
$base += $_ for values %{$freq};
Line 312:
my $cv = $cf{$c};
 
my $rem = ($enc - $pow * $cv) / $fv;
 
$enc = $rem;
Line 377:
# frequencies of all previously occurring symbols
for @chars -> $c {
my $xL = $L*$base + %cf{$c}*$pf;
$L = $L * $base + $x * $pf;
$pf *= %freq{$c};
}
Line 401 ⟶ 400:
my $enc = $encoding * $radix**$pow;
 
my# $base = 0;Base
my $base += $_ for[+] %freq.values;
 
# Create the cumulative frequency table
Line 498 ⟶ 497:
# frequencies of all previously occurring symbols
for b in bytes:
xlower = lower*base + cf[b]*pf
lower = lower * base + x*pf
pf *= freq[b]
 
Line 519 ⟶ 517:
enc *= radix**pow;
 
# Base
base = sum(freq.values())
 
Line 607 ⟶ 606:
# frequencies of all previously occurring symbols
bytes.each do |b|
xlower = lower*base + cf[b]*pf
lower = lower * base + x*pf
pf *= freq[b]
end
Line 631 ⟶ 629:
enc *= radix**pow;
 
base# = 0Base
base = freq.values.reduce(:+)
freq.each_value { |v| base += v }
 
# Create the cumulative frequency table
Line 728 ⟶ 726:
# frequencies of all previously occurring symbols
bytes.each { |b|
var xL = (L*base + cf{b}*pf)
L *= base += x*pf
pf *= freq{b}
}
Line 747 ⟶ 744:
enc *= radix**pow;
 
var# base = 0Base
freq.each_value { |v|var base += v }freq.values.sum
 
# Create the cumulative frequency table
2,747

edits