codec_doclist.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Tencent is pleased to support the open source community by making wwsearch
  3. * available.
  4. *
  5. * Copyright (C) 2018-present Tencent. All Rights Reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  8. * use this file except in compliance with the License. You may obtain a copy of
  9. * the License at
  10. *
  11. * https://opensource.org/licenses/Apache-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OF ANY KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations under the License.
  17. */
  18. #pragma once
  19. #include "doc_iterator.h"
  20. #include "search_slice.h"
  21. #include "serialize.h"
  22. #include "storage_type.h"
  23. namespace wwsearch {
  24. // 1 byte in header
  25. // no order insert.
  26. struct DocListHeader {
  27. // version = 0 -> default,fixed size
  28. uint8_t version : 4;
  29. // flag for version used
  30. uint8_t flag : 3;
  31. uint8_t extend : 1;
  32. DocListHeader() : version(0), flag(0), extend(0) {}
  33. } __attribute__((packed));
  34. typedef uint8_t DocumentState;
  35. enum kDocumentIDState { kDocumentStateOK = 0, kDocumentStateDelete = 1 };
  36. class DocListWriterCodec : public SerializeAble {
  37. public:
  38. virtual ~DocListWriterCodec() {}
  39. virtual void AddDocID(const DocumentID& doc_id, DocumentState state) = 0;
  40. virtual std::string DebugString() = 0;
  41. };
  42. class DocListReaderCodec : public DocIdSetIterator {
  43. private:
  44. size_t priority_; // used for merge.
  45. public:
  46. virtual ~DocListReaderCodec() {}
  47. virtual DocumentState& State() = 0;
  48. inline void SetPriority(size_t v) { this->priority_ = v; }
  49. inline size_t GetPriority() { return this->priority_; }
  50. private:
  51. };
  52. typedef bool (*DocListReaderCodecGreater)(DocListReaderCodec* left,
  53. DocListReaderCodec* right);
  54. } // namespace wwsearch