Main Page | Class Hierarchy | Class List | File List | Class Members

queryProcessor.h

00001 /*********************************************************************
00002  *
00003  * Condor ClassAd library
00004  * Copyright (C) 1990-2003, Condor Team, Computer Sciences Department,
00005  * University of Wisconsin-Madison, WI and Rajesh Raman.
00006  *
00007  * This source code is covered by the Condor Public License, which can
00008  * be found in the accompanying LICENSE file, or online at
00009  * www.condorproject.org.
00010  *
00011  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00012  * AND THE UNIVERSITY OF WISCONSIN-MADISON "AS IS" AND ANY EXPRESS OR
00013  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00014  * WARRANTIES OF MERCHANTABILITY, OF SATISFACTORY QUALITY, AND FITNESS
00015  * FOR A PARTICULAR PURPOSE OR USE ARE DISCLAIMED. THE COPYRIGHT
00016  * HOLDERS AND CONTRIBUTORS AND THE UNIVERSITY OF WISCONSIN-MADISON
00017  * MAKE NO MAKE NO REPRESENTATION THAT THE SOFTWARE, MODIFICATIONS,
00018  * ENHANCEMENTS OR DERIVATIVE WORKS THEREOF, WILL NOT INFRINGE ANY
00019  * PATENT, COPYRIGHT, TRADEMARK, TRADE SECRET OR OTHER PROPRIETARY
00020  * RIGHT.
00021  *
00022  *********************************************************************/
00023 
00024 #if !defined(QP_H)
00025 #define QP_H
00026 
00027 #include "rectangle.h"
00028 #include <set>
00029 
00030 class ClassAdIndex;
00031 class IntervalTree;
00032 typedef std::map<std::string,ClassAdIndex*,CaseIgnLTStr> Indexes;
00033 typedef std::set<int> IndexEntries;
00034 typedef std::map<int, KeySet> QueryOutcome;
00035 
00036 class QueryProcessor {
00037 public:
00038         QueryProcessor( );
00039         ~QueryProcessor( );
00040         bool InitializeIndexes( Rectangles&, bool useSummaries=true );
00041         void ClearIndexes( );
00042         bool DoQuery( Rectangles&, KeySet& );
00043         void PurgeRectangle( int rId );
00044         bool MapRectangleID( int srId, int &rId, int &portNum, int &pId, int &cId );
00045         bool MapPortID( int pId, int &portNum, int &cId );
00046         bool UnMapClassAdID( int cId, int &brId, int &erId );
00047         void Display( FILE* );
00048 
00049         static int numQueries;
00050 //private:
00051         void DumpQState( QueryOutcome & );
00052         int                             numRectangles, numSummaries;
00053         Rectangles              *rectangles, summaries;
00054 
00055         Representatives reps;
00056         Constituents    consts;
00057         KeyMap                  constRepMap;
00058         bool                    summarize;
00059 
00060                 // only indexes here; deviant/absent info in rectangles/summaries
00061         Indexes                 imported, exported;
00062 };
00063 
00064 
00065 class Query {
00066 public:
00067         ~Query( );
00068         Query *MakeQuery( Rectangles* );
00069         Query *MakeConjunctQuery( Query*, Query* );
00070         Query *MakeDisjunctQuery( Query*, Query* );
00071         bool   RunQuery( QueryProcessor&, KeySet& );
00072 private:
00073         Query( );
00074         enum Op { IDENT, AND, OR };
00075         Op                      op;
00076         Query           *left, *right;
00077         Rectangles      *rectangles;
00078 };
00079 
00080 
00081         
00082 //----------------------------------------------------------------------------
00083 
00084 class ClassAdIndex {
00085 public:
00086         ClassAdIndex( );
00087         virtual ~ClassAdIndex( );
00088         virtual bool Delete( int, const Interval& )=0;
00089         virtual bool Filter( const Interval&, KeySet& )=0;
00090         virtual bool FilterAll( KeySet& )=0;
00091 };
00092 
00093 class ClassAdNumericIndex : public ClassAdIndex {
00094 public:
00095         virtual ~ClassAdNumericIndex( );
00096         static ClassAdNumericIndex *MakeNumericIndex( OneDimension& );
00097         virtual bool Delete( int, const Interval& );
00098         virtual bool Filter( const Interval&, KeySet& );
00099         virtual bool FilterAll( KeySet& );
00100 
00101 private:
00102         ClassAdNumericIndex( );
00103         IntervalTree    *intervalTree;
00104 };
00105 
00106 typedef std::map<std::string, IndexEntries, CaseIgnLTStr> StringIndex;
00107 class ClassAdStringIndex : public ClassAdIndex {
00108 public:
00109         virtual ~ClassAdStringIndex( );
00110         static ClassAdStringIndex *MakeStringIndex( OneDimension& );
00111         virtual bool Delete( int, const Interval& );
00112         virtual bool Filter( const Interval&, KeySet& );
00113         virtual bool FilterAll( KeySet& );
00114 private:
00115         ClassAdStringIndex( );
00116         StringIndex     stringIndex;
00117 };
00118 
00119 
00120 class ClassAdBooleanIndex : public ClassAdIndex {
00121 public:
00122         virtual ~ClassAdBooleanIndex( );
00123         static ClassAdBooleanIndex *MakeBooleanIndex( OneDimension& );
00124         virtual bool Delete( int, const Interval& );
00125         virtual bool Filter( const Interval&, KeySet& );
00126         virtual bool FilterAll( KeySet& );
00127 private:
00128         ClassAdBooleanIndex( );
00129         IndexEntries    yup, nope;
00130 };
00131 
00132 
00133 #endif