Lolly 1.4.27
Loading...
Searching...
No Matches
Classes | Functions
fast_search.hpp File Reference
#include "array.hpp"
#include "hashmap.hpp"
#include "string.hpp"
Include dependency graph for fast_search.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  string_searcher_rep
 
class  string_searcher
 

Functions

 CONCRETE_CODE (string_searcher)
 
void get_longest_common (string s1, string s2, int &b1, int &e1, int &b2, int &e2)
 

Function Documentation

◆ CONCRETE_CODE()

CONCRETE_CODE ( string_searcher )

◆ get_longest_common()

void get_longest_common ( string s1,
string s2,
int & b1,
int & e1,
int & b2,
int & e2 )

Definition at line 31 of file fast_search.cpp.

125 {
126 // NOTE: There are better algorithms based on generalized suffix trees.
127 b1= e1= b2= e2 = 0;
128 int bestl= 0;
131 for (int i= min (N (ss1->a), N (ss2->a)) - 1; i >= 0; i--) {
135 while (it->busy ()) {
136 int h = it->next ();
137 array<int> ps1= a1[h];
138 array<int> ps2= a2[h];
139 if (N (ps1) == 0 || N (ps2) == 0) continue;
140 for (int j1= 0; j1 < N (ps1); j1++) {
141 int pos1= ps1[j1];
142 if (b1 <= pos1 && pos1 < e1) continue;
143 for (int j2= 0; j2 < N (ps2); j2++) {
144 int pos2= ps2[j2];
145 int bb1= pos1, ee1= pos1, bb2= pos2, ee2= pos2;
146 while (bb1 > 0 && bb2 > 0 && s1[bb1 - 1] == s2[bb2 - 1]) {
147 bb1--;
148 bb2--;
149 }
150 while (ee1 < N (s1) && ee2 < N (s2) && s1[ee1] == s2[ee2]) {
151 ee1++;
152 ee2++;
153 }
154 if (ee1 - bb1 > bestl ||
155 (ee1 - bb1 == bestl && (bb1 < b1 || (bb1 == b1 && bb2 < b2)))) {
156 b1 = bb1;
157 e1 = ee1;
158 b2 = bb2;
159 e2 = ee2;
160 bestl= e1 - b1;
161 }
162 }
163 }
164 }
165 }
166}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
blackbox b1
blackbox b2
The list class represents a linked list.
Definition list.hpp:48
iterator< T > iterate(hashmap< T, U > h)
Generates an iterator for a container of type hashmap<T, U>.
Definition iterator.ipp:166
SI min(SI i, SI j)
Returns the minimum of two signed integers.
Definition minmax.hpp:27