00001 #define TRACE_NAME "QueryablePool"
00002 #include "QueryablePool.h"
00003
00004 #include "InMemoryPool.h"
00005 #include "Query.h"
00006
00008
00009
00010
00012
00013 QueryablePool::QueryablePool()
00014 {
00015
00016 }
00017
00018 #if 0
00019
00020 QueryablePool::QueryablePool(const QueryablePool& other)
00021 {
00022 NOT_IMPLEMENTED
00023 }
00024
00025 const QueryablePool& QueryablePool::operator=(const QueryablePool& other)
00026 {
00027 NOT_IMPLEMENTED
00028 }
00029
00030 bool QueryablePool::operator==(const QueryablePool& other) const
00031 {
00032 NOT_IMPLEMENTED
00033 }
00034
00035 bool QueryablePool::operator<(const QueryablePool& other) const
00036 {
00037 NOT_IMPLEMENTED
00038 }
00039
00040 size_t QueryablePool::hash() const
00041 {
00042 NOT_IMPLEMENTED
00043 }
00044
00045 std::ostream& QueryablePool::print_to(std::ostream& stream) const
00046 {
00047 NOT_IMPLEMENTED
00048 }
00049
00050 #endif
00051
00052 QueryablePool::~QueryablePool()
00053 {
00054
00055 }
00056
00058
00059
00060
00062
00063
00064
00065 TripleSource* QueryablePool::unionWith(const TripleSource& other)
00066 {
00067
00068 NOT_IMPLEMENTED;
00069 }
00070
00071
00072
00073 TripleSource* QueryablePool::intersect(const TripleSource& other, int max)
00074 {
00075
00076
00077
00078 InMemoryPool* newPat = new InMemoryPool(other);
00079 TRACE "Intersect Me " << *this << endl;
00080 TRACE "and newPat" << *newPat << endl;
00081
00082 while (true) {
00083
00084 if (newPat->size() == 0) return newPat;
00085
00086 Query* m = query(*newPat);
00087 if (m->fetch()) {
00088
00089 delete m;
00090 TRACE "returning newpat = " << newPat << endl;
00091 return newPat;
00092 }
00093
00094 Triple t = m->getFailurePoint();
00095 delete m;
00096 newPat->remove(t);
00097 TRACE "newPat losing triple: " << t << endl;
00098 }
00099 }
00100
00101 TripleSource* QueryablePool::diff(const TripleSource& other, int max)
00102 {
00103
00104
00105 InMemoryPool newPat(other.getScope());
00106
00107 newPat.mUnion(other);
00108 InMemoryPool* diff = new InMemoryPool(other.getScope());
00109 int diffsFound = 0;
00110
00111 while (diffsFound <= max) {
00112
00113 if (newPat.size() == 0) return diff;
00114
00115 Query* m = this->query(newPat);
00116 if (m->fetch()) {
00117
00118
00119 delete m;
00120 return diff;
00121 }
00122
00123 Triple t = m->getFailurePoint();
00124 delete m;
00125
00126 diff->add(t);
00127 newPat.remove(t);
00128 ++diffsFound;
00129 }
00130 return diff;
00131
00132 }
00133
00134
00136
00137
00138
00140
00141 #undef TRACE_NAME