uint64_t patternId(const t_idx& idx, const t_pattern& word_vec) { uint64_t lb = 0, rb = idx.cst.size() - 1; backward_search(idx.cst.csa, lb, rb, word_vec.begin(), word_vec.end(), lb, rb); auto node = idx.cst.node(lb, rb); return idx.cst.id(node); }
size_type search(t_pat_iter begin, t_pat_iter end, result& res, size_t k) const { size_type sp=1, ep=0; if (0 == backward_search(m_csa_full, 0, m_csa_full.size()-1, begin, end, sp, ep)) { res = result(); return 0; } else { auto tmp_res = topk_greedy(sp, ep, k); res = result(sp, ep, std::move(tmp_res)); return ep-sp+1; } }
static typename t_csa::size_type count( const t_csa& csa, t_pat_iter begin, t_pat_iter end, csa_tag ) { if (end - begin > (typename std::iterator_traits<t_pat_iter>::difference_type)csa.size()) return 0; typename t_csa::size_type t=0; // dummy variable for the backward_search call return backward_search(csa, 0, csa.size()-1, begin, end, t, t); }
typename t_csa::size_type locate( const t_csa& csa, t_pat_iter begin, t_pat_iter end, t_rac& occ, SDSL_UNUSED typename enable_if<is_same<csa_tag, typename t_csa::index_category>::value, csa_tag>::type x = csa_tag() ) { typename t_csa::size_type occ_begin, occ_end, occs; occs = backward_search(csa, 0, csa.size()-1, begin, end, occ_begin, occ_end); occ.resize(occs); for (typename t_csa::size_type i=0; i < occs; ++i) { occ[i] = csa[occ_begin+i]; } return occs; }
typename t_csa::size_type backward_search( const t_csa& csa, typename t_csa::size_type l, typename t_csa::size_type r, t_pat_iter begin, t_pat_iter end, typename t_csa::size_type& l_res, typename t_csa::size_type& r_res, SDSL_UNUSED typename enable_if<is_same<csa_tag, typename t_csa::index_category>::value, csa_tag>::type x = csa_tag() ) { t_pat_iter it = end; while (begin < it and r+1-l > 0) { --it; typename t_csa::size_type size = backward_search(csa, l, r, (typename t_csa::char_type)*it, l, r); } l_res = l; r_res = r; return r+1-l; }
void timeCount(ParamProgram *par, uint m){ double t, avgTime; uchar* pat; uint k; string query; uint64_t lb, rb, l, r; avgTime = 0.0; for (k=0; k<REPET; k++){ pat = par->seq+par->patterns[k]; query = string((char *)pat); l=lb=0; r=rb=par->index->fmi.size()-1; t = getTime_ms(); backward_search(par->index->fmi, lb, rb, query.begin(), query.begin()+m, l, r); t = getTime_ms() - t; avgTime += t/(double)REPET; } cout << "____________________________________________________" << endl; cout << "Time for count..." << endl; cout << "Average CPU time for count m=" << m << " = " << avgTime*1000.0 << " Microseconds" << endl; cout << "____________________________________________________" << endl; }