Arithmetic coding/As a generalized change of radix: Difference between revisions
Content added Content deleted
(Added D) |
|||
Line 71: | Line 71: | ||
// Lower bound |
// Lower bound |
||
BigInt lower = 0; |
|||
// Product of all frequencies |
// Product of all frequencies |
||
BigInt pf = 1; |
|||
// Each term is multiplied by the product of the |
// Each term is multiplied by the product of the |
||
Line 109: | Line 109: | ||
BigInt enc = num * bigPow(powr, pow); |
BigInt enc = num * bigPow(powr, pow); |
||
BigInt base = 0; |
|||
foreach (v; freq) { |
foreach (v; freq) { |
||
base += v; |
base += v; |
||
Line 137: | Line 137: | ||
for (BigInt i=base-1; i>=0; i--) { |
for (BigInt i=base-1; i>=0; i--) { |
||
pow = bigPow(base, i); |
pow = bigPow(base, i); |
||
assert(pow != 0, "WAT"); |
|||
auto div = enc / pow; |
auto div = enc / pow; |