diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/containers/comptrie/node.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/containers/comptrie/node.h')
-rw-r--r-- | library/cpp/containers/comptrie/node.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/library/cpp/containers/comptrie/node.h b/library/cpp/containers/comptrie/node.h new file mode 100644 index 00000000000..d6f4317db09 --- /dev/null +++ b/library/cpp/containers/comptrie/node.h @@ -0,0 +1,80 @@ +#pragma once + +#include <cstddef> + +namespace NCompactTrie { + class ILeafSkipper; + + enum TDirection { + D_LEFT, + D_FINAL, + D_NEXT, + D_RIGHT, + D_MAX + }; + + inline TDirection& operator++(TDirection& direction) { + direction = static_cast<TDirection>(direction + 1); + return direction; + } + + inline TDirection& operator--(TDirection& direction) { + direction = static_cast<TDirection>(direction - 1); + return direction; + } + + class TNode { + public: + TNode(); + // Processes epsilon links and sets ForwardOffset to correct value. Assumes an epsilon link doesn't point to an epsilon link. + TNode(const char* data, size_t offset, const ILeafSkipper& skipFunction); + + size_t GetOffset() const { + return Offset; + } + + size_t GetLeafOffset() const { + return Offsets[D_FINAL]; + } + size_t GetLeafLength() const { + return LeafLength; + } + size_t GetCoreLength() const { + return CoreLength; + } + + size_t GetOffsetByDirection(TDirection direction) const { + return Offsets[direction]; + } + + size_t GetForwardOffset() const { + return Offsets[D_NEXT]; + } + size_t GetLeftOffset() const { + return Offsets[D_LEFT]; + } + size_t GetRightOffset() const { + return Offsets[D_RIGHT]; + } + char GetLabel() const { + return Label; + } + + bool IsFinal() const { + return GetLeafOffset() != 0; + } + + bool HasEpsilonLinkForward() const { + return GetForwardOffset() > Offset + CoreLength; + } + + private: + size_t Offsets[D_MAX]; + size_t Offset; + size_t LeafLength; + size_t CoreLength; + + char Label; + }; + +} |