Skip to content

Commit

Permalink
Chore: bump deps
Browse files Browse the repository at this point in the history
  • Loading branch information
iamazy committed Feb 12, 2024
1 parent ac2b561 commit 7a30999
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 42 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
time: "17:00"
open-pull-requests-limit: 2
43 changes: 43 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: build reed-solomon-erasure

on:
pull_request:
push:
branches:

jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy
- uses: actions/cache@v3
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo
- name: Check code format
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
- uses: actions/cache@v3
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo
- uses: taiki-e/install-action@nextest
- name: Test
run: cargo nextest run --no-fail-fast --all-features

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target/
/Cargo.lock
.idea
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ coveralls = { repository = "darrenldl/reed-solomon-erasure" }
libc = { version = "0.2", optional = true }
# `log2()` impl for `no_std`
libm = "0.2.1"
lru = "0.7.8"
lru = "0.12"
# Efficient `Mutex` implementation for `std` environment
parking_lot = { version = "0.11.2", optional = true }
smallvec = "1.2"
parking_lot = { version = "0.12", optional = true }
smallvec = "1.13"
# `Mutex` implementation for `no_std` environment with the same high-level API as `parking_lot`
spin = { version = "0.9.2", default-features = false, features = ["spin_mutex"] }
spin = { version = "0.9", default-features = false, features = ["spin_mutex"] }

[dev-dependencies]
rand = { version = "0.7.2", features = ["small_rng"] }
quickcheck = "0.9"
rand = { version = "0.8", features = ["small_rng"] }
quickcheck = "1"

# Scientific benchmarking
criterion = { version = "0.4.0", features = ["html_reports"] }
criterion = { version = "0.5", features = ["html_reports"] }

[build-dependencies]
cc = { version = "1.0", optional = true }
cc = { version = "1", optional = true }

[[bench]]
name = "bandwidth"
Expand Down
8 changes: 7 additions & 1 deletion benches/bandwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,11 @@ fn reconstruct_none(c: &mut Criterion) {
}
}

criterion_group!(benches, encode, reconstruct_one, reconstruct_all, reconstruct_none);
criterion_group!(
benches,
encode,
reconstruct_one,
reconstruct_all,
reconstruct_none
);
criterion_main!(benches);
22 changes: 12 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn gen_log_table(polynomial: usize) -> [u8; FIELD_SIZE] {
for log in 0..FIELD_SIZE - 1 {
result[b] = log as u8;

b = b << 1;
b <<= 1;

if FIELD_SIZE <= b {
b = (b - FIELD_SIZE) ^ polynomial;
Expand All @@ -32,8 +32,8 @@ const EXP_TABLE_SIZE: usize = FIELD_SIZE * 2 - 2;
fn gen_exp_table(log_table: &[u8; FIELD_SIZE]) -> [u8; EXP_TABLE_SIZE] {
let mut result: [u8; EXP_TABLE_SIZE] = [0; EXP_TABLE_SIZE];

for i in 1..FIELD_SIZE {
let log = log_table[i] as usize;
for (i, log) in log_table.iter().enumerate().take(FIELD_SIZE).skip(1) {
let log = *log as usize;
result[log] = i as u8;
result[log + FIELD_SIZE - 1] = i as u8;
}
Expand All @@ -58,9 +58,9 @@ fn gen_mul_table(
) -> [[u8; FIELD_SIZE]; FIELD_SIZE] {
let mut result: [[u8; FIELD_SIZE]; FIELD_SIZE] = [[0; 256]; 256];

for a in 0..FIELD_SIZE {
for b in 0..FIELD_SIZE {
result[a][b] = multiply(log_table, exp_table, a as u8, b as u8);
for (a, result_a) in result.iter_mut().enumerate().take(FIELD_SIZE) {
for (b, result_b) in result_a.iter_mut().enumerate().take(FIELD_SIZE) {
*result_b = multiply(log_table, exp_table, a as u8, b as u8);
}
}

Expand Down Expand Up @@ -137,7 +137,7 @@ fn write_tables() {

let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("table.rs");
let mut f = File::create(&dest_path).unwrap();
let mut f = File::create(dest_path).unwrap();

write_table!(1D => f, log_table, "LOG_TABLE", "u8");
write_table!(1D => f, exp_table, "EXP_TABLE", "u8");
Expand Down Expand Up @@ -169,9 +169,11 @@ fn compile_simd_c() {
Err(_error) => {
// On x86-64 enabling Haswell architecture unlocks useful instructions and improves performance
// dramatically while allowing it to run ony modern CPU.
match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str(){
"x86_64" => { build.flag(&"-march=haswell"); },
_ => ()
match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
"x86_64" => {
build.flag(&"-march=haswell");
}
_ => (),
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extern crate alloc;
use alloc::sync::Arc;
use alloc::vec;
use alloc::vec::Vec;
use std::num::NonZeroUsize;

use smallvec::SmallVec;

Expand Down Expand Up @@ -462,7 +463,9 @@ impl<F: Field> ReedSolomon<F> {
parity_shard_count: parity_shards,
total_shard_count: total_shards,
matrix,
data_decode_matrix_cache: Mutex::new(LruCache::new(DATA_DECODE_MATRIX_CACHE_CAPACITY)),
data_decode_matrix_cache: Mutex::new(LruCache::new(
NonZeroUsize::new(DATA_DECODE_MATRIX_CACHE_CAPACITY).unwrap(),
)),
})
}

Expand All @@ -484,8 +487,8 @@ impl<F: Field> ReedSolomon<F> {
inputs: &[T],
outputs: &mut [U],
) {
for i_input in 0..self.data_shard_count {
self.code_single_slice(matrix_rows, i_input, inputs[i_input].as_ref(), outputs);
for (i_input, item) in inputs.iter().enumerate().take(self.data_shard_count) {
self.code_single_slice(matrix_rows, i_input, item.as_ref(), outputs);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
//! and simply leave out the corrupted shards when attempting to reconstruct
//! the missing data.
#![allow(dead_code)]
#![allow(clippy::len_without_is_empty)]
#![allow(clippy::suspicious_arithmetic_impl)]
#![allow(clippy::type_complexity)]
#![allow(clippy::wrong_self_convention)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(test)]
Expand Down Expand Up @@ -100,7 +104,7 @@ pub trait Field: Sized {
assert_eq!(input.len(), out.len());

for (i, o) in input.iter().zip(out) {
*o = Self::mul(elem.clone(), i.clone())
*o = Self::mul(elem, *i)
}
}

Expand All @@ -113,7 +117,7 @@ pub trait Field: Sized {
assert_eq!(input.len(), out.len());

for (i, o) in input.iter().zip(out) {
*o = Self::add(o.clone(), Self::mul(elem.clone(), i.clone()))
*o = Self::add(*o, Self::mul(elem, *i))
}
}
}
Expand Down
31 changes: 13 additions & 18 deletions src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<F: Field> Matrix<F> {
}

pub fn get(&self, r: usize, c: usize) -> F::Elem {
acc!(self, r, c).clone()
acc!(self, r, c)
}

pub fn set(&mut self, r: usize, c: usize, val: F::Elem) {
Expand All @@ -128,7 +128,7 @@ impl<F: Field> Matrix<F> {
for c in 0..rhs.col_count {
let mut val = F::zero();
for i in 0..self.col_count {
let mul = F::mul(acc!(self, r, i).clone(), acc!(rhs, i, c).clone());
let mul = F::mul(acc!(self, r, i), acc!(rhs, i, c));

val = F::add(val, mul);
}
Expand All @@ -148,11 +148,11 @@ impl<F: Field> Matrix<F> {
let mut result = Self::new(self.row_count, self.col_count + rhs.col_count);
for r in 0..self.row_count {
for c in 0..self.col_count {
acc!(result, r, c) = acc!(self, r, c).clone();
acc!(result, r, c) = acc!(self, r, c);
}
let self_column_count = self.col_count;
for c in 0..rhs.col_count {
acc!(result, r, self_column_count + c) = acc!(rhs, r, c).clone();
acc!(result, r, self_column_count + c) = acc!(rhs, r, c);
}
}

Expand All @@ -163,7 +163,7 @@ impl<F: Field> Matrix<F> {
let mut result = Self::new(rmax - rmin, cmax - cmin);
for r in rmin..rmax {
for c in cmin..cmax {
acc!(result, r - rmin, c - cmin) = acc!(self, r, c).clone();
acc!(result, r - rmin, c - cmin) = acc!(self, r, c);
}
}
result
Expand All @@ -180,7 +180,6 @@ impl<F: Field> Matrix<F> {
let (r2_s, _) = self.calc_row_start_end(r2);

if r1 == r2 {
return;
} else {
for i in 0..self.col_count {
self.data.swap(r1_s + i, r2_s + i);
Expand Down Expand Up @@ -208,22 +207,20 @@ impl<F: Field> Matrix<F> {
}
// Scale to 1.
if acc!(self, r, r) != F::one() {
let scale = F::div(F::one(), acc!(self, r, r).clone());
let scale = F::div(F::one(), acc!(self, r, r));
for c in 0..self.col_count {
acc!(self, r, c) = F::mul(scale, acc!(self, r, c).clone());
acc!(self, r, c) = F::mul(scale, acc!(self, r, c));
}
}
// Make everything below the 1 be a 0 by subtracting
// a multiple of it. (Subtraction and addition are
// both exclusive or in the Galois field.)
for r_below in r + 1..self.row_count {
if acc!(self, r_below, r) != F::zero() {
let scale = acc!(self, r_below, r).clone();
let scale = acc!(self, r_below, r);
for c in 0..self.col_count {
acc!(self, r_below, c) = F::add(
acc!(self, r_below, c).clone(),
F::mul(scale, acc!(self, r, c).clone()),
);
acc!(self, r_below, c) =
F::add(acc!(self, r_below, c), F::mul(scale, acc!(self, r, c)));
}
}
}
Expand All @@ -233,12 +230,10 @@ impl<F: Field> Matrix<F> {
for d in 0..self.row_count {
for r_above in 0..d {
if acc!(self, r_above, d) != F::zero() {
let scale = acc!(self, r_above, d).clone();
let scale = acc!(self, r_above, d);
for c in 0..self.col_count {
acc!(self, r_above, c) = F::add(
acc!(self, r_above, c).clone(),
F::mul(scale, acc!(self, d, c).clone()),
);
acc!(self, r_above, c) =
F::add(acc!(self, r_above, c), F::mul(scale, acc!(self, d, c)));
}
}
}
Expand Down

0 comments on commit 7a30999

Please sign in to comment.