leaf_skipper.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <cstddef>
  3. namespace NCompactTrie {
  4. class ILeafSkipper {
  5. public:
  6. virtual size_t SkipLeaf(const char* p) const = 0;
  7. virtual ~ILeafSkipper() = default;
  8. };
  9. template <class TPacker>
  10. class TPackerLeafSkipper: public ILeafSkipper {
  11. private:
  12. const TPacker* Packer;
  13. public:
  14. TPackerLeafSkipper(const TPacker* packer)
  15. : Packer(packer)
  16. {
  17. }
  18. size_t SkipLeaf(const char* p) const override {
  19. return Packer->SkipLeaf(p);
  20. }
  21. // For test purposes.
  22. const TPacker* GetPacker() const {
  23. return Packer;
  24. }
  25. };
  26. // The data you need to traverse the trie without unpacking the values.
  27. struct TOpaqueTrie {
  28. const char* Data;
  29. size_t Length;
  30. const ILeafSkipper& SkipFunction;
  31. TOpaqueTrie(const char* data, size_t dataLength, const ILeafSkipper& skipFunction)
  32. : Data(data)
  33. , Length(dataLength)
  34. , SkipFunction(skipFunction)
  35. {
  36. }
  37. bool operator==(const TOpaqueTrie& other) const {
  38. return Data == other.Data &&
  39. Length == other.Length &&
  40. &SkipFunction == &other.SkipFunction;
  41. }
  42. bool operator!=(const TOpaqueTrie& other) const {
  43. return !(*this == other);
  44. }
  45. };
  46. }