Skip to content

Commit

Permalink
freshen up (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik authored Dec 26, 2024
1 parent 6c938fa commit 4ee7111
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 42 deletions.
63 changes: 46 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,54 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]

env:
CARGO_TERM_COLOR: always
release:
types: [ published ]
workflow_dispatch:

jobs:
CI:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: taiki-e/install-action@v2
with: { 'tool': 'just' }
- uses: actions/checkout@v4
- name: Ensure this crate has not yet been published (on release)
if: github.event_name == 'release'
run: just check-if-published
- uses: Swatinem/rust-cache@v2
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
- run: just ci-test
- name: Check semver
uses: obi1kenobi/cargo-semver-checks-action@v2

msrv:
name: Test MSRV
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: taiki-e/install-action@v2
with: { tool: just }
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
- name: Read crate metadata
id: metadata
run: echo "rust-version=$(sed -ne 's/rust-version *= *\"\(.*\)\"/\1/p' Cargo.toml)" >> $GITHUB_OUTPUT
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
profile: default
- run: cargo fmt --all -- --check
- run: cargo build
- run: cargo test
- run: cargo clippy -- -Dwarnings
- run: cargo bench
# - name: Coveralls
# uses: coverallsapp/github-action
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
toolchain: ${{ steps.metadata.outputs.rust-version }}
components: rustfmt
- run: just ci-test-msrv

publish:
name: Publish to crates.io
if: startsWith(github.ref, 'refs/tags/')
needs: [ test, msrv ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
16 changes: 13 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
[package]
name = "delta-encoding"
version = "0.4.0"
description = "A library to encode and decode a delta-encoded stream of numbers"
authors = ["Yuri Astrakhan <[email protected]>"]
repository = "https://github.com/nyurik/delta-encoding"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A library to encode and decode a delta-encoded stream of numbers"
repository = "https://github.com/nyurik/delta-encoding"
keywords = ["delta-encoding", "encoding", "encoder", "decoder", "protobuf"]
categories = ["encoding"]
rust-version = "1.78.0"

[dependencies]
num-traits = "0.2"

[dev-dependencies]
criterion = { version = "0.3", features = ["html_reports"] }
criterion = { version = "0.5", features = ["html_reports"] }

[[bench]]
name = "encoder"
harness = false

[lints.rust]
unsafe_code = "forbid"
unused_qualifications = "warn"

[lints.clippy]
pedantic = { level = "warn", priority = -1 }
module_name_repetitions = "allow"
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[![geo on Crates.io](https://img.shields.io/crates/v/delta-encoding.svg)](https://crates.io/crates/delta-encoding)
[![Coverage Status](https://coveralls.io/repos/github/nyurik/delta-encoding/badge.svg)](https://coveralls.io/github/nyurik/delta-encoding)
[![Documentation](https://docs.rs/delta-encoding/badge.svg)](https://docs.rs/delta-encoding)

# Delta-Encoding library

[![GitHub](https://img.shields.io/badge/github-nyurik/delta--encoding-8da0cb?logo=github)](https://github.com/nyurik/delta-encoding)
[![crates.io version](https://img.shields.io/crates/v/delta-encoding)](https://crates.io/crates/delta-encoding)
[![docs.rs](https://img.shields.io/docsrs/delta-encoding)](https://docs.rs/delta-encoding)
[![crates.io license](https://img.shields.io/crates/l/delta-encoding)](https://github.com/nyurik/delta-encoding/blob/main/LICENSE-APACHE)
[![CI build](https://github.com/nyurik/delta-encoding/actions/workflows/ci.yml/badge.svg)](https://github.com/nyurik/delta-encoding/actions)


A simple library for encoding and decoding a stream of values as delta-encoded. For example, if you have a stream of values like this:

```text
Expand Down Expand Up @@ -45,10 +48,23 @@ pub fn main() {
```

## Development
All of these must succeed:
```bash
cargo test # Testing
cargo bench # Benchmarking
cargo fmt # Code format
cargo clippy # Code lints
```

* This project is easier to develop with [just](https://github.com/casey/just#readme), a modern alternative to `make`.
Install it with `cargo install just`.
* To get a list of available commands, run `just`.
* To run tests, use `just test`.

## License

Licensed under either of

* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the
Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.
18 changes: 10 additions & 8 deletions benches/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use delta_encoding::{DeltaEncoder, DeltaEncoderExt};
criterion_group!(benches, bench_map, bench_iter);
criterion_main!(benches);

#[allow(clippy::cast_possible_wrap)]
fn bench_map(c: &mut Criterion) {
let samples: &[u64] = &[1, 1000, 100000];
let samples: &[u64] = &[1, 1000, 100_000];

let mut group = c.benchmark_group("mapping");
for count in samples.iter() {
for count in samples {
group.throughput(Throughput::Bytes(*count * 8));
group.bench_function(format!("Encode {count} i64 values"), move |b| {
b.iter(|| {
Expand All @@ -17,25 +18,26 @@ fn bench_map(c: &mut Criterion) {
.map(|v| enc.encode(v))
.for_each(|x: i64| {
black_box(x);
})
})
});
});
});
}
group.finish();
}

#[allow(clippy::cast_possible_wrap)]
fn bench_iter(c: &mut Criterion) {
let samples: &[u64] = &[1, 1000, 100000];
let samples: &[u64] = &[1, 1000, 100_000];

let mut group = c.benchmark_group("iterator");
for count in samples.iter() {
for count in samples {
group.throughput(Throughput::Bytes(*count * 8));
group.bench_function(format!("Encode {count} i64 values"), move |b| {
b.iter(|| {
(0..(*count as i64)).deltas().for_each(|x: i64| {
black_box(x);
})
})
});
});
});
}
group.finish();
Expand Down
68 changes: 68 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env just --justfile

@_default:
just --list

# Clean all build artifacts
clean:
cargo clean
rm -f Cargo.lock

update:
cargo +nightly -Z unstable-options update --breaking
cargo update

# Run cargo clippy
clippy:
cargo clippy --workspace --all-targets -- -D warnings

# Test code formatting
test-fmt:
cargo fmt --all -- --check

# Run cargo fmt
fmt:
cargo +nightly fmt -- --config imports_granularity=Module,group_imports=StdExternalCrate

# Build and open code documentation
docs:
cargo doc --no-deps --open

# Quick compile
check:
RUSTFLAGS='-D warnings' cargo check --workspace --all-targets

# Run all tests
test:
RUSTFLAGS='-D warnings' cargo test --workspace --all-targets

# Test documentation
test-doc:
cargo test --doc
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps

rust-info:
rustc --version
cargo --version

# Run all tests as expected by CI
ci-test: rust-info test-fmt clippy check test test-doc

# Run minimal subset of tests to ensure compatibility with MSRV
ci-test-msrv: rust-info check test

# Verify that the current version of the crate is not the same as the one published on crates.io
check-if-published:
#!/usr/bin/env bash
LOCAL_VERSION="$(grep '^version =' Cargo.toml | sed -E 's/version = "([^"]*)".*/\1/')"
echo "Detected crate version: $LOCAL_VERSION"
CRATE_NAME="$(grep '^name =' Cargo.toml | head -1 | sed -E 's/name = "(.*)"/\1/')"
echo "Detected crate name: $CRATE_NAME"
PUBLISHED_VERSION="$(cargo search ${CRATE_NAME} | grep "^${CRATE_NAME} =" | sed -E 's/.* = "(.*)".*/\1/')"
echo "Published crate version: $PUBLISHED_VERSION"
if [ "$LOCAL_VERSION" = "$PUBLISHED_VERSION" ]; then
echo "ERROR: The current crate version has already been published."
exit 1
else
echo "The current crate version has not yet been published."
fi
2 changes: 1 addition & 1 deletion src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ where
{
DeltaDecoderIter {
iter: self,
decoder: Default::default(),
decoder: DeltaDecoder::default(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
{
DeltaEncoderIter {
iter: self,
encoder: Default::default(),
encoder: DeltaEncoder::default(),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ pub use decoder::{DeltaDecoder, DeltaDecoderExt, DeltaDecoderIter};

#[cfg(test)]
mod tests {
use super::*;
use std::iter::zip;

use super::*;

pub(crate) const TEST_DATA: &[(&[i64], &[i64])] = &[
(&[], &[]),
(&[0], &[0]),
Expand Down

0 comments on commit 4ee7111

Please sign in to comment.