Skip to content

Commit

Permalink
run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonVandeVyver committed Oct 24, 2024
1 parent 6dccb19 commit 94894a8
Show file tree
Hide file tree
Showing 25 changed files with 235 additions and 199 deletions.
11 changes: 7 additions & 4 deletions bitarray/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,13 @@ 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: 46 additions & 35 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 @@ -166,7 +166,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 @@ -310,10 +310,13 @@ 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 @@ -332,23 +335,27 @@ 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 @@ -363,16 +370,20 @@ 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: 12 additions & 9 deletions fa-compression/src/algorithm1/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,18 @@ 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 @@ -125,8 +127,9 @@ 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: 4 additions & 3 deletions fa-compression/src/algorithm2/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,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]
)
}
}
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
Loading

0 comments on commit 94894a8

Please sign in to comment.