Skip to content

Commit

Permalink
cargo fmt + clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
tibvdm committed Apr 8, 2024
1 parent edff3dd commit 889af07
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions fa-compression/benches/algorithm1/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use fa_compression::algorithm1::{
decode,
encode
};

use super::util::generate_annotation;

/// Generate a random number of encoded annotations.
Expand Down
1 change: 1 addition & 0 deletions fa-compression/benches/algorithm1/encode.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use criterion::black_box;
use fa_compression::algorithm1::encode;

use super::util::generate_annotation;

/// Generate a random number of decoded annotations.
Expand Down
2 changes: 1 addition & 1 deletion fa-compression/benches/algorithm1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use criterion::criterion_group;

use super::util;

mod encode;
mod decode;
mod encode;

criterion_group!(benches, encode::encode_benchmark, decode::decode_benchmark);
3 changes: 2 additions & 1 deletion fa-compression/benches/algorithm2/decode.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use criterion::black_box;
use fa_compression::algorithm2::{
decode,
encode,
encode,
CompressionTable
};

use super::util::generate_annotation;

fn generate_encoded_annotations_and_table(count: usize) -> (Vec<u8>, CompressionTable) {
Expand Down
4 changes: 3 additions & 1 deletion fa-compression/benches/algorithm2/encode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use criterion::black_box;
use fa_compression::algorithm2::{
encode, CompressionTable
encode,
CompressionTable
};

use super::util::generate_annotation;

fn generate_decoded_annotations_and_table(count: usize) -> (String, CompressionTable) {
Expand Down
2 changes: 1 addition & 1 deletion fa-compression/benches/algorithm2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use criterion::criterion_group;

use super::util;

mod encode;
mod decode;
mod encode;

criterion_group!(benches, encode::encode_benchmark, decode::decode_benchmark);
2 changes: 1 addition & 1 deletion fa-compression/benches/bench_main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use criterion::criterion_main;

mod util;
mod algorithm1;
mod algorithm2;
mod util;

criterion_main!(algorithm1::benches, algorithm2::benches);
5 changes: 4 additions & 1 deletion fa-compression/src/algorithm1/decode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! This module provides a function to decode a byte array into a string representation of
//! annotations.

use super::{CharacterSet, Decode};
use super::{
CharacterSet,
Decode
};

/// The prefixes for the different types of annotations.
static PREFIXES: [&str; 3] = ["EC:", "GO:", "IPR:IPR"];
Expand Down
2 changes: 1 addition & 1 deletion fa-compression/src/algorithm2/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn decode(input: &[u8], compression_table: CompressionTable) -> String {

let mut result = String::with_capacity(input.len() / 3 * 15);
for bytes in input.chunks_exact(3) {
let index = u32::from_le_bytes([ bytes[0], bytes[1], bytes[2], 0 ]) as usize;
let index = u32::from_le_bytes([bytes[0], bytes[1], bytes[2], 0]) as usize;
result.push_str(&compression_table[index].annotation);
result.push(';');
}
Expand Down
7 changes: 5 additions & 2 deletions fa-compression/src/algorithm2/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn encode(input: &str, compression_table: CompressionTable) -> Vec<u8> {

for annotation in input.split(';') {
if let Some(index) = compression_table.index_of(annotation) {
encoded.extend_from_slice(&index.to_le_bytes()[0..3])
encoded.extend_from_slice(&index.to_le_bytes()[0 .. 3])
}
}

Expand Down Expand Up @@ -64,6 +64,9 @@ mod tests {
#[test]
fn test_encode_all() {
let table = create_compresion_table();
assert_eq!(encode("IPR:IPR000001;EC:1.1.1.-;IPR:IPR000003;GO:0000002", table), vec![ 0, 0, 0, 7, 0, 0, 2, 0, 0, 5, 0, 0 ])
assert_eq!(
encode("IPR:IPR000001;EC:1.1.1.-;IPR:IPR000003;GO:0000002", table),
vec![0, 0, 0, 7, 0, 0, 2, 0, 0, 5, 0, 0]
)
}
}
16 changes: 12 additions & 4 deletions fa-compression/src/algorithm2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
mod encode;
mod decode;
mod encode;

use std::ops::Index;

pub use encode::encode;
pub use decode::decode;
pub use encode::encode;

pub struct CompressionTableEntry {
pub annotation: String
}

pub struct CompressionTable {
pub entries: Vec<CompressionTableEntry>,
pub entries: Vec<CompressionTableEntry>
}

impl CompressionTable {
Expand All @@ -28,7 +28,15 @@ impl CompressionTable {
}

pub fn index_of(&self, annotation: &str) -> Option<usize> {
self.entries.iter().position(|entry| entry.annotation == annotation)
self.entries
.iter()
.position(|entry| entry.annotation == annotation)
}
}

impl Default for CompressionTable {
fn default() -> Self {
Self::new()
}

Check warning on line 40 in fa-compression/src/algorithm2/mod.rs

View check run for this annotation

Codecov / codecov/patch

fa-compression/src/algorithm2/mod.rs#L38-L40

Added lines #L38 - L40 were not covered by tests
}

Expand Down

0 comments on commit 889af07

Please sign in to comment.