rans_encode
result = rans_encode(data)
Input: data · Output: result
What it is
rANS entropy coding of data (a Str, or a Vec of 0-255 byte values) — a static frequency table, unlike range_encode's adaptive model, so the table travels with the payload.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = rans_encode(data) | data Str or Vecnot documented yet | freq Veca length-256 Vec, the symbol frequency tablebytes Veca Vec of 0-255 coded bytessymbol_count Numa Num, the input length | Returns a Record with fields freq (a length-256 Vec, the symbol frequency table), bytes (a Vec of 0-255 coded bytes) and symbol_count (a Num, the input length). Empty input gives none rather than a record. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
s = "hello hello hello compression world"
enc = rans_encode(s)
print(numel(enc.bytes)) # coded length, in bytes
print(rans_decode(enc, as_str = true) == s) # true
output
18 true
from file-io