roxielmj.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef ROXIELMJ_HPP
  14. #define ROXIELMJ_HPP
  15. //Limited Match Join helpers (s[1..n])
  16. #include "thorhelper.hpp"
  17. #include "roxiehelper.hpp"
  18. #include "roxiemem.hpp"
  19. #include "limits.h"
  20. #include "jqueue.tpp"
  21. #include "thorcommon.hpp"
  22. //===================================================================================
  23. THORHELPER_API IRHLimitedCompareHelper *createRHLimitedCompareHelper();
  24. //===================================================================================
  25. //CRHRollingCacheElem copied/modified from THOR CRHRollingCacheElem
  26. class CRHRollingCacheElem
  27. {
  28. public:
  29. int cmp;
  30. const void *row;
  31. CRHRollingCacheElem();
  32. ~CRHRollingCacheElem();
  33. void set(const void *_row);
  34. };
  35. //CRHRollingCache copied/modified from THOR
  36. class CRHRollingCache: extends CInterface
  37. {
  38. unsigned max; // max cache size
  39. QueueOf<CRHRollingCacheElem,true> cache;
  40. IRowStream * in;
  41. bool eos;
  42. public:
  43. ~CRHRollingCache();
  44. void init(IRowStream *_in, unsigned _max);
  45. #ifdef TRACEROLLING
  46. void PrintCache();
  47. #endif
  48. inline CRHRollingCacheElem *mid(int rel);
  49. void advance();
  50. };
  51. //===================================================================================
  52. //CRHDualCache copied from THOR CDualCache, and modified to get input from IRowStream instead
  53. //of IReadSeqVar and to manage rows as OwnedRoxieRow types
  54. // Could probably be combined with CDualCache now ?
  55. class THORHELPER_API CRHDualCache: public CInterface
  56. {
  57. // similar to rolling cache - should be combined really
  58. IRowStream * in;
  59. MemoryAttr varbuf;
  60. bool eos;
  61. unsigned base;
  62. unsigned posL;
  63. unsigned posR;
  64. QueueOf<CRHRollingCacheElem,true> cache;
  65. public:
  66. CRHDualCache();
  67. ~CRHDualCache();
  68. void init(IRowStream * _in);
  69. inline IRowStream * input() { return in; }
  70. #ifdef TRACEROLLING
  71. void PrintCache();
  72. #endif
  73. bool get(unsigned n, CRHRollingCacheElem *&out);
  74. class cOut: public IRowStream, public CInterface
  75. {
  76. private:
  77. bool stopped;
  78. CRHDualCache *parent;
  79. unsigned &pos;
  80. public:
  81. IMPLEMENT_IINTERFACE;
  82. cOut(CRHDualCache *_parent, unsigned &_pos);
  83. const void * nextRow();
  84. private:
  85. void stop();
  86. } *strm1, *strm2;
  87. IRowStream *queryOut1() { return strm1; }
  88. IRowStream *queryOut2() { return strm2; }
  89. };
  90. //===================================================================================
  91. inline int iabs(int a) { return a<0?-a:a; }
  92. inline int imin(int a,int b) { return a<b?a:b; }
  93. //CRHLimitedCompareHelper
  94. class CRHLimitedCompareHelper: implements IRHLimitedCompareHelper, public CInterface
  95. {
  96. Owned<CRHRollingCache> cache;
  97. unsigned atmost;
  98. ICompare * limitedcmp;
  99. ICompare * cmp;
  100. public:
  101. IMPLEMENT_IINTERFACE;
  102. void init( unsigned _atmost,
  103. IRowStream *_in,
  104. ICompare * _cmp,
  105. ICompare * _limitedcmp );
  106. bool getGroup(OwnedRowArray &group,const void *left);
  107. };
  108. #endif // ROXIELMJ_HPP