From 9f3d6f46ed1f60382d1f42354b29bf9b1be3eedb Mon Sep 17 00:00:00 2001 From: tibvdm Date: Sat, 18 May 2024 00:41:59 +0200 Subject: [PATCH] fmt + clippy --- bitarray/src/binary.rs | 39 +++++++------ bitarray/src/lib.rs | 38 ++++++++----- sa-builder/src/lib.rs | 16 +++--- sa-builder/src/main.rs | 42 +++++++------- sa-compression/src/lib.rs | 80 ++++++++++++++++---------- sa-index/src/binary.rs | 108 +++++++++++++++++++----------------- sa-index/src/lib.rs | 20 +++---- sa-index/src/sa_searcher.rs | 6 +- sa-server/src/main.rs | 12 +++- 9 files changed, 209 insertions(+), 152 deletions(-) diff --git a/bitarray/src/binary.rs b/bitarray/src/binary.rs index ecd27a5..59b3293 100644 --- a/bitarray/src/binary.rs +++ b/bitarray/src/binary.rs @@ -1,6 +1,11 @@ //! This module provides utilities for reading and writing the bitarray as binary. -use std::io::{BufRead, Read, Result, Write}; +use std::io::{ + BufRead, + Read, + Result, + Write +}; use crate::BitArray; @@ -61,11 +66,12 @@ impl Binary for BitArray { self.data.clear(); let mut buffer = vec![0; 8 * 1024]; - + loop { let (finished, bytes_read) = fill_buffer(&mut reader, &mut buffer); - for buffer_slice in buffer[..bytes_read].chunks_exact(8) { - self.data.push(u64::from_le_bytes(buffer_slice.try_into().unwrap())); + for buffer_slice in buffer[.. bytes_read].chunks_exact(8) { + self.data + .push(u64::from_le_bytes(buffer_slice.try_into().unwrap())); } if finished { @@ -86,8 +92,8 @@ impl Binary for BitArray { /// /// # Returns /// -/// Returns a tuple `(finished, bytes_read)` where `finished` indicates whether the end of the input is reached, -/// and `bytes_read` is the number of bytes read into the buffer. +/// Returns a tuple `(finished, bytes_read)` where `finished` indicates whether the end of the input +/// is reached, and `bytes_read` is the number of bytes read into the buffer. fn fill_buffer(input: &mut T, buffer: &mut Vec) -> (bool, usize) { // Store the buffer size in advance, because rust will complain // about the buffer being borrowed mutably while it's borrowed @@ -109,7 +115,7 @@ fn fill_buffer(input: &mut T, buffer: &mut Vec) -> (bool, usize) { // We've read {bytes_read} bytes Ok(bytes_read) => { // Shrink the writable buffer slice - writable_buffer_space = writable_buffer_space[bytes_read..].as_mut(); + writable_buffer_space = writable_buffer_space[bytes_read ..].as_mut(); } Err(err) => { @@ -137,7 +143,7 @@ mod tests { let mut input = input_str.as_bytes(); let mut buffer = vec![0; 800]; - + loop { let (finished, bytes_read) = fill_buffer(&mut input, &mut buffer); @@ -170,19 +176,20 @@ 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] fn test_read_binary() { let 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 + 0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, 0xde, 0xbc, 0x0a, 0x89, 0x67, 0x45, + 0x23, 0x01, 0x00, 0x00, 0x00, 0x00, 0x56, 0x34, 0x12, 0xf0, ]; let mut bitarray = BitArray::with_capacity(4, 40); diff --git a/bitarray/src/lib.rs b/bitarray/src/lib.rs index 0b1f2bc..0ff6b9a 100644 --- a/bitarray/src/lib.rs +++ b/bitarray/src/lib.rs @@ -2,7 +2,10 @@ mod binary; -use std::io::{Result, Write}; +use std::io::{ + Result, + Write +}; /// Re-export the `Binary` trait. pub use binary::Binary; @@ -10,11 +13,11 @@ pub use binary::Binary; /// A fixed-size bit array implementation. pub struct BitArray { /// The underlying data storage for the bit array. - data: Vec, + data: Vec, /// The mask used to extract the relevant bits from each element in the data vector. - mask: u64, + mask: u64, /// The length of the bit array. - len: usize, + len: usize, /// The number of bits in a single element of the data vector. bits_per_value: usize } @@ -34,7 +37,7 @@ impl BitArray { Self { data: vec![0; capacity * bits_per_value / 64 + 1], mask: (1 << bits_per_value) - 1, - len: capacity, + len: capacity, bits_per_value } } @@ -56,7 +59,8 @@ impl BitArray { if start_block_offset + self.bits_per_value <= 64 { // Shift the value to the right so that the relevant bits are in the least significant // position Then mask out the irrelevant bits - return self.data[start_block] >> (64 - start_block_offset - self.bits_per_value) & self.mask; + return self.data[start_block] >> (64 - start_block_offset - self.bits_per_value) + & self.mask; } let end_block = (index + 1) * self.bits_per_value / 64; @@ -87,7 +91,8 @@ impl BitArray { // If the value is contained within a single block if start_block_offset + self.bits_per_value <= 64 { // Clear the relevant bits in the start block - self.data[start_block] &= !(self.mask << (64 - start_block_offset - self.bits_per_value)); + self.data[start_block] &= + !(self.mask << (64 - start_block_offset - self.bits_per_value)); // Set the relevant bits in the start block self.data[start_block] |= value << (64 - start_block_offset - self.bits_per_value); return; @@ -146,13 +151,14 @@ impl BitArray { /// /// A `Result` indicating whether the write operation was successful or not. pub fn data_to_writer( - data: Vec, + data: Vec, bits_per_value: usize, max_capacity: usize, - writer: &mut impl Write, + writer: &mut impl Write ) -> Result<()> { // Calculate the capacity of the bit array so the data buffer can be stored entirely - // This makes the process of writing partial data to the writer easier as bounds checking is not needed + // This makes the process of writing partial data to the writer easier as bounds checking is not + // needed let capacity = max_capacity / (bits_per_value * 64) * bits_per_value * 64; // If the capacity is 0, we can write the data directly to the writer @@ -255,11 +261,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] diff --git a/sa-builder/src/lib.rs b/sa-builder/src/lib.rs index 7fe320c..41cb0d2 100644 --- a/sa-builder/src/lib.rs +++ b/sa-builder/src/lib.rs @@ -73,14 +73,14 @@ pub fn build_ssa( } /// Translate all L's to I's in the given text -/// +/// /// # Arguments /// * `text` - The text in which we want to translate the L's to I's -/// +/// /// # Returns -/// +/// /// The text with all L's translated to I's -fn translate_l_to_i(text: &mut Vec) { +fn translate_l_to_i(text: &mut [u8]) { for character in text.iter_mut() { if *character == b'L' { *character = b'I' @@ -89,13 +89,13 @@ fn translate_l_to_i(text: &mut Vec) { } /// Sample the suffix array with the given sparseness factor -/// +/// /// # Arguments /// * `sa` - The suffix array that we want to sample /// * `sparseness_factor` - The sparseness factor used for sampling -/// +/// /// # Returns -/// +/// /// The sampled suffix array fn sample_sa(sa: &mut Vec, sparseness_factor: u8) { if sparseness_factor <= 1 { @@ -110,7 +110,7 @@ fn sample_sa(sa: &mut Vec, sparseness_factor: u8) { current_sampled_index += 1; } } - + // make shorter sa.resize(current_sampled_index, 0); } diff --git a/sa-builder/src/main.rs b/sa-builder/src/main.rs index ca07bff..a78fdce 100644 --- a/sa-builder/src/main.rs +++ b/sa-builder/src/main.rs @@ -1,12 +1,18 @@ -use std::{fs::{File, OpenOptions}, io::Result}; +use std::{ + fs::{ + File, + OpenOptions + }, + io::Result +}; use clap::Parser; use sa_builder::{ build_ssa, Arguments }; -use sa_index::binary::dump_suffix_array; use sa_compression::dump_compressed_suffix_array; +use sa_index::binary::dump_suffix_array; use sa_mappings::{ proteins::Proteins, taxonomy::{ @@ -25,34 +31,32 @@ fn main() { compress_sa } = Arguments::parse(); - let taxon_id_calculator = TaxonAggregator::try_from_taxonomy_file(&taxonomy, AggregationMethod::LcaStar).unwrap_or_else( - |err| eprint_and_exit(err.to_string().as_str()) - ); + let taxon_id_calculator = + TaxonAggregator::try_from_taxonomy_file(&taxonomy, AggregationMethod::LcaStar) + .unwrap_or_else(|err| eprint_and_exit(err.to_string().as_str())); // read input - let mut data = Proteins::try_from_database_file_without_annotations(&database_file, &taxon_id_calculator).unwrap_or_else( - |err| eprint_and_exit(err.to_string().as_str()) - ); + let mut data = + Proteins::try_from_database_file_without_annotations(&database_file, &taxon_id_calculator) + .unwrap_or_else(|err| eprint_and_exit(err.to_string().as_str())); // calculate sparse suffix array - let sa = build_ssa(&mut data, &construction_algorithm, sparseness_factor).unwrap_or_else( - |err| eprint_and_exit(err.to_string().as_str()) - ); + let sa = build_ssa(&mut data, &construction_algorithm, sparseness_factor) + .unwrap_or_else(|err| eprint_and_exit(err.to_string().as_str())); // open the output file - let mut file = open_file(&output).unwrap_or_else( - |err| eprint_and_exit(err.to_string().as_str()) - ); + let mut file = + open_file(&output).unwrap_or_else(|err| eprint_and_exit(err.to_string().as_str())); if compress_sa { let bits_per_value = (data.len() as f64).log2().ceil() as usize; - if let Err(err) = dump_compressed_suffix_array(sa, sparseness_factor, bits_per_value, &mut file) { - eprint_and_exit(err.to_string().as_str()); - }; - } else { - if let Err(err) = dump_suffix_array(&sa, sparseness_factor, &mut file) { + if let Err(err) = + dump_compressed_suffix_array(sa, sparseness_factor, bits_per_value, &mut file) + { eprint_and_exit(err.to_string().as_str()); }; + } else if let Err(err) = dump_suffix_array(&sa, sparseness_factor, &mut file) { + eprint_and_exit(err.to_string().as_str()); } } diff --git a/sa-compression/src/lib.rs b/sa-compression/src/lib.rs index a762bf7..62362ac 100644 --- a/sa-compression/src/lib.rs +++ b/sa-compression/src/lib.rs @@ -1,6 +1,16 @@ -use std::{error::Error, io::{BufRead, Write}}; +use std::{ + error::Error, + io::{ + BufRead, + Write + } +}; -use bitarray::{data_to_writer, Binary, BitArray}; +use bitarray::{ + data_to_writer, + Binary, + BitArray +}; /// Writes the compressed suffix array to a writer. /// @@ -15,23 +25,30 @@ use bitarray::{data_to_writer, Binary, BitArray}; /// /// Returns an error if writing to the writer fails. pub fn dump_compressed_suffix_array( - sa: Vec, + sa: Vec, sparseness_factor: u8, bits_per_value: usize, - writer: &mut impl Write, + writer: &mut impl Write ) -> Result<(), Box> { // Write the flags to the writer // 00000001 indicates that the suffix array is compressed - writer.write(&[bits_per_value as u8]).map_err(|_| "Could not write the required bits to the writer")?; + writer + .write(&[bits_per_value as u8]) + .map_err(|_| "Could not write the required bits to the writer")?; // Write the sparseness factor to the writer - writer.write(&[sparseness_factor]).map_err(|_| "Could not write the sparseness factor to the writer")?; + writer + .write(&[sparseness_factor]) + .map_err(|_| "Could not write the sparseness factor to the writer")?; // Write the size of the suffix array to the writer - writer.write(&(sa.len() as u64).to_le_bytes()).map_err(|_| "Could not write the size of the suffix array to the writer")?; + writer + .write(&(sa.len() as u64).to_le_bytes()) + .map_err(|_| "Could not write the size of the suffix array to the writer")?; // Compress the suffix array and write it to the writer - data_to_writer(sa, bits_per_value, 8 * 1024, writer).map_err(|_| "Could not write the compressed suffix array to the writer")?; + data_to_writer(sa, bits_per_value, 8 * 1024, writer) + .map_err(|_| "Could not write the compressed suffix array to the writer")?; Ok(()) } @@ -52,17 +69,23 @@ pub fn load_compressed_suffix_array( ) -> Result<(u8, BitArray), Box> { // Read the sample rate from the binary file (1 byte) let mut sample_rate_buffer = [0_u8; 1]; - reader.read_exact(&mut sample_rate_buffer).map_err(|_| "Could not read the sample rate from the binary file")?; + reader + .read_exact(&mut sample_rate_buffer) + .map_err(|_| "Could not read the sample rate from the binary file")?; let sample_rate = sample_rate_buffer[0]; // Read the size of the suffix array from the binary file (8 bytes) let mut size_buffer = [0_u8; 8]; - reader.read_exact(&mut size_buffer).map_err(|_| "Could not read the size of the suffix array from the binary file")?; + reader + .read_exact(&mut size_buffer) + .map_err(|_| "Could not read the size of the suffix array from the binary file")?; let size = u64::from_le_bytes(size_buffer) as usize; // Read the compressed suffix array from the binary file let mut compressed_suffix_array = BitArray::with_capacity(size, bits_per_value); - compressed_suffix_array.read_binary(reader).map_err(|_| "Could not read the compressed suffix array from the binary file")?; + compressed_suffix_array + .read_binary(reader) + .map_err(|_| "Could not read the compressed suffix array from the binary file")?; Ok((sample_rate, compressed_suffix_array)) } @@ -78,36 +101,33 @@ mod tests { let mut writer = vec![]; dump_compressed_suffix_array(sa, 1, 8, &mut writer).unwrap(); - assert_eq!(writer, vec![ - // bits per value - 8, - // sparseness factor - 1, - // size of the suffix array - 10, 0, 0, 0, 0, 0, 0, 0, - // compressed suffix array - 8, 7, 6, 5, 4, 3, 2, 1, - 0, 0, 0, 0, 0, 0, 10, 9 - ]); + assert_eq!( + writer, + vec![ + // bits per value + 8, // sparseness factor + 1, // size of the suffix array + 10, 0, 0, 0, 0, 0, 0, 0, // compressed suffix array + 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 10, 9 + ] + ); } #[test] fn test_load_compressed_suffix_array() { let data = vec![ // sparseness factor - 1, - // size of the suffix array - 10, 0, 0, 0, 0, 0, 0, 0, - // compressed suffix array - 8, 7, 6, 5, 4, 3, 2, 1, - 0, 0, 0, 0, 0, 0, 10, 9 + 1, // size of the suffix array + 10, 0, 0, 0, 0, 0, 0, 0, // compressed suffix array + 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 10, 9, ]; let mut reader = std::io::BufReader::new(&data[..]); - let (sample_rate, compressed_suffix_array) = load_compressed_suffix_array(&mut reader, 8).unwrap(); + let (sample_rate, compressed_suffix_array) = + load_compressed_suffix_array(&mut reader, 8).unwrap(); assert_eq!(sample_rate, 1); - for i in 0..10 { + for i in 0 .. 10 { assert_eq!(compressed_suffix_array.get(i), i as u64 + 1); } } diff --git a/sa-index/src/binary.rs b/sa-index/src/binary.rs index f9ed95d..48e1e84 100644 --- a/sa-index/src/binary.rs +++ b/sa-index/src/binary.rs @@ -1,4 +1,11 @@ -use std::{error::Error, io::{BufRead, Read, Write}}; +use std::{ + error::Error, + io::{ + BufRead, + Read, + Write + } +}; /// The `Binary` trait provides methods for reading and writing a struct as binary. pub trait Binary { @@ -57,10 +64,10 @@ impl Binary for Vec { self.clear(); let mut buffer = vec![0; 8 * 1024]; - + loop { let (finished, bytes_read) = fill_buffer(&mut reader, &mut buffer); - for buffer_slice in buffer[..bytes_read].chunks_exact(8) { + for buffer_slice in buffer[.. bytes_read].chunks_exact(8) { self.push(i64::from_le_bytes(buffer_slice.try_into().unwrap())); } @@ -87,21 +94,28 @@ impl Binary for Vec { pub fn dump_suffix_array( sa: &Vec, sparseness_factor: u8, - writer: &mut impl Write, + writer: &mut impl Write ) -> Result<(), Box> { // Write the required bits to the writer // 01000000 indicates that the suffix array is not compressed - writer.write(&[64_u8]).map_err(|_| "Could not write the required bits to the writer")?; + writer + .write(&[64_u8]) + .map_err(|_| "Could not write the required bits to the writer")?; // Write the sparseness factor to the writer - writer.write(&[sparseness_factor]).map_err(|_| "Could not write the sparseness factor to the writer")?; + writer + .write(&[sparseness_factor]) + .map_err(|_| "Could not write the sparseness factor to the writer")?; // Write the size of the suffix array to the writer let sa_len = sa.len(); - writer.write(&(sa_len).to_le_bytes()).map_err(|_| "Could not write the size of the suffix array to the writer")?; + writer + .write(&(sa_len).to_le_bytes()) + .map_err(|_| "Could not write the size of the suffix array to the writer")?; // Write the suffix array to the writer - sa.write_binary(writer).map_err(|_| "Could not write the suffix array to the writer")?; + sa.write_binary(writer) + .map_err(|_| "Could not write the suffix array to the writer")?; Ok(()) } @@ -121,16 +135,21 @@ pub fn dump_suffix_array( pub fn load_suffix_array(reader: &mut impl BufRead) -> Result<(u8, Vec), Box> { // Read the sample rate from the binary file (1 byte) let mut sample_rate_buffer = [0_u8; 1]; - reader.read_exact(&mut sample_rate_buffer).map_err(|_| "Could not read the sample rate from the binary file")?; + reader + .read_exact(&mut sample_rate_buffer) + .map_err(|_| "Could not read the sample rate from the binary file")?; let sample_rate = sample_rate_buffer[0]; // Read the size of the suffix array from the binary file (8 bytes) let mut size_buffer = [0_u8; 8]; - reader.read_exact(&mut size_buffer).map_err(|_| "Could not read the size of the suffix array from the binary file")?; + reader + .read_exact(&mut size_buffer) + .map_err(|_| "Could not read the size of the suffix array from the binary file")?; let size = u64::from_le_bytes(size_buffer) as usize; let mut sa = Vec::with_capacity(size); - sa.read_binary(reader).map_err(|_| "Could not read the suffix array from the binary file")?; + sa.read_binary(reader) + .map_err(|_| "Could not read the suffix array from the binary file")?; Ok((sample_rate, sa)) } @@ -144,8 +163,8 @@ pub fn load_suffix_array(reader: &mut impl BufRead) -> Result<(u8, Vec), Bo /// /// # Returns /// -/// Returns a tuple `(finished, bytes_read)` where `finished` indicates whether the end of the input is reached, -/// and `bytes_read` is the number of bytes read into the buffer. +/// Returns a tuple `(finished, bytes_read)` where `finished` indicates whether the end of the input +/// is reached, and `bytes_read` is the number of bytes read into the buffer. fn fill_buffer(input: &mut T, buffer: &mut Vec) -> (bool, usize) { // Store the buffer size in advance, because rust will complain // about the buffer being borrowed mutably while it's borrowed @@ -167,7 +186,7 @@ fn fill_buffer(input: &mut T, buffer: &mut Vec) -> (bool, usize) { // We've read {bytes_read} bytes Ok(bytes_read) => { // Shrink the writable buffer slice - writable_buffer_space = writable_buffer_space[bytes_read..].as_mut(); + writable_buffer_space = writable_buffer_space[bytes_read ..].as_mut(); } Err(err) => { @@ -195,7 +214,7 @@ mod tests { let mut input = input_str.as_bytes(); let mut buffer = vec![0; 800]; - + loop { let (finished, bytes_read) = fill_buffer(&mut input, &mut buffer); @@ -224,23 +243,20 @@ mod tests { values.write_binary(&mut buffer).unwrap(); - assert_eq!(buffer, vec![ - 1, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 0, 0, 0, 0, - 5, 0, 0, 0, 0, 0, 0, 0 - ]); + assert_eq!( + buffer, + vec![ + 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0 + ] + ); } #[test] fn test_read_binary() { let buffer = vec![ - 1, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 0, 0, 0, 0, - 5, 0, 0, 0, 0, 0, 0, 0 + 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, + 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, ]; let mut values = Vec::new(); @@ -256,35 +272,27 @@ mod tests { dump_suffix_array(&sa, 1, &mut buffer).unwrap(); - assert_eq!(buffer, vec![ - // required bits - 64, - // Sparseness factor - 1, - // Size of the suffix array - 5, 0, 0, 0, 0, 0, 0, 0, - // Suffix array - 1, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 0, 0, 0, 0, - 5, 0, 0, 0, 0, 0, 0, 0 - ]); + assert_eq!( + buffer, + vec![ + // required bits + 64, // Sparseness factor + 1, // Size of the suffix array + 5, 0, 0, 0, 0, 0, 0, 0, // Suffix array + 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0 + ] + ); } #[test] fn test_load_suffix_array() { let buffer = vec![ // Sample rate - 1, - // Size of the suffix array - 5, 0, 0, 0, 0, 0, 0, 0, - // Suffix array - 1, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 0, 0, 0, 0, - 5, 0, 0, 0, 0, 0, 0, 0 + 1, // Size of the suffix array + 5, 0, 0, 0, 0, 0, 0, 0, // Suffix array + 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, + 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, ]; let mut reader = buffer.as_slice(); diff --git a/sa-index/src/lib.rs b/sa-index/src/lib.rs index 6ffc0e9..9e2f769 100644 --- a/sa-index/src/lib.rs +++ b/sa-index/src/lib.rs @@ -15,9 +15,9 @@ pub enum SuffixArray { impl SuffixArray { /// Returns the length of the suffix array. - /// + /// /// # Returns - /// + /// /// The length of the suffix array. pub fn len(&self) -> usize { match self { @@ -27,13 +27,13 @@ impl SuffixArray { } /// Returns the suffix array at the given index. - /// + /// /// # Arguments - /// + /// /// * `index` - The index of the suffix array. - /// + /// /// # Returns - /// + /// /// The suffix array at the given index. pub fn get(&self, index: usize) -> i64 { match self { @@ -43,9 +43,9 @@ impl SuffixArray { } /// Returns whether the suffix array is empty. - /// + /// /// # Returns - /// + /// /// True if the suffix array is empty, false otherwise. pub fn is_empty(&self) -> bool { self.len() == 0 @@ -57,9 +57,9 @@ pub trait Nullable { const NULL: T; /// Returns whether the value is NULL. - /// + /// /// # Returns - /// + /// /// True if the value is NULL, false otherwise. fn is_null(&self) -> bool; } diff --git a/sa-index/src/sa_searcher.rs b/sa-index/src/sa_searcher.rs index b4c00a5..5bf924b 100644 --- a/sa-index/src/sa_searcher.rs +++ b/sa-index/src/sa_searcher.rs @@ -19,7 +19,8 @@ use crate::{ Minimum }, suffix_to_protein_index::SuffixToProteinIndex, - Nullable, SuffixArray + Nullable, + SuffixArray }; /// Enum indicating if we are searching for the minimum, or maximum bound in the suffix array @@ -240,7 +241,8 @@ impl Searcher { while right - left > 1 { let center = (left + right) / 2; let skip = min(lcp_left, lcp_right); - let (retval, lcp_center) = self.compare(search_string, self.sa.get(center), skip, bound); + let (retval, lcp_center) = + self.compare(search_string, self.sa.get(center), skip, bound); found |= lcp_center == search_string.len(); diff --git a/sa-server/src/main.rs b/sa-server/src/main.rs index eacd212..7fb3322 100644 --- a/sa-server/src/main.rs +++ b/sa-server/src/main.rs @@ -1,5 +1,11 @@ use std::{ - error::Error, fs::File, io::{BufReader, Read}, sync::Arc + error::Error, + fs::File, + io::{ + BufReader, + Read + }, + sync::Arc }; use axum::{ @@ -221,7 +227,9 @@ fn load_suffix_array_file(file: &str) -> Result<(u8, SuffixArray), Box