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

Function encode

nodedb-codec/src/fastlanes/mod.rs:48–68  ·  view source on GitHub ↗

Encode a slice of i64 values using FOR + bit-packing.

(values: &[i64])

Source from the content-addressed store, hash-verified

46
47/// Encode a slice of i64 values using FOR + bit-packing.
48pub fn encode(values: &[i64]) -> Vec<u8> {
49 let total_count = values.len() as u32;
50 let block_count = if values.is_empty() {
51 0u16
52 } else {
53 values.len().div_ceil(BLOCK_SIZE) as u16
54 };
55
56 let mut out = Vec::with_capacity(GLOBAL_HEADER_SIZE + values.len() * 5);
57
58 // Global header.
59 out.extend_from_slice(&total_count.to_le_bytes());
60 out.extend_from_slice(&block_count.to_le_bytes());
61
62 // Encode each block.
63 for chunk in values.chunks(BLOCK_SIZE) {
64 encode_block(chunk, &mut out);
65 }
66
67 out
68}
69
70/// Decode FOR + bit-packed bytes back to i64 values.
71pub fn decode(data: &[u8]) -> Result<Vec<i64>, CodecError> {

Callers 15

empty_roundtripFunction · 0.70
single_valueFunction · 0.70
small_range_valuesFunction · 0.70
constant_rate_timestampsFunction · 0.70
pre_delta_timestampsFunction · 0.70
negative_valuesFunction · 0.70
boundary_valuesFunction · 0.70
multiple_blocksFunction · 0.70
partial_last_blockFunction · 0.70
compression_vs_rawFunction · 0.70

Calls 3

encode_blockFunction · 0.85
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by 15

empty_roundtripFunction · 0.56
single_valueFunction · 0.56
small_range_valuesFunction · 0.56
constant_rate_timestampsFunction · 0.56
pre_delta_timestampsFunction · 0.56
negative_valuesFunction · 0.56
boundary_valuesFunction · 0.56
multiple_blocksFunction · 0.56
partial_last_blockFunction · 0.56
compression_vs_rawFunction · 0.56