Debug swcsa
[SXSI/TextCollection.git] / Query.h
1 /**
2  * Interface for alignment queries
3  */
4
5 #ifndef _Query_H_
6 #define _Query_H_
7
8 #include "TextCollection.h"
9
10 #include <stack>
11 #include <vector>
12 #include <set>
13
14 namespace SXSI
15 {
16
17 /**
18  * Base class for queries
19  */
20 class Query
21 {
22 public:
23     TextCollection::document_result align(uchar const *p, unsigned k);
24
25     void setDebug(bool b)
26     { this->debug = b; }
27
28     virtual ~Query() 
29     {  }
30
31 protected:
32     virtual void firstStep() = 0;
33
34     inline bool pushChar(char c) {
35         ulong nmin = tc->LF(c, smin.top()-1);
36         ulong nmax = tc->LF(c, smax.top())-1;
37         if (nmin > nmax) return false;
38         smin.push(nmin);
39         smax.push(nmax);
40         match.push_back(c);
41         return true;
42     }
43
44     inline void popChar() {
45         smin.pop();
46         smax.pop();
47         match.pop_back();
48     }
49
50     inline int min(int a, int b) {
51         if (a < b) return a; else return b;
52     }
53
54     inline int min(int a, int b, int c) {
55         if (a < b) if (a < c) return a; else return c;
56         else if (b < c) return b; else return c;
57     }
58
59     Query(TextCollection const *tc_);
60
61     uchar const *pat;
62     unsigned patlen;
63     TextCollection const *tc;
64     bool debug;
65     unsigned klimit;
66     ulong textlen;
67     
68     const char *ALPHABET;
69     static const unsigned ALPHABET_SIZE = 5;
70     static const char ALPHABET_DNA[];
71
72     std::stack<ulong> smin;
73     std::stack<ulong> smax;
74     std::vector<uchar> match;
75     std::set<TextCollection::DocId> result;
76  
77 private:
78     Query();
79     // No copy constructor or assignment
80     Query(Query const&);
81     Query& operator = (Query const&);
82 };
83
84 } // Namespace
85
86 #endif // _Query_H_