/// Calculate occ array with sampling from BWT of length n.
/// Time complexity: O(n).
/// Space complexity: O(n / k * A) with A being the alphabet size.
/// The specified alphabet must match the alphabet of the text and its BWT.
/// For large texts, it is advisable to transform
/// the text before calculating the BWT (see alphabets::rank_transform).
///
/// # Arguments
///
/// * `bwt` - the BWT
/// * `k` - the sampling rate: every k-th entry will be stored
Calculate occ array with sampling from BWT of length n.
Calculate occ array with sampling from BWT of length n .
pub fn new(bwt: &BWTSlice, k: u32, alphabet: &Alphabet) -> Self {
        let n = bwt.len();
        let m = alphabet
            .max_symbol()
            .expect("Expecting non-empty alphabet.") as usize
            + 1;
        let mut alpha = alphabet.symbols.iter().collect::<Vec<usize>>();
        // include sentinel '$'
        if (b'$' as usize) < m && !alphabet.is_word(b"$") {
            alpha.push(b'$' as usize);
        }
        let mut occ: Vec<Vec<usize>> = vec![Vec::new(); m];
        let mut curr_occ = vec![0usize; m];
        // characters not in the alphabet won't take up much space
        for &a in &alpha {
            occ[a].reserve(n / k as usize);
        }
        for (i, &c) in bwt.iter().enumerate() {
            curr_occ[c as usize] += 1;
            if i % k as usize == 0 {
                // only visit characters in the alphabet
                for &a in &alpha {
                    occ[a].push(curr_occ[a]);
                }
            }
        }
        Occ { occ, k }
    }
pub fn new ( bwt : & BWTSlice , k : u32 , alphabet : & Alphabet ) -> Self { let n = bwt . len ( ) ; let m = alphabet . max_symbol ( ) . expect ( " " ) as usize + 1 ; let mut alpha = alphabet . symbols . iter ( ) . collect :: < Vec < usize > > ( ) ; // include sentinel '$' if ( b'$' as usize ) < m && ! alphabet . is_word ( b" " ) { alpha . push ( b'$' as usize ) ; } let mut occ : Vec < Vec < usize > > = vec ! [ Vec new ( ) m ] ; let mut curr_occ = vec ! [ 0usize m ] ; // characters not in the alphabet won't take up much space for & a in & alpha { occ [ a ] . reserve ( n / k as usize ) ; } for ( i , & c ) in bwt . iter ( ) . enumerate ( ) { curr_occ [ c as usize ] += 1 ; if i % k as usize == 0 { // only visit characters in the alphabet for & a in & alpha { occ [ a ] . push ( curr_occ [ a ] ) ; } } } Occ { occ , k } }
Calculate occ array with sampling from BWT of length n.
Time complexity: O(n).
Calculate occ array with sampling from BWT of length n . Time complexity : O ( n ) .
bwt
&BWTSlice
k
u32
alphabet
&Alphabet