Advertisement
Guest User

Untitled

a guest
Dec 10th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include "search.h"
  2. #include <iostream>
  3.  
  4. void searchIndex(const vector<string> &patterns, const string &txt,
  5. const vector<int> &sa, function<void(const string &)> reporter)
  6. {
  7. // auto lambda1 = [txt](const int &i, const string &pat)
  8. // {
  9. // cout << "1 " << i << endl;
  10. // return txt.compare(i, pat.size(), pat) < 0;
  11. // };
  12. // auto lambda2 = [txt](const string &pat, const int &i)
  13. // {
  14. // cout << "2 " << i << endl;
  15. // return txt.compare(i, pat.size(), pat) > 0;
  16. // };
  17. // set<int> occurrences;
  18. // for (const string &pattern : patterns)
  19. // {
  20. // auto lower = lower_bound(sa.begin(), sa.end(), pattern, lambda1);
  21. // auto upper = upper_bound(lower, sa.end(), pattern, lambda2);
  22.  
  23. // for (auto i = lower; i != upper; ++i)
  24. // occurrences.insert(*i);
  25. // }
  26.  
  27. set<int> occ;
  28.  
  29. for(int i = 0; i < patterns.size(); i++){
  30. for(int j = 0; j < sa.size(); j++){
  31. cout << "sa " << sa[j];
  32. cout << " slice ";
  33. for(int k=sa[j]; k<sa[j]+patterns[i].size();k++) cout << txt[k];
  34. cout << endl;
  35. if (txt.compare(sa[j], patterns[i].size(), patterns[i]) == 0){
  36. occ.insert(sa[j]);
  37. cout << "patS " << patterns[i].size() << endl;
  38. cout << "occ " << sa[j] << endl;
  39. }
  40. }
  41. }
  42.  
  43.  
  44. for(int i=0; i<patterns.size();i++) cout << endl << patterns[i] << endl << endl;
  45. const int size = txt.size();
  46. int previousLine = -1;
  47. for (const int &pos : occ)
  48. {
  49. int start, end;
  50. for (start = pos; start > 0 && txt[start - 1] != '\n'; --start)
  51. ;
  52.  
  53. if (start == previousLine)
  54. continue;
  55.  
  56. for (end = pos; end < size && txt[end] != '\n'; ++end)
  57. ;
  58.  
  59. reporter(txt.substr(start, end - start));
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement