Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

QueryablePool.cpp

00001 #define TRACE_NAME "QueryablePool"
00002 #include "QueryablePool.h"
00003 // $Id: QueryablePool_8cpp-source.html,v 1.2 2001/10/10 20:40:58 sandro Exp $
00004 #include "InMemoryPool.h"
00005 #include "Query.h"
00006 
00008 //
00009 //  Standard Member Functions
00010 //
00012 
00013 QueryablePool::QueryablePool()
00014 {
00015     // blank default    
00016 }
00017 
00018 #if 0  /* omit definitions until they are implemented */
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 /* omit definitions until they are implemented */
00051     
00052 QueryablePool::~QueryablePool()
00053 {
00054     // blank default    
00055 }
00056 
00058 //
00059 //  Additional Public Member Functions
00060 //
00062 
00063 
00064 
00065 TripleSource* QueryablePool::unionWith(const TripleSource& other) 
00066 {
00067     // really just a namespace thing...
00068     NOT_IMPLEMENTED;
00069 }
00070 
00071 /* this implementation is NOT XSB specific, just QueryablePool... */
00072 
00073 TripleSource* QueryablePool::intersect(const TripleSource& other, int max) 
00074 {
00075 
00076     // BUG   max isn't really implemented here, with this cheezy algorithm.
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             // in theory we have information here which could be useful,
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     // do we need Foreign  for this?   t comes from other
00104     // and gets added to diff....
00105     InMemoryPool newPat(other.getScope());
00106     //newPat.addAll(other);
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             // in theory we have information here which could be useful,
00118             // like for the other half of the match process.
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 //  Additional Private Member Functions
00138 //
00140 
00141 #undef TRACE_NAME

Home to blindfold. This page generated via doxygen 1.2.11.1 Wed Oct 10 16:40:33 2001.