#![feature(test)]

extern crate test;
extern crate bio;

use bio::alphabets;
use bio::data_structures::bwt::{bwt, less, Occ};
use bio::data_structures::fmindex::{FMIndex, FMIndexable};
use bio::data_structures::suffix_array::{suffix_array, SuffixArray};
use test::{Bencher, black_box};

#[bench]
fn search_index_seeds(b: &mut Bencher) {
    let alphabet = alphabets::dna::iupac_alphabet();
    let sa = suffix_array(STR_1);
    let bwt = bwt(STR_1, &sa);
    let less = less(&bwt, &alphabet);
    let occ = Occ::new(&bwt, 3, &alphabet);
    let fmindex = FMIndex::new(&bwt, &less, &occ);

    b.iter(|| {
        let sequence = b"TCCAAAACAATAACGGAGGTGTCCAAAGGTCAGCTCAGCGTGTGGTTTCT";
        let seed_length = 20;

        let seeds = (0..(sequence.len() + 1 - seed_length))
            .map(|i| (i, &sequence[i..i + seed_length]));

        let mut locations = black_box(Vec::new());

        let mut loc_temp = Vec::new();
        for (offset, seed) in seeds {
            let interval = fmindex.backward_search(seed.iter());

            loc_temp.extend((interval.lower..interval.upper)
                .map(|i| (sa[i], offset)));
        }

        locations = loc_temp;
    });
}

static STR_1: &'static [u8] = b"[encoded data, 45000 characters]";
