pub trait NumberLike: Copy + Debug + Display + Default + PartialEq + 'static {
    type Signed: SignedLike + NumberLike<Signed = Self::Signed, Unsigned = Self::Unsigned>;
    type Unsigned: UnsignedLike;

    const HEADER_BYTE: u8;
    const PHYSICAL_BITS: usize;

    // Required methods
    fn to_unsigned(self) -> Self::Unsigned;
    fn from_unsigned(off: Self::Unsigned) -> Self;
    fn to_signed(self) -> Self::Signed;
    fn from_signed(signed: Self::Signed) -> Self;
    fn to_bytes(self) -> Vec<u8>;
    fn from_bytes(bytes: &[u8]) -> QCompressResult<Self>;

    // Provided methods
    fn num_eq(&self, other: &Self) -> bool { ... }
    fn read_from(reader: &mut BitReader<'_>) -> QCompressResult<Self> { ... }
    fn write_to(self, writer: &mut BitWriter) { ... }
}
Expand description

Trait for data types supported for compression/decompression.

If you have a new data type you would like to add to the library or implement as custom in your own, these are the questions you need to answer:

  • What are the corresponding signed integer and unsigned integer types? These are usually the next-larger signed and unsigned integers.
  • How can I convert to these signed and unsigned representations and back in a way that preserves ordering? For instance, converting f32 to i32 can be done trivially by transmuting the bytes in memory, but converting from f32 to u32 in an order-preserving way requires flipping the sign bit and, if negative, the rest of the bits.
  • How can I encode and decode this number in an uncompressed way? This uncompressed representation is used to store metadata in each chunk of the Quantile Compression format.

Note: API stability of NumberLike is not guaranteed.

Required Associated Types§

source

type Signed: SignedLike + NumberLike<Signed = Self::Signed, Unsigned = Self::Unsigned>

The signed integer this type can convert between to do wrapped subtraction and addition for delta encoding/decoding. Must be another NumberLike with the same Signed and Unsigned as this type; in this way, if we take 7th order deltas, they are ensured to have the same type as 1st order deltas.

source

type Unsigned: UnsignedLike

The unsigned integer this type can convert between to do bitwise logic and such.

Required Associated Constants§

source

const HEADER_BYTE: u8

A number from 0-255 that corresponds to the number’s data type.

Each NumberLike implementation should have a different HEADER_BYTE. This byte gets written into the file’s header during compression, and if the wrong header byte shows up during decompression, the decompressor will return an error.

To choose a header byte for a new data type, review all header bytes in the library and pick an unused one. For instance, as of writing, bytes 1 through 15 are used, so 16 would be a good choice for another q_compress-supported data type, and 255 would be a good choice for a custom data type.

source

const PHYSICAL_BITS: usize

The number of bits in the number’s uncompressed representation. This must match the number of bytes in the to_bytes and from_bytes implementations. Note that booleans have 8 physical bits (not 1) and timestamps have 96 (not 128).

Required Methods§

source

fn to_unsigned(self) -> Self::Unsigned

Used during compression to convert to an unsigned integer.

source

fn from_unsigned(off: Self::Unsigned) -> Self

Used during decompression to convert back from an unsigned integer.

source

fn to_signed(self) -> Self::Signed

Used during delta encoding to convert to a signed integer.

source

fn from_signed(signed: Self::Signed) -> Self

Used during delta decoding to convert back from a signed integer.

source

fn to_bytes(self) -> Vec<u8>

Returns an uncompressed representation for the number.

source

fn from_bytes(bytes: &[u8]) -> QCompressResult<Self>

Creates a number from an uncompressed representation.

Provided Methods§

source

fn num_eq(&self, other: &Self) -> bool

This is no longer important and will go away in a future release.

source

fn read_from(reader: &mut BitReader<'_>) -> QCompressResult<Self>

Parses an uncompressed representation of the number from the BitReader.

source

fn write_to(self, writer: &mut BitWriter)

Appends an uncompressed representation of the number to the BitWriter.

Implementations on Foreign Types§

source§

impl NumberLike for f32

source§

const HEADER_BYTE: u8 = 6u8

source§

const PHYSICAL_BITS: usize = 32usize

§

type Signed = i32

§

type Unsigned = u32

source§

fn to_signed(self) -> Self::Signed

source§

fn from_signed(signed: Self::Signed) -> Self

source§

fn to_unsigned(self) -> Self::Unsigned

source§

fn from_unsigned(off: Self::Unsigned) -> Self

source§

fn to_bytes(self) -> Vec<u8>

source§

fn from_bytes(bytes: &[u8]) -> QCompressResult<Self>

source§

impl NumberLike for i16

source§

const HEADER_BYTE: u8 = 13u8

source§

const PHYSICAL_BITS: usize = 16usize

§

type Signed = i16

§

type Unsigned = u16

source§

fn to_signed(self) -> Self::Signed

source§

fn from_signed(signed: Self::Signed) -> Self

source§

fn to_unsigned(self) -> Self::Unsigned

source§

fn from_unsigned(off: Self::Unsigned) -> Self

source§

fn to_bytes(self) -> Vec<u8>

source§

fn from_bytes(bytes: &[u8]) -> QCompressResult<Self>

source§

impl NumberLike for u64

source§

const HEADER_BYTE: u8 = 2u8

source§

const PHYSICAL_BITS: usize = 64usize

§

type Signed = i64

§

type Unsigned = u64

source§

fn to_signed(self) -> Self::Signed

source§

fn from_signed(signed: Self::Signed) -> Self

source§

fn to_unsigned(self) -> Self::Unsigned

source§

fn from_unsigned(off: Self::Unsigned) -> Self

source§

fn to_bytes(self) -> Vec<u8>

source§

fn from_bytes(bytes: &[u8]) -> QCompressResult<Self>

source§

impl NumberLike for f64

source§

const HEADER_BYTE: u8 = 5u8

source§

const PHYSICAL_BITS: usize = 64usize

§

type Signed = i64

§

type Unsigned = u64

source§

fn to_signed(self) -> Self::Signed

source§

fn from_signed(signed: Self::Signed) -> Self

source§

fn to_unsigned(self) -> Self::Unsigned

source§

fn from_unsigned(off: Self::Unsigned) -> Self

source§

fn to_bytes(self) -> Vec<u8>

source§

fn from_bytes(bytes: &[u8]) -> QCompressResult<Self>

source§

impl NumberLike for i32

source§

const HEADER_BYTE: u8 = 3u8

source§

const PHYSICAL_BITS: usize = 32usize

§

type Signed = i32

§

type Unsigned = u32

source§

fn to_signed(self) -> Self::Signed

source§

fn from_signed(signed: Self::Signed) -> Self

source§

fn to_unsigned(self) -> Self::Unsigned

source§

fn from_unsigned(off: Self::Unsigned) -> Self

source§

fn to_bytes(self) -> Vec<u8>

source§

fn from_bytes(bytes: &[u8]) -> QCompressResult<Self>

source§

impl NumberLike for u32

source§

const HEADER_BYTE: u8 = 4u8

source§

const PHYSICAL_BITS: usize = 32usize

§

type Signed = i32

§

type Unsigned = u32

source§

fn to_signed(self) -> Self::Signed

source§

fn from_signed(signed: Self::Signed) -> Self

source§

fn to_unsigned(self) -> Self::Unsigned

source§

fn from_unsigned(off: Self::Unsigned) -> Self

source§

fn to_bytes(self) -> Vec<u8>

source§

fn from_bytes(bytes: &[u8]) -> QCompressResult<Self>

source§

impl NumberLike for bool

source§

impl NumberLike for i64

source§

const HEADER_BYTE: u8 = 1u8

source§

const PHYSICAL_BITS: usize = 64usize

§

type Signed = i64

§

type Unsigned = u64

source§

fn to_signed(self) -> Self::Signed

source§

fn from_signed(signed: Self::Signed) -> Self

source§

fn to_unsigned(self) -> Self::Unsigned

source§

fn from_unsigned(off: Self::Unsigned) -> Self

source§

fn to_bytes(self) -> Vec<u8>

source§

fn from_bytes(bytes: &[u8]) -> QCompressResult<Self>

source§

impl NumberLike for u16

source§

const HEADER_BYTE: u8 = 12u8

source§

const PHYSICAL_BITS: usize = 16usize

§

type Signed = i16

§

type Unsigned = u16

source§

fn to_signed(self) -> Self::Signed

source§

fn from_signed(signed: Self::Signed) -> Self

source§

fn to_unsigned(self) -> Self::Unsigned

source§

fn from_unsigned(off: Self::Unsigned) -> Self

source§

fn to_bytes(self) -> Vec<u8>

source§

fn from_bytes(bytes: &[u8]) -> QCompressResult<Self>

Implementors§