pub fn lcp<SA: Deref<Target = RawSuffixArray>>(text: &[u8], pos: SA) -> LCPArray {
    assert_eq!(text.len(), pos.len());
    let n = text.len();

    // provide the lexicographical rank for each suffix
    let mut rank: Vec<usize> = iter::repeat(0).take(n).collect();
    for (r, p) in pos.iter().enumerate() {
        rank[*p] = r;
    }

    let mut lcp = SmallInts::from_elem(-1, n + 1);
    let mut l = 0usize;
    for (p, &r) in rank.iter().enumerate().take(n - 1) {
        // since the sentinel has rank 0 and is excluded above,
        // we will never have a negative index below
        let pred = pos[r - 1];
        while pred + l < n && p + l < n && text[p + l] == text[pred + l] {
            l += 1;
        }
        lcp.set(r, l as isize);
        l = if l > 0 { l - 1 } else { 0 };
    }

    lcp
}
/// Construct lcp array for given text and suffix array of length n.
/// Complexity: O(n).
///
/// # Arguments
///
/// * `text` - the text ended by sentinel symbol (being lexicographically smallest)
/// * `pos` - the suffix array for the text
///
/// # Example
///
/// ```
/// use bio::data_structures::suffix_array::{lcp, suffix_array};
/// let text = b"GCCTTAACATTATTACGCCTA$";
/// let pos = suffix_array(text);
///
/// // obtain compressed LCP array
/// let lcp = lcp(text, &pos);
///
/// // get most values in O(1).
/// assert_eq!(lcp.get(6).unwrap(), 4);
///
/// // obtain uncompressed LCP array.
/// let uncompressed = lcp.decompress();
/// assert_eq!(
///     uncompressed,
///     [-1, 0, 1, 1, 2, 1, 4, 0, 1, 3, 1, 1, 2, 0, 4, 0, 2, 2, 2, 1, 3, 3, -1]
/// )
/// ```
Construct lcp array for given text and suffix array of length n.
Construct lcp array for given text and suffix array of length n .
pub fn lcp<SA: Deref<Target = RawSuffixArray>>(text: &[u8], pos: SA) -> LCPArray {
    assert_eq!(text.len(), pos.len());
    let n = text.len();
    // provide the lexicographical rank for each suffix
    let mut rank: Vec<usize> = iter::repeat(0).take(n).collect();
    for (r, p) in pos.iter().enumerate() {
        rank[*p] = r;
    }
    let mut lcp = SmallInts::from_elem(-1, n + 1);
    let mut l = 0usize;
    for (p, &r) in rank.iter().enumerate().take(n - 1) {
        // since the sentinel has rank 0 and is excluded above,
        // we will never have a negative index below
        let pred = pos[r - 1];
        while pred + l < n && p + l < n && text[p + l] == text[pred + l] {
            l += 1;
        }
        lcp.set(r, l as isize);
        l = if l > 0 { l - 1 } else { 0 };
    }
    lcp
}
pub fn lcp < SA : Deref < Target = RawSuffixArray > > ( text : & [ u8 ] , pos : SA ) -> LCPArray { assert_eq ! ( text len ( ) pos len ( ) ) ; let n = text . len ( ) ; // provide the lexicographical rank for each suffix let mut rank : Vec < usize > = iter :: repeat ( 0 ) . take ( n ) . collect ( ) ; for ( r , p ) in pos . iter ( ) . enumerate ( ) { rank [ * p ] = r ; } let mut lcp = SmallInts :: from_elem ( - 1 , n + 1 ) ; let mut l = 0usize ; for ( p , & r ) in rank . iter ( ) . enumerate ( ) . take ( n - 1 ) { // since the sentinel has rank 0 and is excluded above, // we will never have a negative index below let pred = pos [ r - 1 ] ; while pred + l < n && p + l < n && text [ p + l ] == text [ pred + l ] { l += 1 ; } lcp . set ( r , l as isize ) ; l = if l > 0 { l - 1 } else { 0 } ; } lcp }
Construct lcp array for given text and suffix array of length n.
Complexity: O(n).
Construct lcp array for given text and suffix array of length n . Complexity : O ( n ) .
text
&[u8]
pos
SA
text
&[u8]
pos
SA
example
```
use bio::data_structures::suffix_array::{lcp, suffix_array};
let text = b"GCCTTAACATTATTACGCCTA$";
let pos = suffix_array(text).

obtain compressed LCP array
let lcp = lcp(text, &pos).

get most values in O(1).

obtain uncompressed LCP array.
` ` ` use bio :: data_structures :: suffix_array :: { lcp suffix_array } ; let text = b " GCCTTAACATTATTACGCCTA$ " ; let pos = suffix_array ( text ) . obtain compressed LCP array let lcp = lcp ( text &pos ) . get most values in O ( 1 ) . obtain uncompressed LCP array .