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

Function encode

nodedb-fts/src/codec/delta.rs:13–23  ·  view source on GitHub ↗

Delta encoding/decoding for sorted `u32` sequences. Posting lists are sorted by doc ID. Delta encoding stores the first ID absolute and subsequent IDs as `current - previous`. Typical deltas are much smaller than absolute IDs, enabling tighter bitpacking. Delta-encode a sorted slice of u32 values in place. After encoding: `out[0] = values[0]`, `out[i] = values[i] - values[i-1]`. The input MUST b

(values: &[u32])

Source from the content-addressed store, hash-verified

11/// After encoding: `out[0] = values[0]`, `out[i] = values[i] - values[i-1]`.
12/// The input MUST be sorted ascending. Unsorted input produces garbage.
13pub fn encode(values: &[u32]) -> Vec<u32> {
14 if values.is_empty() {
15 return Vec::new();
16 }
17 let mut deltas = Vec::with_capacity(values.len());
18 deltas.push(values[0]);
19 for i in 1..values.len() {
20 deltas.push(values[i] - values[i - 1]);
21 }
22 deltas
23}
24
25/// Decode delta-encoded values back to absolute sorted values.
26///

Callers 15

roundtrip_basicFunction · 0.70
single_elementFunction · 0.70
consecutive_idsFunction · 0.70
large_gapsFunction · 0.70
to_bytesMethod · 0.50
encode_fieldnormFunction · 0.50
make_postingsFunction · 0.50
compression_ratioFunction · 0.50
make_compact_postingFunction · 0.50
cpFunction · 0.50
record_docMethod · 0.50

Calls 3

is_emptyMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by 6

roundtrip_basicFunction · 0.56
single_elementFunction · 0.56
consecutive_idsFunction · 0.56
large_gapsFunction · 0.56
compression_ratioFunction · 0.40