rtlkey.hpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 RTLKEY_INCL
  14. #define RTLKEY_INCL
  15. #include "eclrtl.hpp"
  16. enum KeySegmentMonitorSerializeType
  17. {
  18. KSMST_none, // can't serialize
  19. KSMST_WILDKEYSEGMENTMONITOR,
  20. KSMST_SETKEYSEGMENTMONITOR,
  21. KSMST_SINGLEKEYSEGMENTMONITOR,
  22. KSMST_SINGLEBIGSIGNEDKEYSEGMENTMONITOR,
  23. KSMST_SINGLELITTLESIGNEDKEYSEGMENTMONITOR,
  24. KSMST_CSINGLELITTLEKEYSEGMENTMONITOR,
  25. KSMST_DUMMYKEYSEGMENTMONITOR,
  26. KSMST_OVERRIDEABLEKEYSEGMENTMONITOR,
  27. KSMST_VAROFFSETKEYSEGMENTMONITOR,
  28. KSMST_max
  29. };
  30. interface ITransition : extends IInterface
  31. {
  32. virtual bool getState() const = 0;
  33. virtual const void *getValue() const = 0;
  34. virtual MemoryBuffer &serialize(size32_t size, MemoryBuffer &buffer) const = 0;
  35. };
  36. interface IStringSet : public IInterface
  37. {
  38. virtual void addRange(const void *loval, const void *hival) = 0;
  39. virtual void addAll() = 0;
  40. virtual ITransition *queryTransition(unsigned idx) = 0;
  41. virtual bool getTransitionValue(void *value, unsigned idx) = 0;
  42. virtual void killRange(const void *loval, const void *hival) = 0;
  43. virtual bool inRange(const void *val) const = 0;
  44. virtual bool inRange(const void *val, unsigned &transition) const = 0;
  45. virtual size32_t getSize() = 0;
  46. virtual void reset() = 0;
  47. virtual unsigned transitionCount() = 0;
  48. virtual const char *describe(StringBuffer &ret) = 0;
  49. virtual IStringSet *invertSet() = 0;
  50. virtual IStringSet *unionSet(IStringSet *) = 0;
  51. virtual IStringSet *intersectSet(IStringSet *) = 0;
  52. virtual bool isEmptySet() const = 0;
  53. virtual bool isFullSet() const = 0;
  54. virtual bool isSingleValue() const = 0;
  55. virtual bool isSigned() const = 0;
  56. virtual bool isBigEndian() const = 0;
  57. virtual unsigned numValues() const = 0;
  58. virtual int memcmp(const void *val1, const void *val2, size32_t size) const = 0;
  59. virtual bool decrement(void *val) const = 0;
  60. virtual bool increment(void *val) const = 0;
  61. virtual MemoryBuffer &serialize(MemoryBuffer &buffer) const = 0;
  62. };
  63. ECLRTL_API IStringSet *createStringSet(size32_t size);
  64. ECLRTL_API IStringSet *createStringSet(size32_t size, bool bigEndian, bool isSigned);
  65. ECLRTL_API IStringSet *deserializeStringSet(MemoryBuffer &mb);
  66. ECLRTL_API int memcmpbigsigned(const void *l, const void *r, unsigned size);
  67. ECLRTL_API int memcmplittleunsigned(const void *l, const void *r, unsigned size);
  68. ECLRTL_API int memcmplittlesigned(const void *l, const void *r, unsigned size);
  69. class RtlRow;
  70. // In the parameter names below, "expanded" means it's a pointer to a "key buffer" value, while
  71. // "raw" means it's a pointer to a disk record. For indexes, the two are the same, but for
  72. // disk files where we may be using segmonitors as a way to serialize remote filters and to build on-the-fly indexes,
  73. // the distinction is significant.
  74. // To support varoffset segmonitors, all "raw" values are passed as const RtlRow *. We do not support varoffset segmonitors in
  75. // on-the-fly in-memory indexes, meaning that the functions taking "expanded" params do not need to support offset translation
  76. // and the varoffset segmonitor does not implement these functions.
  77. interface IKeySegmentMonitor : public IInterface
  78. {
  79. public:
  80. virtual bool increment(void * expandedRow) const = 0;
  81. virtual void setLow(void * expandedRow) const = 0;
  82. virtual void endRange(void * expandedRow) const = 0;
  83. virtual bool matchesBuffer(const void * expandedRow) const = 0;
  84. virtual bool matches(const RtlRow * rawRow) const = 0;
  85. virtual IKeySegmentMonitor *merge(IKeySegmentMonitor *with) const = 0; // merge with adjacent, if possible
  86. virtual IKeySegmentMonitor *combine(const IKeySegmentMonitor *with) const = 0; // combine with overlapping (compulsory)
  87. virtual IKeySegmentMonitor * split(unsigned splitSize) = 0;
  88. virtual bool isWild() const = 0;
  89. virtual unsigned getOffset() const = 0;
  90. virtual unsigned getSize() const = 0;
  91. virtual void *queryValue() const = 0;
  92. virtual int docompare(const void * expandedLeft, const void * rawRight) const = 0;
  93. // virtual unsigned getFlags() const = 0;
  94. virtual bool isEmpty() const = 0;
  95. virtual bool equivalentTo(const IKeySegmentMonitor &other) const = 0;
  96. virtual bool isSigned() const = 0;
  97. virtual bool isLittleEndian() const = 0;
  98. virtual int docompareraw(const void * rawLeft, const void * rawRight) const = 0; // NOTE - no RtlRow version since only used for in-memory index builds
  99. virtual unsigned queryHashCode() const = 0;
  100. virtual bool isWellKeyed() const = 0;
  101. virtual bool setOffset(unsigned _offset) = 0;
  102. virtual bool isOptional() const = 0;
  103. virtual void setHigh(void * expandedRow) const = 0;
  104. virtual bool isSimple() const = 0;
  105. virtual void copy(void *expandedRow, const void *rawRow) const = 0;
  106. virtual MemoryBuffer &serialize(MemoryBuffer &mb) const = 0;
  107. virtual KeySegmentMonitorSerializeType serializeType() const = 0;
  108. virtual IKeySegmentMonitor *clone() const = 0;
  109. virtual unsigned numFieldsRequired() const = 0;
  110. };
  111. interface IOverrideableKeySegmentMonitor : public IKeySegmentMonitor
  112. {
  113. virtual void setOverrideBuffer(const void *ptr) = 0;
  114. };
  115. interface IBlobProvider
  116. {
  117. virtual byte * lookupBlob(unsigned __int64 id) = 0; // return reference, not freed by code generator, can dispose once transform() has returned.
  118. };
  119. interface IBlobCreator
  120. {
  121. virtual unsigned __int64 createBlob(size32_t _size, const void * _ptr) = 0;
  122. };
  123. interface IIndexReadContext
  124. {
  125. public:
  126. virtual void append(IKeySegmentMonitor *segment) = 0;
  127. virtual unsigned ordinality() const = 0;
  128. virtual IKeySegmentMonitor *item(unsigned idx) const = 0;
  129. virtual void setMergeBarrier(unsigned offset) = 0;
  130. };
  131. interface IKeySegmentOffsetTranslator : public IInterface
  132. {
  133. virtual const void * getSegmentBase(const void * row) const = 0;
  134. virtual const char * queryFactoryName() const = 0;
  135. };
  136. interface IKeySegmentFormatTranslator : public IInterface
  137. {
  138. virtual void extractField(void * target, const void * row) const = 0;
  139. virtual const char * queryFactoryName() const = 0;
  140. virtual unsigned queryHashCode() const = 0;
  141. };
  142. ECLRTL_API IStringSet *createRtlStringSet(size32_t size);
  143. ECLRTL_API IStringSet *createRtlStringSetEx(size32_t size, bool bigEndian, bool isSigned);
  144. ECLRTL_API IStringSet *createRtlStringValue(size32_t size, const char * value);
  145. //Following can optionally return either of their arguments as the result.
  146. ECLRTL_API IStringSet *rtlUnionSet(IStringSet * lhs, IStringSet * rhs);
  147. ECLRTL_API IStringSet *rtlIntersectSet(IStringSet * lhs, IStringSet * rhs);
  148. ECLRTL_API IKeySegmentMonitor *createKeySegmentMonitor(bool optional, IStringSet *set, unsigned _offset, unsigned _size);
  149. ECLRTL_API IKeySegmentMonitor *createEmptyKeySegmentMonitor(bool optional, unsigned _offset, unsigned _size);
  150. ECLRTL_API IKeySegmentMonitor *createWildKeySegmentMonitor(unsigned _offset, unsigned _size);
  151. ECLRTL_API IKeySegmentMonitor *createDummyKeySegmentMonitor(unsigned _offset, unsigned _size, bool isSigned, bool isLittleEndian);
  152. ECLRTL_API IKeySegmentMonitor *createSingleKeySegmentMonitor(bool optional, unsigned _offset, unsigned _size, const void * value);
  153. ECLRTL_API IOverrideableKeySegmentMonitor *createOverrideableKeySegmentMonitor(IKeySegmentMonitor *base);
  154. ECLRTL_API IKeySegmentMonitor *createSingleBigSignedKeySegmentMonitor(bool optional, unsigned offset, unsigned size, const void * value);
  155. ECLRTL_API IKeySegmentMonitor *createSingleLittleSignedKeySegmentMonitor(bool optional, unsigned offset, unsigned size, const void * value);
  156. ECLRTL_API IKeySegmentMonitor *createSingleLittleKeySegmentMonitor(bool optional, unsigned offset, unsigned size, const void * value);
  157. //takes over ownership of base
  158. ECLRTL_API IKeySegmentMonitor *createNewVarOffsetKeySegmentMonitor(IKeySegmentMonitor * base, unsigned fieldIdx);
  159. //takes over ownership of both arguments
  160. ECLRTL_API IKeySegmentMonitor *createTranslatedKeySegmentMonitor(IKeySegmentMonitor * base, unsigned offset, IKeySegmentFormatTranslator * translator);
  161. ECLRTL_API IKeySegmentMonitor *deserializeKeySegmentMonitor(MemoryBuffer &mb);
  162. ECLRTL_API void deserializeSet(IStringSet & set, size32_t minRecordSize, const RtlTypeInfo * fieldType, const char * filter);
  163. #endif