/* //paragraph [1] Title: [{\Large \bf \begin{center}] [\end{center}}] //paragraph [10] Footnote: [{\footnote{] [}}] //[TOC] [\tableofcontents] [1] Header-File of SpatialJoin-Algebra December 2010, Jiamin Lu [TOC] 1 Overview This header file defines an auxiliary class SpatialJoinLocalInfo. 2 Defines and Includes */ #ifndef SPATIALJOIN_ALGEBRA_H__ #define SPATIALJOIN_ALGEBRA_H__ #include #include "Algebras/Spatial/SpatialAlgebra.h" #include "Algebras/Relation-C++/RelationAlgebra.h" #include "Algebra.h" #include "NestedList.h" #include "QueryProcessor.h" #include "Algebras/Rectangle/RectangleAlgebra.h" #include "StandardTypes.h" #include "ListUtils.h" #include "Progress.h" #include "RTuple.h" extern NestedList* nl; extern QueryProcessor* qp; namespace extrel2{ class TupleBuffer2; class TupleBuffer2Iterator; } typedef enum {leftStream, rightStream} streamType; template class SpatialJoin2LocalInfo: protected ProgressWrapper { private: Rectangle *joinBox; Supplier pf; //parameter function bool isSet; //ensure setting the function's parameters struct{ Word streamWord; extrel2::TupleBuffer2 *streamBuffer; extrel2::TupleBuffer2Iterator *tb2Iter; int card; Rectangle *MBR; double avgSize[dim]; }r[2]; void scanStream(int attrIndex, streamType loc, Supplier s); public: SpatialJoin2LocalInfo(Word leftStreamWord, Word leftAttrIndexWord, Word rightStreamWord, Word rightAttrIndexWord, Word funWord, Supplier s, ProgressLocalInfo* p); void openInputStream(streamType loc); Tuple* getNextInputTuple(streamType loc); void closeInputStream(streamType loc); inline void OpenFunction() { if (isSet) qp->Open(pf); } Tuple* NextResultTuple(); ~SpatialJoin2LocalInfo(){ for(int i = 0; i < 2; i++) { if(r[i].tb2Iter){ delete r[i].tb2Iter; r[i].tb2Iter=0; } if (r[i].streamBuffer) { delete r[i].streamBuffer; r[i].streamBuffer = 0; } if (r[i].MBR){ delete r[i].MBR; r[i].MBR=0; } } // delete functions arguments created in the constructor ArgVectorPointer funargs = qp->Argument(pf); if(dim == 2){ delete (CcReal*) (*funargs)[2].addr; delete (CcReal*) (*funargs)[3].addr; delete (CcReal*) (*funargs)[4].addr; delete (CcReal*) (*funargs)[5].addr; delete (CcInt*) (*funargs)[6].addr; delete (CcReal*) (*funargs)[7].addr; delete (CcReal*) (*funargs)[8].addr; } else { // dim==3 delete (CcReal*) (*funargs)[2].addr; delete (CcReal*) (*funargs)[3].addr; delete (CcReal*) (*funargs)[4].addr; delete (CcReal*) (*funargs)[5].addr; delete (CcInt*) (*funargs)[6].addr; delete (CcReal*) (*funargs)[7].addr; delete (CcReal*) (*funargs)[8].addr; delete (CcReal*) (*funargs)[9].addr; delete (CcReal*) (*funargs)[10].addr; delete (CcInt*) (*funargs)[11].addr; delete (CcReal*) (*funargs)[12].addr; } delete joinBox; } }; /* 1.4 pj2LocalInfo Class Assists ~parajoin2~ operator. */ typedef enum { tupBufferA, tupBufferB } tupleBufferType; class pj2LocalInfo: public ProgressLocalInfo { private: Word streamA, streamB; Supplier pf; //parameter function int keyAIndex, keyBIndex; TupleBuffer *tba, *tbb; GenericRelationIterator *ita, *itb; RTuple cta, ctb; int maxMem; bool endOfStream; //End of the output stream bool moreInputTuples; //End of the input stream bool LoadTuples(); //Load tuples with same key attribute value int CompareTuples(Tuple* ta, int kai, Tuple* tb, int kbi); inline Tuple* NextTuple(Word stream) { bool yield = false; Word result( Address(0) ); if(stream.addr) { qp->Request(stream.addr, result); yield = qp->Received(stream.addr); if(yield) { return static_cast (result.addr); } } return 0; } public: pj2LocalInfo(Word _sa, Word _sb, Word _kai, Word _kbi, Word _fun, Supplier s) : streamA(_sa), streamB(_sb), tba(0), tbb(0), ita(0), itb(0), cta(0), ctb(0), endOfStream(false), moreInputTuples(true) { keyAIndex = StdTypes::GetInt( _kai ) - 1; keyBIndex = StdTypes::GetInt( _kbi ) - 1; pf = _fun.addr; qp->SetupStreamArg(pf, 1, s); qp->SetupStreamArg(pf, 2, s); qp->Open(pf); maxMem = (qp->GetMemorySize(s) * 1024 * 1024); } ~pj2LocalInfo() { if (ita){ delete ita; ita = 0;} if (tba){ delete tba; tba = 0;} if (itb){ delete itb; itb = 0;} if (tbb){ delete tbb; tbb = 0;} } Tuple* getNextTuple(); inline Tuple* getNextInputTuple(tupleBufferType tbt) { if (ita && tupBufferA == tbt) return ita->GetNextTuple(); else if (itb && tupBufferB == tbt) return itb->GetNextTuple(); else return 0; } }; #endif /* SPATIALJOIN_ALGEBRA_H__ */