Skip to content

Commit

Permalink
Merge pull request #2 from mayeranalytics/0.4.2
Browse files Browse the repository at this point in the history
0.4.2
  • Loading branch information
mayeranalytics authored Nov 13, 2024
2 parents 89ec7ed + 2cdf86f commit 72912d3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CHANGELOG
=========

- 0.4
- 0.4.1 Added codec::generic
- 0.4.2 Fix build system, remove trait default impl dec_buf_len and enc_buf_size,
use template param WT instead of W which is confusing
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "turbopfor_rs"
version = "0.4.1"
version = "0.4.2"
edition = "2021"
authors = ["MM <mmayer@mayeranalytics.com>"]
license = "GPL-2.0"
Expand Down
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A big thansk to [Patrick Zippenfenig](https://github.com/patrick-zippenfenig) fo

## Installation

Cargo should automaticall download, patch and build the turbopfor library.
Cargo should automatically download, patch and build the turbopfor library.

```shell
cargo build
Expand Down Expand Up @@ -119,14 +119,34 @@ println!("{:?}", output);

The `output` `Vec<u32>` is

```
```rust
[0, 1, 2, 3,
0, 0, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0]
```

Clearly, Trubopfor writes more than 4 `u32`s.

### turbopfor_rs::generic

v0.4.1 introduces `turbopfor_rs::generic` that reorganizes the encoders and decoders under a single trait `Encoding` that has four implementations:

- `StandardEncoding` for unsorted integer lists (using codec::dec and enc)
- `IncreasingEncoding` for increasing integer lists (using codec::ddec and denc)
- `StrictlyIncreasingEncoding` for strictly increasing integer lists (using codec::d1dec and d1enc)
- `ZigZagEncoding` for unsorted integer lists (using codec::zdec and zenc)

```rust
let input: Vec<T> = vec![4, 83, 23, 214, 255, 0, 2];
let buf_len = StandardEncoding::<W, T>::enc_buf_size(input.len());
let mut buf = vec![0u8; 1024];
assert!(buf.len() >= buf_len);
let size = StandardEncoding::<W, T>::encode(&input, &mut buf);
println!("{}", size);
```

Having all functions under one trait facilitates generic programming. Otherwise there's nothing new, here.

### Coverage

| | bindings | wrapper | tests | |
Expand Down Expand Up @@ -263,7 +283,7 @@ Exceptions:

Information about buffer sizes is scattered all over the place:

- [Alignment and padding, Issue #59]([Alignment and tailing padding requirements for the decoder APIs · Issue #59 · powturbo/TurboPFor-Integer-Compression · GitHub](https://github.com/powturbo/TurboPFor-Integer-Compression/issues/59):
- [Alignment and padding, Issue #59]([Alignment and tailing padding requirements for the decoder APIs · Issue #59 · powturbo/TurboPFor-Integer-Compression · GitHub](https://github.com/powturbo/TurboPFor-Integer-Compression/issues/59)):

- Alignment for input and output is not required

Expand Down
15 changes: 0 additions & 15 deletions src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,11 @@
use crate::codec::*;
use crate::sample::*;
use std::marker::PhantomData;
use std::mem;
use rand::{ // for testing
prelude::Distribution,
distributions::Standard,
};

pub trait EncodingBase {
type W: Width;
}

pub struct StandardEncodingBase<WT> { _wt: PhantomData<WT> }
pub struct IncreasingEncodingBase<WT> { _wt: PhantomData<WT> }
pub struct StrictlyIncreasingEncodingBase<WT> { _wt: PhantomData<WT> }
pub struct ZigZagEncodingBase<WT> { _wt: PhantomData<WT> }

impl<WT:Width> EncodingBase for StandardEncodingBase<WT> { type W = WT; }
impl<WT:Width> EncodingBase for IncreasingEncodingBase<WT> { type W = WT; }
impl<WT:Width> EncodingBase for StrictlyIncreasingEncodingBase<WT> { type W = WT; }
impl<WT:Width> EncodingBase for ZigZagEncodingBase<WT> { type W = WT; }

/// Trait for encoding types with width.
pub trait Encoding {
type W: Width;
Expand Down

0 comments on commit 72912d3

Please sign in to comment.