pub struct Compressor<T: NumberLike>(_);
Expand description

Converts vectors of numbers into compressed bytes in .qco format.

Most compressor methods leave its state unchanged if they return an error. You can configure behavior like compression level by instantiating with .from_config()

You can use the standalone compressor at a file or chunk level.

use q_compress::standalone::Compressor;

let my_nums = vec![1, 2, 3];

// FILE LEVEL
let mut compressor = Compressor::<i32>::default();
let bytes = compressor.simple_compress(&my_nums);

// CHUNK LEVEL
let mut compressor = Compressor::<i32>::default();
compressor.header().expect("header");
compressor.chunk(&my_nums).expect("chunk");
compressor.footer().expect("footer");
let bytes = compressor.drain_bytes();

Note that in practice we would need larger chunks than this to achieve good compression, preferably containing 2k-10M numbers.

Implementations§

source§

impl<T: NumberLike> Compressor<T>

source

pub fn from_config(config: CompressorConfig) -> Self

Creates a new compressor, given a CompressorConfig. Internally, the compressor builds Flags as well as an internal configuration that doesn’t show up in the output file. You can inspect the flags it chooses with .flags().

source

pub fn flags(&self) -> &Flags

Returns a reference to the compressor’s flags.

source

pub fn header(&mut self) -> QCompressResult<()>

Writes out a header using the compressor’s data type and flags. Will return an error if the compressor has already written the header.

Each .qco file must start with such a header, which contains:

  • a 4-byte magic header for “qco!” in ascii,
  • a byte for the data type (e.g. i64 has byte 1 and f64 has byte 5), and
  • bytes for the flags used to compress.
source

pub fn chunk(&mut self, nums: &[T]) -> QCompressResult<ChunkMetadata<T>>

Writes out a chunk of data representing the provided numbers. Will return an error if the compressor has not yet written the header or already written the footer.

Each chunk contains a ChunkMetadata section followed by the chunk body. The chunk body encodes the numbers passed in here.

source

pub fn footer(&mut self) -> QCompressResult<()>

Writes out a single footer byte indicating that the .qco file has ended. Will return an error if the compressor has not yet written the header or already written the footer.

source

pub fn simple_compress(&mut self, nums: &[T]) -> Vec<u8>

Takes in a slice of numbers and returns compressed bytes.

Unlike most methods, this does not guarantee atomicity of the compressor’s state.

source

pub fn drain_bytes(&mut self) -> Vec<u8>

Returns all bytes produced by the compressor so far that have not yet been read.

source

pub fn byte_size(&mut self) -> usize

Returns the number of bytes produced by the compressor so far that have not yet been read.

Trait Implementations§

source§

impl<T: Clone + NumberLike> Clone for Compressor<T>

source§

fn clone(&self) -> Compressor<T>

Returns a copy 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<T: Debug + NumberLike> Debug for Compressor<T>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: NumberLike> Default for Compressor<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Compressor<T>where <T as NumberLike>::Signed: RefUnwindSafe, <T as NumberLike>::Unsigned: RefUnwindSafe,

§

impl<T> Send for Compressor<T>where <T as NumberLike>::Signed: Send, <T as NumberLike>::Unsigned: Send,

§

impl<T> Sync for Compressor<T>where <T as NumberLike>::Signed: Sync, <T as NumberLike>::Unsigned: Sync,

§

impl<T> Unpin for Compressor<T>where <T as NumberLike>::Signed: Unpin, <T as NumberLike>::Unsigned: Unpin,

§

impl<T> UnwindSafe for Compressor<T>where <T as NumberLike>::Signed: UnwindSafe, <T as NumberLike>::Unsigned: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.