diff --git a/libsais64-rs/src/bitpacking.rs b/libsais64-rs/src/bitpacking.rs index ea6578e..d3fb910 100644 --- a/libsais64-rs/src/bitpacking.rs +++ b/libsais64-rs/src/bitpacking.rs @@ -13,24 +13,23 @@ fn get_rank(c: u8) -> u8 { pub const BITS_PER_CHAR: usize = 5; // Bitpack text in a vector of u8 elements. BITS_PER_CHAR * sparseness_factor <= 8. -pub fn bitpack_text_8(text: &Vec, sparseness_factor: usize) -> Vec { +pub fn bitpack_text_8(text: &[u8], sparseness_factor: usize) -> Vec { assert!(BITS_PER_CHAR * sparseness_factor <= 8); let num_ints = (text.len() + (sparseness_factor-1)) / sparseness_factor; let mut text_packed = vec![0; num_ints]; - if text.len() == 0 { + if text.is_empty() { return text_packed; } - for i in 0..(num_ints-1) { + for (i, element) in text_packed.iter_mut().enumerate().take(num_ints-1) { let ti = i * sparseness_factor; - let mut element = 0u8; + *element = 0u8; for j in 0..sparseness_factor { let rank_c = get_rank(text[ti + j]); - element |= rank_c << (BITS_PER_CHAR * (sparseness_factor - 1 - j)); + *element |= rank_c << (BITS_PER_CHAR * (sparseness_factor - 1 - j)); } - text_packed[i] = element; } // Handle the last element @@ -47,24 +46,23 @@ pub fn bitpack_text_8(text: &Vec, sparseness_factor: usize) -> Vec { } // Bitpack text in a vector of u16 elements. BITS_PER_CHAR * sparseness_factor <= 16. -pub fn bitpack_text_16(text: &Vec, sparseness_factor: usize) -> Vec { +pub fn bitpack_text_16(text: &[u8], sparseness_factor: usize) -> Vec { assert!(BITS_PER_CHAR * sparseness_factor <= 16); let num_ints = (text.len() + (sparseness_factor-1)) / sparseness_factor; let mut text_packed = vec![0; num_ints]; - if text.len() == 0 { + if text.is_empty() { return text_packed; } - for i in 0..(num_ints-1) { + for (i, element) in text_packed.iter_mut().enumerate().take(num_ints-1) { let ti = i * sparseness_factor; - let mut element = 0u16; + *element = 0u16; for j in 0..sparseness_factor { let rank_c = get_rank(text[ti + j]) as u16; - element |= rank_c << (BITS_PER_CHAR * (sparseness_factor - 1 - j)); + *element |= rank_c << (BITS_PER_CHAR * (sparseness_factor - 1 - j)); } - text_packed[i] = element; } // Handle the last element @@ -81,24 +79,23 @@ pub fn bitpack_text_16(text: &Vec, sparseness_factor: usize) -> Vec { } // Bitpack text in a vector of u32 elements. BITS_PER_CHAR * sparseness_factor <= 32. -pub fn bitpack_text_32(text: &Vec, sparseness_factor: usize) -> Vec { +pub fn bitpack_text_32(text: &[u8], sparseness_factor: usize) -> Vec { assert!(BITS_PER_CHAR * sparseness_factor <= 32); let num_ints = (text.len() + (sparseness_factor-1)) / sparseness_factor; let mut text_packed = vec![0; num_ints]; - if text.len() == 0 { + if text.is_empty() { return text_packed; } - for i in 0..(num_ints-1) { + for (i, element) in text_packed.iter_mut().enumerate().take(num_ints-1) { let ti = i * sparseness_factor; - let mut element = 0u32; + *element = 0u32; for j in 0..sparseness_factor { let rank_c = get_rank(text[ti + j]) as u32; - element |= rank_c << (BITS_PER_CHAR * (sparseness_factor - 1 - j)); + *element |= rank_c << (BITS_PER_CHAR * (sparseness_factor - 1 - j)); } - text_packed[i] = element; } // Handle the last element diff --git a/sa-builder/src/lib.rs b/sa-builder/src/lib.rs index 424b306..1ee7199 100644 --- a/sa-builder/src/lib.rs +++ b/sa-builder/src/lib.rs @@ -54,7 +54,7 @@ pub fn build_ssa( // Build the suffix array using the selected algorithm let mut sa = match construction_algorithm { - SAConstructionAlgorithm::LibSais => libsais64(&text, sparseness_factor)?, + SAConstructionAlgorithm::LibSais => libsais64(text, sparseness_factor)?, SAConstructionAlgorithm::LibDivSufSort => libdivsufsort_rs::divsufsort64(text).ok_or("Building suffix array failed")? }; @@ -82,7 +82,7 @@ fn libsais64(text: &Vec, sparseness_factor: u8) -> Result, &str> { eprintln!("\tLibsais sparseness factor: {}", libsais_sparseness); eprintln!("\tSample rate: {}", sample_rate); - let mut sa = libsais64_rs::sais64(&text, libsais_sparseness)?; + let mut sa = libsais64_rs::sais64(text, libsais_sparseness)?; if sample_rate > 1 { sample_sa(&mut sa, sample_rate as u8);