node.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #include <cstddef>
  3. namespace NCompactTrie {
  4. class ILeafSkipper;
  5. enum TDirection {
  6. D_LEFT,
  7. D_FINAL,
  8. D_NEXT,
  9. D_RIGHT,
  10. D_MAX
  11. };
  12. inline TDirection& operator++(TDirection& direction) {
  13. direction = static_cast<TDirection>(direction + 1);
  14. return direction;
  15. }
  16. inline TDirection& operator--(TDirection& direction) {
  17. direction = static_cast<TDirection>(direction - 1);
  18. return direction;
  19. }
  20. class TNode {
  21. public:
  22. TNode();
  23. // Processes epsilon links and sets ForwardOffset to correct value. Assumes an epsilon link doesn't point to an epsilon link.
  24. TNode(const char* data, size_t offset, const ILeafSkipper& skipFunction);
  25. size_t GetOffset() const {
  26. return Offset;
  27. }
  28. size_t GetLeafOffset() const {
  29. return Offsets[D_FINAL];
  30. }
  31. size_t GetLeafLength() const {
  32. return LeafLength;
  33. }
  34. size_t GetCoreLength() const {
  35. return CoreLength;
  36. }
  37. size_t GetOffsetByDirection(TDirection direction) const {
  38. return Offsets[direction];
  39. }
  40. size_t GetForwardOffset() const {
  41. return Offsets[D_NEXT];
  42. }
  43. size_t GetLeftOffset() const {
  44. return Offsets[D_LEFT];
  45. }
  46. size_t GetRightOffset() const {
  47. return Offsets[D_RIGHT];
  48. }
  49. char GetLabel() const {
  50. return Label;
  51. }
  52. bool IsFinal() const {
  53. return GetLeafOffset() != 0;
  54. }
  55. bool HasEpsilonLinkForward() const {
  56. return GetForwardOffset() > Offset + CoreLength;
  57. }
  58. private:
  59. size_t Offsets[D_MAX];
  60. size_t Offset;
  61. size_t LeafLength;
  62. size_t CoreLength;
  63. char Label;
  64. };
  65. }