fn backward_search<'b, P: Iterator<Item = &'b u8> + DoubleEndedIterator>(
        &self,
        pattern: P,
    ) -> BackwardSearchResult {
        let (mut l, mut r) = (0, self.bwt().len() - 1);
        // to keep track of the last "valid" search interval if
        // there is any valid suffix match.
        let (mut pl, mut pr) = (l, r);

        // the length of the suffix we have been able to match
        // successfully
        let mut matched_len = 0;
        // track if we exit early or not due to an empty
        // search interval.
        let mut complete_match = true;

        for &a in pattern.rev() {
            let less = self.less(a);
            pl = l;
            pr = r;
            l = less + if l > 0 { self.occ(l - 1, a) } else { 0 };
            r = less + self.occ(r, a) - 1;

            // The symbol was not found if we end up with an empty interval.
            // Terminate the LF-mapping process. In this case, also mark that
            // we do not have a complete match.
            if l > r {
                complete_match = false;
                break;
            }
            matched_len += 1;
        }

        // if we matched at least 1 character
        if matched_len > 0 {
            // if we matched the full pattern length we
            // have a complete match
            if complete_match {
                return BackwardSearchResult::Complete(Interval {
                    lower: l,
                    upper: r + 1,
                });
            } else {
                // if we matched less than the full pattern length, we have
                // a partial suffix match
                return BackwardSearchResult::Partial(
                    Interval {
                        lower: pl,
                        upper: pr + 1,
                    },
                    matched_len,
                );
            }
        } else {
            // if we matched nothing we have an absent result
            return BackwardSearchResult::Absent;
        }
    }
/// Perform backward search, yielding `BackwardSearchResult` enum that
/// contains the suffix array interval denoting exact occurrences of the given pattern
/// of length m in the text if it exists, or the suffix array interval denoting the
/// exact occurrences of a maximal matching suffix of the given pattern if it does
/// not exist.  If none of the pattern can be matched, the `BackwardSearchResult` is
/// `Absent`.
/// Complexity: O(m).
///
/// # Arguments
///
/// * `pattern` - the pattern to search
///
/// # Example
///
/// ```
/// use bio::alphabets::dna;
/// use bio::data_structures::bwt::{bwt, less, Occ};
/// use bio::data_structures::fmindex::{BackwardSearchResult, FMIndex, FMIndexable};
/// use bio::data_structures::suffix_array::suffix_array;
///
/// let text = b"GCCTTAACATTATTACGCCTA$";
/// let alphabet = dna::n_alphabet();
/// let sa = suffix_array(text);
/// let bwt = bwt(text, &sa);
/// let less = less(&bwt, &alphabet);
/// let occ = Occ::new(&bwt, 3, &alphabet);
/// let fm = FMIndex::new(&bwt, &less, &occ);
///
/// let pattern = b"TTA";
/// let bsr = fm.backward_search(pattern.iter());
///
/// let positions = match bsr {
///     BackwardSearchResult::Complete(sai) => sai.occ(&sa),
///     BackwardSearchResult::Partial(sai, _l) => sai.occ(&sa),
///     BackwardSearchResult::Absent => Vec::<usize>::new()
/// };
///
/// assert_eq!(positions, [3, 12, 9]);
/// ```
Perform backward search, yielding `BackwardSearchResult` enum that
contains the suffix array interval denoting exact occurrences of the given pattern
of length m in the text if it exists, or the suffix array interval denoting the
exact occurrences of a maximal matching suffix of the given pattern if it does
not exist.  If none of the pattern can be matched, the `BackwardSearchResult` is
`Absent`.
Perform backward search yielding ` BackwardSearchResult ` enum that contains the suffix array interval denoting exact occurrences of the given pattern of length m in the text if it exists or the suffix array interval denoting the exact occurrences of a maximal matching suffix of the given pattern if it does not exist . If none of the pattern can be matched the ` BackwardSearchResult ` is ` Absent ` .
fn backward_search<'b, P: Iterator<Item = &'b u8> + DoubleEndedIterator>(
        &self,
        pattern: P,
    ) -> BackwardSearchResult {
        let (mut l, mut r) = (0, self.bwt().len() - 1);
        // to keep track of the last "valid" search interval if
        // there is any valid suffix match.
        let (mut pl, mut pr) = (l, r);
        // the length of the suffix we have been able to match
        // successfully
        let mut matched_len = 0;
        // track if we exit early or not due to an empty
        // search interval.
        let mut complete_match = true;
        for &a in pattern.rev() {
            let less = self.less(a);
            pl = l;
            pr = r;
            l = less + if l > 0 { self.occ(l - 1, a) } else { 0 };
            r = less + self.occ(r, a) - 1;
            // The symbol was not found if we end up with an empty interval.
            // Terminate the LF-mapping process. In this case, also mark that
            // we do not have a complete match.
            if l > r {
                complete_match = false;
                break;
            }
            matched_len += 1;
        }
        // if we matched at least 1 character
        if matched_len > 0 {
            // if we matched the full pattern length we
            // have a complete match
            if complete_match {
                return BackwardSearchResult::Complete(Interval {
                    lower: l,
                    upper: r + 1,
                });
            } else {
                // if we matched less than the full pattern length, we have
                // a partial suffix match
                return BackwardSearchResult::Partial(
                    Interval {
                        lower: pl,
                        upper: pr + 1,
                    },
                    matched_len,
                );
            }
        } else {
            // if we matched nothing we have an absent result
            return BackwardSearchResult::Absent;
        }
    }
fn backward_search < ' b , P : Iterator < Item = & ' b u8 > + DoubleEndedIterator > ( & self , pattern : P , ) -> BackwardSearchResult { let ( mut l , mut r ) = ( 0 , self . bwt ( ) . len ( ) - 1 ) ; // to keep track of the last "valid" search interval if // there is any valid suffix match. let ( mut pl , mut pr ) = ( l , r ) ; // the length of the suffix we have been able to match // successfully let mut matched_len = 0 ; // track if we exit early or not due to an empty // search interval. let mut complete_match = true ; for & a in pattern . rev ( ) { let less = self . less ( a ) ; pl = l ; pr = r ; l = less + if l > 0 { self . occ ( l - 1 , a ) } else { 0 } ; r = less + self . occ ( r , a ) - 1 ; // The symbol was not found if we end up with an empty interval. // Terminate the LF-mapping process. In this case, also mark that // we do not have a complete match. if l > r { complete_match = false ; break ; } matched_len += 1 ; } // if we matched at least 1 character if matched_len > 0 { // if we matched the full pattern length we // have a complete match if complete_match { return BackwardSearchResult :: Complete ( Interval { lower : l , upper : r + 1 , } ) ; } else { // if we matched less than the full pattern length, we have // a partial suffix match return BackwardSearchResult :: Partial ( Interval { lower : pl , upper : pr + 1 , } , matched_len , ) ; } } else { // if we matched nothing we have an absent result return BackwardSearchResult :: Absent ; } }
Perform backward search, yielding `BackwardSearchResult` enum that
contains the suffix array interval denoting exact occurrences of the given pattern
of length m in the text if it exists, or the suffix array interval denoting the
exact occurrences of a maximal matching suffix of the given pattern if it does
not exist.
Perform backward search yielding ` BackwardSearchResult ` enum that contains the suffix array interval denoting exact occurrences of the given pattern of length m in the text if it exists or the suffix array interval denoting the exact occurrences of a maximal matching suffix of the given pattern if it does not exist .
&self
pattern
P
&self
pattern
P
example
```
use bio::alphabets::dna;
use bio::data_structures::bwt::{bwt, less, Occ};
use bio::data_structures::fmindex::{BackwardSearchResult, FMIndex, FMIndexable};
use bio::data_structures::suffix_array::suffix_array.

let text = b"GCCTTAACATTATTACGCCTA$";
let alphabet = dna::n_alphabet();
let sa = suffix_array(text);
let bwt = bwt(text, &sa);
let less = less(&bwt, &alphabet);
let occ = Occ::new(&bwt, 3, &alphabet);
let fm = FMIndex::new(&bwt, &less, &occ).

let pattern = b"TTA";
let bsr = fm.backward_search(pattern.iter()).

let positions = match bsr {
BackwardSearchResult::Complete(sai) => sai.occ(&sa),
BackwardSearchResult::Partial(sai, _l) => sai.occ(&sa),
BackwardSearchResult::Absent => Vec::::new()
}.


` ` ` use bio :: alphabets :: dna ; use bio :: data_structures :: bwt :: { bwt less Occ } ; use bio :: data_structures :: fmindex :: { BackwardSearchResult FMIndex FMIndexable } ; use bio :: data_structures :: suffix_array :: suffix_array . let text = b " GCCTTAACATTATTACGCCTA$ " ; let alphabet = dna :: n_alphabet () ; let sa = suffix_array ( text ) ; let bwt = bwt ( text &sa ) ; let less = less ( &bwt &alphabet ) ; let occ = Occ :: new ( &bwt 3 &alphabet ) ; let fm = FMIndex :: new ( &bwt &less &occ ) . let pattern = b " TTA " ; let bsr = fm . backward_search ( pattern . iter () ) . let positions = match bsr { BackwardSearchResult :: Complete ( sai ) = > sai . occ ( &sa ) BackwardSearchResult :: Partial ( sai _l ) = > sai . occ ( &sa ) BackwardSearchResult :: Absent = > Vec :::: new () } .