Skip to content

Commit

Permalink
run clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonVandeVyver committed Oct 24, 2024
1 parent 944adc2 commit 6dccb19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
33 changes: 15 additions & 18 deletions libsais64-rs/src/bitpacking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>, sparseness_factor: usize) -> Vec<u8> {
pub fn bitpack_text_8(text: &[u8], sparseness_factor: usize) -> Vec<u8> {
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
Expand All @@ -47,24 +46,23 @@ pub fn bitpack_text_8(text: &Vec<u8>, sparseness_factor: usize) -> Vec<u8> {
}

// Bitpack text in a vector of u16 elements. BITS_PER_CHAR * sparseness_factor <= 16.
pub fn bitpack_text_16(text: &Vec<u8>, sparseness_factor: usize) -> Vec<u16> {
pub fn bitpack_text_16(text: &[u8], sparseness_factor: usize) -> Vec<u16> {
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
Expand All @@ -81,24 +79,23 @@ pub fn bitpack_text_16(text: &Vec<u8>, sparseness_factor: usize) -> Vec<u16> {
}

// Bitpack text in a vector of u32 elements. BITS_PER_CHAR * sparseness_factor <= 32.
pub fn bitpack_text_32(text: &Vec<u8>, sparseness_factor: usize) -> Vec<u32> {
pub fn bitpack_text_32(text: &[u8], sparseness_factor: usize) -> Vec<u32> {
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
Expand Down
4 changes: 2 additions & 2 deletions sa-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?
};

Expand Down Expand Up @@ -82,7 +82,7 @@ fn libsais64(text: &Vec<u8>, sparseness_factor: u8) -> Result<Vec<i64>, &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);
Expand Down

0 comments on commit 6dccb19

Please sign in to comment.