MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / rans_encode_symbol

Function rans_encode_symbol

nodedb-codec/src/rans.rs:225–235  ·  view source on GitHub ↗
(state: &mut u32, bitstream: &mut Vec<u8>, start: u32, freq: u32)

Source from the content-addressed store, hash-verified

223// ---------------------------------------------------------------------------
224
225fn rans_encode_symbol(state: &mut u32, bitstream: &mut Vec<u8>, start: u32, freq: u32) {
226 // Renormalize: output bytes until state is in the correct range.
227 let max_state = ((RANS_L >> PROB_BITS) << 8) * freq;
228 while *state >= max_state {
229 bitstream.push((*state & 0xFF) as u8);
230 *state >>= 8;
231 }
232
233 // Encode symbol.
234 *state = ((*state / freq) << PROB_BITS) + (*state % freq) + start;
235}
236
237fn rans_decode_symbol(
238 state: u32,

Callers 1

encodeFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected