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

    const HEADER_BYTE: u8;
    const PHYSICAL_BITS: usize;
Show 14 methods fn num_eq(&self, other: &Self) -> bool;
fn num_cmp(&self, other: &Self) -> Ordering;
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: Vec<u8>) -> QCompressResult<Self>; fn read_from(reader: &mut BitReader) -> QCompressResult<Self> { ... }
fn write_to(self, writer: &mut BitWriter) { ... }
fn le(&self, other: &Self) -> bool { ... }
fn lt(&self, other: &Self) -> bool { ... }
fn ge(&self, other: &Self) -> bool { ... }
fn gt(&self, other: &Self) -> bool { ... }
}
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.

Associated Types

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

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.

Associated Constants

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

Each NumberLike implementation should have a different HeaderByte. 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 10 are used, so 11 would be a good choice for another q_compress-supported data type, and 255 would be a good choice for a custom data type.

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

Lossless check for bit-exact equality. This is important because not all data types support full ordering: https://stackoverflow.com/questions/26489701/why-does-rust-not-implement-total-ordering-via-the-ord-trait-for-f64-and-f32.

Lossless numerical comparison. This is important for the same reason as num_eq. We use it to sort numbers and calculate quantiles. For example, this function can order the many f32 and f64 NaN representations.

Used during compression to convert to an unsigned integer.

Used during decompression to convert back from an unsigned integer.

Used during delta encoding to convert to a signed integer.

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

Returns an uncompressed representation for the number.

Creates a number from an uncompressed representation.

Provided methods

Parses an uncompressed representation of the number from the BitReader.

Appends an uncompressed representation of the number to the BitWriter.

Implementations on Foreign Types

Implementors