00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef PQS_DEFS_included
00042 #define PQS_DEFS_included
00043
00044 #include <stdio.h>
00045 #include <vector>
00046 #include <set>
00047 #include <algorithm>
00048 #include <memory>
00049
00050
00051 class PQS_MANAGER;
00052 struct op;
00053 struct tn;
00054 typedef struct tn TN;
00055 typedef struct op OP;
00056
00057
00058 typedef OP * PQS_OP;
00059 typedef TN * PQS_TN;
00060
00061
00062
00063 enum PQS_ITYPE {
00064 PQS_ITYPE_INVALID,
00065 PQS_ITYPE_NOPREDICATES,
00066 PQS_ITYPE_NORM,
00067 PQS_ITYPE_UNC,
00068 PQS_ITYPE_OR,
00069 PQS_ITYPE_AND,
00070 PQS_ITYPE_ORANDCM,
00071 PQS_ITYPE_ORCM,
00072 PQS_ITYPE_ANDCM,
00073 PQS_ITYPE_ANDORCM,
00074 PQS_ITYPE_DIVSQRT,
00075 PQS_ITYPE_LAST
00076 };
00077
00078
00079
00080 enum PQS_RELOPTYPE {
00081 PQS_RELOPTYPE_OTHER,
00082 PQS_RELOPTYPE_EQ,
00083 PQS_RELOPTYPE_NE
00084 };
00085
00086
00087 typedef INT32 PQS_NODE_FLAGS;
00088
00089 #define PQS_FLAG_CONDITION_TRUE 1 // The compare condition is always TRUE
00090 #define PQS_FLAG_CONDITION_FALSE 2 // The compare condition is always FALSE
00091
00092
00093 typedef INT32 PQS_MARKER_TYPE;
00094
00095
00096 typedef INT32 PQS_NODE_IDX;
00097
00098 #define PQS_IDX_NONE 0
00099 #define PQS_IDX_TRUE -1
00100 #define PQS_IDX_FALSE -2
00101 #define PQS_IDX_INVALID -3
00102 #define PQS_Is_Real_Idx(x) ((x)>0)
00103
00104
00105 enum PQS_TRUTH {
00106 PQS_TRUTH_NEVER,
00107 PQS_TRUTH_ALWAYS,
00108 PQS_TRUTH_POSSIBLE,
00109 PQS_TRUTH_UNKNOWN
00110 };
00111
00112
00113
00114
00115 struct PQS_TN_MAP_TYPE {
00116 PQS_TN tn_to_use;
00117
00118 PQS_NODE_IDX last_def;
00119 BOOL used_as_qual_pred;
00120 BOOL no_query;
00121
00122 inline PQS_TN_MAP_TYPE() {
00123 last_def = PQS_IDX_INVALID;
00124 used_as_qual_pred = FALSE;
00125 no_query = FALSE;
00126 tn_to_use = NULL;
00127 }
00128 };
00129
00130
00131
00132
00133
00134 template <class T, class C = std::less<T> >
00135 class PQS_SET {
00136 public:
00137 #ifdef PQS_USE_MEMPOOLS
00138 typedef mempool_allocator<T> set_allocator_type;
00139 #else
00140 typedef std::allocator<T> set_allocator_type;
00141 #endif
00142 typedef std::set<T,C,set_allocator_type> set_type;
00143 typedef typename set_type::iterator set_iterator_type;
00144 set_type _set;
00145
00146 PQS_SET<T,C>()
00147 #ifdef PQS_USE_MEMPOOLS
00148 : _set(set_type::key_compare(),set_allocator_type(PQS_mem_pool))
00149 #endif
00150 {}
00151
00152 inline static PQS_SET<T,C> Intersection(PQS_SET<T,C> &A,PQS_SET<T,C> &B)
00153 {
00154 PQS_SET<T,C> result;
00155 set_intersection(A._set.begin(),A._set.end(),B._set.begin(),B._set.end(),
00156 inserter(result._set,result._set.begin()));
00157 return result;
00158 }
00159
00160 inline static PQS_SET<T,C> Union(PQS_SET<T,C> &A,PQS_SET<T,C> &B)
00161 {
00162 PQS_SET<T,C> result;
00163 set_union(A._set.begin(),A._set.end(),B._set.begin(),B._set.end(),
00164 inserter(result._set,result._set.begin()));
00165 return result;
00166 }
00167
00168 inline static PQS_SET<T,C> Diff(PQS_SET<T,C> &A,PQS_SET<T,C> &B)
00169 {
00170 PQS_SET<T,C> result;
00171 set_difference(A._set.begin(),A._set.end(),B._set.begin(),B._set.end(),
00172 inserter(result._set,result._set.begin()));
00173 return result;
00174 }
00175
00176 inline static BOOL Is_Empty(PQS_SET<T,C> &A) {
00177 return (A._set.empty());
00178 }
00179
00180 inline BOOL Is_Subset(PQS_SET<T,C> &B) {
00181 return includes(_set.begin(),_set.end(),B._set.begin(),B._set.end());
00182 }
00183
00184 inline BOOL Is_Subset(const T &B) {
00185 return (_set.count(B) != 0);
00186 }
00187
00188 inline void Insert(const T &tn) {
00189 _set.insert(tn);
00190 }
00191
00192 inline void Clear() {
00193 _set.erase(_set.begin(),_set.end());
00194 }
00195
00196 inline void Clear(const T &tn) {
00197 _set.erase(tn);
00198 }
00199
00200 inline INT32 Size(void) const {
00201 return _set.size();
00202 }
00203
00204 inline set_iterator_type begin() const {return _set.begin();}
00205 inline set_iterator_type end() const {return _set.end();}
00206
00207 void Print(FILE *f=stdout,BOOL newline=TRUE);
00208 };
00209
00210
00211 #endif
00212