pub struct BuffCodec { /* private fields */ }Expand description
BUFF compressor/decompressor for bounded floating-point arrays.
This implements byte-sliced storage where each bit position across all values is stored contiguously, enabling efficient compression and SIMD-accelerated queries.
Implementations§
Source§impl BuffCodec
impl BuffCodec
Sourcepub fn encode(&self, data: &[f64]) -> Result<Vec<u8>, BuffError>
pub fn encode(&self, data: &[f64]) -> Result<Vec<u8>, BuffError>
Encode an array of f64 values using BUFF byte-sliced encoding.
§Arguments
data- Slice of f64 values to encode
§Returns
A Vec<u8> containing the encoded data, or an error.
§Example
use buff_rs::BuffCodec;
let codec = BuffCodec::new(1000);
let data = vec![1.234, 5.678, 9.012];
let encoded = codec.encode(&data).unwrap();Sourcepub fn encode_with_special(&self, data: &[f64]) -> Result<Vec<u8>, BuffError>
pub fn encode_with_special(&self, data: &[f64]) -> Result<Vec<u8>, BuffError>
Encode an array of f64 values, including special values (Infinity, NaN).
This method handles special floating-point values by storing them separately from regular values. The encoded format uses version 2 which includes a special values section.
§Arguments
data- Slice of f64 values to encode (may contain Infinity, -Infinity, NaN)
§Returns
A Vec<u8> containing the encoded data, or an error.
§Example
use buff_rs::BuffCodec;
let codec = BuffCodec::new(1000);
let data = vec![1.234, f64::INFINITY, 5.678, f64::NAN, -f64::INFINITY];
let encoded = codec.encode_with_special(&data).unwrap();
let decoded = codec.decode(&encoded).unwrap();
assert!(decoded[1].is_infinite() && decoded[1].is_sign_positive());
assert!(decoded[3].is_nan());Sourcepub fn has_special_values(&self, bytes: &[u8]) -> bool
pub fn has_special_values(&self, bytes: &[u8]) -> bool
Check if encoded data contains special values (v2 format).
Sourcepub fn decode(&self, bytes: &[u8]) -> Result<Vec<f64>, BuffError>
pub fn decode(&self, bytes: &[u8]) -> Result<Vec<f64>, BuffError>
Decode BUFF-encoded data back to f64 values.
This method automatically detects the format version and handles both legacy (v1) and special values (v2) formats.
§Arguments
bytes- The encoded byte array
§Returns
A Vec<f64> containing the decoded values, or an error.
§Example
use buff_rs::BuffCodec;
let codec = BuffCodec::new(1000);
let data = vec![1.234, 5.678, 9.012];
let encoded = codec.encode(&data).unwrap();
let decoded = codec.decode(&encoded).unwrap();Sourcepub fn sum(&self, bytes: &[u8]) -> Result<f64, BuffError>
pub fn sum(&self, bytes: &[u8]) -> Result<f64, BuffError>
Compute the sum of all values in the encoded data.
This operates directly on the compressed data without full decompression.
Sourcepub fn max(&self, bytes: &[u8]) -> Result<f64, BuffError>
pub fn max(&self, bytes: &[u8]) -> Result<f64, BuffError>
Find the maximum value in the encoded data.
This operates directly on the compressed data without full decompression.
Sourcepub fn count_greater_than(
&self,
bytes: &[u8],
threshold: f64,
) -> Result<usize, BuffError>
pub fn count_greater_than( &self, bytes: &[u8], threshold: f64, ) -> Result<usize, BuffError>
Count values greater than a threshold.
This operates directly on the compressed data using early termination when possible.