/* ---- This file is part of SECONDO. Copyright (C) 2019, Faculty of Mathematics and Computer Science, Database Systems for New Applications. SECONDO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. SECONDO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SECONDO; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ---- //[<] [\ensuremath{<}] //[>] [\ensuremath{>}] \setcounter{tocdepth}{3} \tableofcontents 1 Hybrid Hash Join */ #pragma once #include #include #include #include "Operator.h" #include "vector" #include "thread" #include "condition_variable" #include #include #include "Algebras/MMRTree/TupleStore1.h" #include "Algebras/SPart/IrregularGrid2D.h" namespace mthreaded { typedef std::function bboxFunc; constexpr int MINRTREE = 4; constexpr int MAXRTREE = 8; class CandidateWorker { private: size_t static constexpr DIM = 2; const size_t maxMem; size_t workersMem; size_t coreNoWorker; size_t streamInNo; std::shared_ptr tupleBuffer; std::shared_ptr partBufferR; std::shared_ptr partBufferS; std::pair joinAttr; std::shared_ptr calcBbox; const double resize; Word fun; TupleType* resultTupleType; const Rect* gridcell; std::shared_ptr> rtreeR; TupleType* ttR; std::vector bufferRMem; size_t countInMem; public: CandidateWorker( size_t _globalMem, size_t _coreNoWorker, size_t _streamInNo, std::shared_ptr _tupleBuffer, std::shared_ptr _partBufferR, std::shared_ptr _partBufferS, std::pair _joinAttr, const double _resize, TupleType* _resultTupleType, const Rect* _gridcell); ~CandidateWorker(); // Thread void operator()(); private: size_t topright(Rect* r1) const; inline bool reportTopright(size_t r1, size_t r2) const; inline void calcMem(Tuple* tuple); void calcRtree(Tuple* tuple, TupleId id, std::shared_ptr overflowBufferR, bool &overflowR); void calcResult(Tuple* tuple); size_t calcIterations(const size_t countOverflow, const size_t tupleSize) const; void freeRTree(); }; class spatialJoinLI { private: Stream streamR; Stream streamS; std::pair joinAttr; const double resize; std::vector joinThreads; size_t maxMem; size_t coreNo; size_t coreNoWorker; TupleType* resultTupleType; TupleType* ttR; TupleType* ttS; std::shared_ptr calcBbox; const size_t cores = MThreadedSingleton::getCoresToUse(); std::shared_ptr tupleBuffer; std::vector> partBufferR; std::vector> partBufferS; size_t bboxsample; constexpr static size_t BBOXSAMPLESTEPS = 10; constexpr static size_t CHANGEBOXSAMPLESTEP = 1000; size_t globalMem; IrregularGrid2D* irrGrid2d; std::vector cellInfoVec; //size_t countN = 0; public: //Constructor spatialJoinLI(Word _streamR, Word _streamS, std::pair _joinAttr, double _resize, size_t _maxMem, ListExpr resultType); //Destructor ~spatialJoinLI(); //Output Tuple* getNext(); private: //Scheduler void Scheduler(); }; class op_spatialJoin { static ListExpr spatialJoinTM(ListExpr args); static int spatialJoinVM(Word* args, Word &result, int message, Word &local, Supplier s); std::string getOperatorSpec(); public: explicit op_spatialJoin() = default; ~op_spatialJoin() = default; std::shared_ptr getOperator(); }; } // end of namespace mthreaded