keybuild.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 KEYBUILD_HPP
  14. #define KEYBUILD_HPP
  15. #include "ctfile.hpp"
  16. class CNodeInfo : implements serializable, public CInterface
  17. {
  18. public:
  19. offset_t pos;
  20. void *value;
  21. unsigned size;
  22. unsigned __int64 sequence;
  23. IMPLEMENT_IINTERFACE;
  24. CNodeInfo(offset_t _pos, const void *_value, unsigned _size, unsigned __int64 _sequence)
  25. {
  26. pos = _pos;
  27. size = _size;
  28. sequence = _sequence;
  29. if (_value)
  30. {
  31. value = malloc(size);
  32. memcpy(value, _value, size);
  33. }
  34. else
  35. value = NULL;
  36. }
  37. CNodeInfo()
  38. {
  39. pos = 0;
  40. size = 0;
  41. value = NULL;
  42. sequence = 0;
  43. }
  44. ~CNodeInfo()
  45. {
  46. free(value);
  47. }
  48. void serialize(MemoryBuffer &tgt)
  49. {
  50. tgt.append(pos).append(size).append(sequence);
  51. if (value)
  52. tgt.append(true).append(size, value);
  53. else
  54. tgt.append(false);
  55. }
  56. void deserialize(MemoryBuffer &src)
  57. {
  58. src.read(pos);
  59. src.read(size);
  60. src.read(sequence);
  61. bool hasValue;
  62. src.read(hasValue);
  63. if (hasValue)
  64. {
  65. value = malloc(size);
  66. memcpy(value, src.readDirect(size), size);
  67. }
  68. else
  69. value = NULL;
  70. }
  71. static int compare(IInterface * const *ll, IInterface * const *rr)
  72. {
  73. CNodeInfo *l = (CNodeInfo *) *ll;
  74. CNodeInfo *r = (CNodeInfo *) *rr;
  75. if (l->pos < r->pos)
  76. return -1;
  77. else if (l->pos == r->pos)
  78. return 0;
  79. else
  80. return 1;
  81. }
  82. };
  83. typedef IArrayOf<CNodeInfo> NodeInfoArray;
  84. interface IKeyBuilder : public IInterface
  85. {
  86. virtual void finish(unsigned *crc = NULL) = 0;
  87. virtual void finish(IPropertyTree * metadata, unsigned * crc = NULL) = 0;
  88. virtual void processKeyData(const char *keyData, offset_t pos, size32_t recsize) = 0;
  89. virtual void addLeafInfo(CNodeInfo *info) = 0;
  90. virtual unsigned __int64 createBlob(size32_t size, const char * _ptr) = 0;
  91. };
  92. extern jhtree_decl IKeyBuilder *createKeyBuilder(IFileIOStream *_out, unsigned flags, unsigned rawSize, unsigned nodeSize, unsigned keyFieldSize, unsigned __int64 startSequence);
  93. interface IKeyDesprayer : public IInterface
  94. {
  95. virtual void addPart(unsigned idx, offset_t numRecords, NodeInfoArray & nodes) = 0;
  96. virtual void finish() = 0;
  97. };
  98. extern jhtree_decl IKeyDesprayer * createKeyDesprayer(IFile * in, IFileIOStream * out);
  99. #endif