Skip to main content

BuffCodec

Struct BuffCodec 

Source
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

Source

pub fn new(scale: usize) -> Self

Create a new BUFF codec with the given scale.

§Arguments
  • scale - The decimal scale (e.g., 1000 for 3 decimal places, 10000 for 4)
§Example
use buff_rs::BuffCodec;

// For 3 decimal places of precision
let codec = BuffCodec::new(1000);
Source

pub fn precision(&self) -> i32

Get the precision (number of decimal places) from the scale.

Source

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();
Source

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());
Source

pub fn has_special_values(&self, bytes: &[u8]) -> bool

Check if encoded data contains special values (v2 format).

Source

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();
Source

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.

Source

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.

Source

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.

Source

pub fn count_equal(&self, bytes: &[u8], target: f64) -> Result<usize, BuffError>

Count values equal to a target.

Source

pub fn metadata(&self, bytes: &[u8]) -> Result<BuffMetadata, BuffError>

Get metadata about the encoded data without decoding.

Trait Implementations§

Source§

impl Clone for BuffCodec

Source§

fn clone(&self) -> BuffCodec

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BuffCodec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.