Skip to content

Commit

Permalink
cargo fmt to format code
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonVandeVyver committed Sep 12, 2024
1 parent 4be9148 commit d1d8f88
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 215 deletions.
11 changes: 4 additions & 7 deletions bitarray/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,10 @@ mod tests {
let mut buffer = Vec::new();
bitarray.write_binary(&mut buffer).unwrap();

assert_eq!(
buffer,
vec![
0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, 0xde, 0xbc, 0x0a, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00,
0x00, 0x00, 0x00, 0x56, 0x34, 0x12, 0xf0
]
);
assert_eq!(buffer, vec![
0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, 0xde, 0xbc, 0x0a, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00, 0x00,
0x00, 0x00, 0x56, 0x34, 0x12, 0xf0
]);
}

#[test]
Expand Down
81 changes: 35 additions & 46 deletions bitarray/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod binary;

use std::{
cmp::max,
io::{Result, Write},
io::{Result, Write}
};

/// Re-export the `Binary` trait.
Expand All @@ -19,7 +19,7 @@ pub struct BitArray {
/// The length of the bit array.
len: usize,
/// The number of bits in a single element of the data vector.
bits_per_value: usize,
bits_per_value: usize
}

impl BitArray {
Expand All @@ -39,7 +39,7 @@ impl BitArray {
data: vec![0; capacity * bits_per_value / 64 + extra],
mask: (1 << bits_per_value) - 1,
len: capacity,
bits_per_value,
bits_per_value
}
}

Expand Down Expand Up @@ -167,7 +167,7 @@ pub fn data_to_writer(
data: Vec<i64>,
bits_per_value: usize,
max_capacity: usize,
writer: &mut impl Write,
writer: &mut impl Write
) -> Result<()> {
// Update the max capacity to be a multiple of the greatest common divisor of the bits per value
// and 64. This is done to ensure that the bit array can store the data entirely
Expand Down Expand Up @@ -311,13 +311,10 @@ mod tests {

data_to_writer(data, 40, 2, &mut writer).unwrap();

assert_eq!(
writer,
vec![
0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, 0xde, 0xbc, 0x0a, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00,
0x00, 0x00, 0x00, 0x56, 0x34, 0x12, 0xf0
]
);
assert_eq!(writer, vec![
0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, 0xde, 0xbc, 0x0a, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00, 0x00,
0x00, 0x00, 0x56, 0x34, 0x12, 0xf0
]);
}

#[test]
Expand All @@ -336,27 +333,23 @@ mod tests {

data_to_writer(data, 32, 8, &mut writer).unwrap();

assert_eq!(
writer,
vec![
0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, 0x33, 0x33, 0x33, 0x66,
0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88, 0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0xaa, 0xaa,
0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee,
0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x22, 0x22, 0x22, 0x22,
0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, 0x33, 0x33, 0x33, 0x66, 0x66, 0x66, 0x66, 0x55,
0x55, 0x55, 0x55, 0x88, 0x88, 0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99,
0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd,
0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11,
0x44, 0x44, 0x44, 0x44, 0x33, 0x33, 0x33, 0x33, 0x66, 0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88,
0x88, 0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc,
0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00,
0x00, 0xff, 0xff, 0xff, 0xff, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44,
0x33, 0x33, 0x33, 0x33, 0x66, 0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88, 0x88, 0x88, 0x77,
0x77, 0x77, 0x77, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb,
0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
0xff
]
);
assert_eq!(writer, vec![
0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, 0x33, 0x33, 0x33, 0x66, 0x66,
0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88, 0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0xaa, 0xaa, 0xaa, 0xaa,
0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd,
0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11,
0x44, 0x44, 0x44, 0x44, 0x33, 0x33, 0x33, 0x33, 0x66, 0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88,
0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc,
0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, 0x33, 0x33, 0x33,
0x66, 0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88, 0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0xaa, 0xaa,
0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee,
0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11,
0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, 0x33, 0x33, 0x33, 0x66, 0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55,
0x88, 0x88, 0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc,
0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff
]);
}

#[test]
Expand All @@ -371,20 +364,16 @@ mod tests {

data_to_writer(data, 32, 8, &mut writer).unwrap();

assert_eq!(
writer,
vec![
0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, 0x33, 0x33, 0x33, 0x66,
0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88, 0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0xaa, 0xaa,
0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee,
0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x22, 0x22, 0x22, 0x22,
0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, 0x33, 0x33, 0x33, 0x66, 0x66, 0x66, 0x66, 0x55,
0x55, 0x55, 0x55, 0x88, 0x88, 0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99,
0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd,
0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11,
0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33
]
);
assert_eq!(writer, vec![
0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, 0x33, 0x33, 0x33, 0x66, 0x66,
0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88, 0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0xaa, 0xaa, 0xaa, 0xaa,
0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd,
0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11,
0x44, 0x44, 0x44, 0x44, 0x33, 0x33, 0x33, 0x33, 0x66, 0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88,
0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc,
0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33
]);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion fa-compression/benches/algorithm1/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn decode_benchmark(c: &mut criterion::Criterion) {
b.iter_batched(
|| generate_encoded_annotations(100),
|annotations| black_box(decode(annotations.as_slice())),
criterion::BatchSize::SmallInput,
criterion::BatchSize::SmallInput
)
});
}
2 changes: 1 addition & 1 deletion fa-compression/benches/algorithm1/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn encode_benchmark(c: &mut criterion::Criterion) {
b.iter_batched(
|| generate_decoded_annotations(100),
|annotations| black_box(encode(annotations.as_str())),
criterion::BatchSize::SmallInput,
criterion::BatchSize::SmallInput
)
});
}
2 changes: 1 addition & 1 deletion fa-compression/benches/algorithm2/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn decode_benchmark(c: &mut criterion::Criterion) {
b.iter_batched(
|| generate_encoded_annotations_and_table(100),
|(annotations, ct)| black_box(decode(annotations.as_slice(), ct)),
criterion::BatchSize::SmallInput,
criterion::BatchSize::SmallInput
)
});
}
2 changes: 1 addition & 1 deletion fa-compression/benches/algorithm2/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn encode_benchmark(c: &mut criterion::Criterion) {
b.iter_batched(
|| generate_decoded_annotations_and_table(100),
|(annotations, ct)| black_box(encode(annotations.as_str(), ct)),
criterion::BatchSize::SmallInput,
criterion::BatchSize::SmallInput
)
});
}
2 changes: 1 addition & 1 deletion fa-compression/benches/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ pub fn generate_annotation(random: &mut ThreadRng) -> String {
0 => generate_ipr(random),
1 => generate_go(random),
2 => generate_ec(random),
_ => unreachable!(),
_ => unreachable!()
}
}
21 changes: 9 additions & 12 deletions fa-compression/src/algorithm1/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,16 @@ mod tests {

#[test]
fn test_encode_no_ec() {
assert_eq!(
encode("IPR:IPR016364;GO:0009279;IPR:IPR008816"),
vec![225, 17, 163, 138, 225, 39, 71, 95, 17, 153, 39]
)
assert_eq!(encode("IPR:IPR016364;GO:0009279;IPR:IPR008816"), vec![
225, 17, 163, 138, 225, 39, 71, 95, 17, 153, 39
])
}

#[test]
fn test_encode_no_go() {
assert_eq!(
encode("IPR:IPR016364;EC:1.1.1.-;EC:1.2.1.7"),
vec![44, 44, 44, 191, 44, 60, 44, 142, 225, 39, 71, 80]
)
assert_eq!(encode("IPR:IPR016364;EC:1.1.1.-;EC:1.2.1.7"), vec![
44, 44, 44, 191, 44, 60, 44, 142, 225, 39, 71, 80
])
}

#[test]
Expand All @@ -127,9 +125,8 @@ mod tests {

#[test]
fn test_encode_all() {
assert_eq!(
encode("IPR:IPR016364;EC:1.1.1.-;IPR:IPR032635;GO:0009279;IPR:IPR008816"),
vec![44, 44, 44, 190, 17, 26, 56, 174, 18, 116, 117, 241, 67, 116, 111, 17, 153, 39]
)
assert_eq!(encode("IPR:IPR016364;EC:1.1.1.-;IPR:IPR032635;GO:0009279;IPR:IPR008816"), vec![
44, 44, 44, 190, 17, 26, 56, 174, 18, 116, 117, 241, 67, 116, 111, 17, 153, 39
])
}
}
8 changes: 4 additions & 4 deletions fa-compression/src/algorithm1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ enum CharacterSet {
Comma,

/// Annotation separator
Semicolon,
Semicolon
}

impl Encode for CharacterSet {
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Encode for CharacterSet {
b'n' => CharacterSet::Preliminary,
b',' => CharacterSet::Comma,
b';' => CharacterSet::Semicolon,
_ => panic!("Invalid character"),
_ => panic!("Invalid character")
}
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ impl Decode for CharacterSet {
13 => 'n',
14 => ',',
15 => ';',
_ => panic!("Invalid character"),
_ => panic!("Invalid character")
}
}
}
Expand Down Expand Up @@ -189,7 +189,7 @@ mod tests {
CharacterSet::Point,
CharacterSet::Preliminary,
CharacterSet::Comma,
CharacterSet::Semicolon,
CharacterSet::Semicolon
];

#[test]
Expand Down
7 changes: 3 additions & 4 deletions fa-compression/src/algorithm2/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ 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
])
}
}
4 changes: 2 additions & 2 deletions fa-compression/src/algorithm2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ pub use encode::encode;
/// Represents an entry in the compression table.
#[doc(hidden)]
pub struct CompressionTableEntry {
annotation: String,
annotation: String
}

/// Represents a compression table.
pub struct CompressionTable {
/// List of annotations in the compression table.
entries: Vec<CompressionTableEntry>,
entries: Vec<CompressionTableEntry>
}

impl CompressionTable {
Expand Down
8 changes: 4 additions & 4 deletions libsais64-rs/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use std::{
error::Error,
fmt::{Display, Formatter},
path::{Path, PathBuf},
process::{Command, ExitStatus},
process::{Command, ExitStatus}
};

/// Custom error for compilation of the C library
#[derive(Debug)]
struct CompileError<'a> {
command: &'a str,
exit_code: Option<i32>,
exit_code: Option<i32>
}

impl<'a> Display for CompileError<'a> {
Expand Down Expand Up @@ -43,7 +43,7 @@ impl<'a> Error for CompileError<'a> {}
fn exit_status_to_result(name: &str, exit_status: ExitStatus) -> Result<(), CompileError> {
match exit_status.success() {
true => Ok(()),
false => Err(CompileError { command: name, exit_code: exit_status.code() }),
false => Err(CompileError { command: name, exit_code: exit_status.code() })
}
}

Expand All @@ -61,7 +61,7 @@ fn main() -> Result<(), Box<dyn Error>> {
Command::new("rm").args(["libsais/CMakeCache.txt"]).status().unwrap_or_default(); // if removing fails, it is since the cmake cache did not exist, we just can ignore it
exit_status_to_result(
"cmake",
Command::new("cmake").args(["-DCMAKE_BUILD_TYPE=\"Release\"", "libsais", "-Blibsais"]).status()?,
Command::new("cmake").args(["-DCMAKE_BUILD_TYPE=\"Release\"", "libsais", "-Blibsais"]).status()?
)?;
exit_status_to_result("make", Command::new("make").args(["-C", "libsais"]).status()?)?;

Expand Down
6 changes: 1 addition & 5 deletions libsais64-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
pub fn sais64(text: &[u8]) -> Option<Vec<i64>> {
let mut sa = vec![0; text.len()];
let exit_code = unsafe { libsais64(text.as_ptr(), sa.as_mut_ptr(), text.len() as i64, 0, std::ptr::null_mut()) };
if exit_code == 0 {
Some(sa)
} else {
None
}
if exit_code == 0 { Some(sa) } else { None }
}

#[cfg(test)]
Expand Down
10 changes: 5 additions & 5 deletions sa-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ pub struct Arguments {
pub construction_algorithm: SAConstructionAlgorithm,
/// If the suffix array should be compressed (default value true)
#[arg(short, long, default_value_t = false)]
pub compress_sa: bool,
pub compress_sa: bool
}

/// Enum representing the two possible algorithms to construct the suffix array
#[derive(ValueEnum, Clone, Debug, PartialEq)]
pub enum SAConstructionAlgorithm {
LibDivSufSort,
LibSais,
LibSais
}

/// Build a sparse suffix array from the given text
Expand All @@ -48,15 +48,15 @@ pub enum SAConstructionAlgorithm {
pub fn build_ssa(
text: &mut Vec<u8>,
construction_algorithm: &SAConstructionAlgorithm,
sparseness_factor: u8,
sparseness_factor: u8
) -> Result<Vec<i64>, Box<dyn Error>> {
// translate all L's to a I
translate_l_to_i(text);

// Build the suffix array using the selected algorithm
let mut sa = match construction_algorithm {
SAConstructionAlgorithm::LibSais => libsais64_rs::sais64(text),
SAConstructionAlgorithm::LibDivSufSort => libdivsufsort_rs::divsufsort64(text),
SAConstructionAlgorithm::LibDivSufSort => libdivsufsort_rs::divsufsort64(text)
}
.ok_or("Building suffix array failed")?;

Expand Down Expand Up @@ -125,7 +125,7 @@ mod tests {
"2",
"--construction-algorithm",
"lib-div-suf-sort",
"--compress-sa",
"--compress-sa"
]);

assert_eq!(args.database_file, "database.fa");
Expand Down
Loading

0 comments on commit d1d8f88

Please sign in to comment.