aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/containers/comptrie/prefix_iterator.h
diff options
context:
space:
mode:
authoronpopov <onpopov@yandex-team.ru>2022-02-10 16:50:38 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:38 +0300
commit84a29dd4980d5b39615e453f289bd1a81213296d (patch)
tree5e320f10d6b5863e0d5ab1a8caa9eefbdaa5195f /library/cpp/containers/comptrie/prefix_iterator.h
parent1717072c6635948128dad7b015a0ec05acbe913b (diff)
downloadydb-84a29dd4980d5b39615e453f289bd1a81213296d.tar.gz
Restoring authorship annotation for <onpopov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/containers/comptrie/prefix_iterator.h')
-rw-r--r--library/cpp/containers/comptrie/prefix_iterator.h162
1 files changed, 81 insertions, 81 deletions
diff --git a/library/cpp/containers/comptrie/prefix_iterator.h b/library/cpp/containers/comptrie/prefix_iterator.h
index b369bb4f42..23b9cbf7c6 100644
--- a/library/cpp/containers/comptrie/prefix_iterator.h
+++ b/library/cpp/containers/comptrie/prefix_iterator.h
@@ -1,88 +1,88 @@
-#pragma once
+#pragma once
-#include "comptrie_trie.h"
-
-// Iterates over all prefixes of the given key in the trie.
-template <class TTrie>
-class TPrefixIterator {
-public:
- using TSymbol = typename TTrie::TSymbol;
- using TPacker = typename TTrie::TPacker;
- using TData = typename TTrie::TData;
-
-private:
- const TTrie& Trie;
- const TSymbol* key;
- size_t keylen;
- const TSymbol* keyend;
- size_t prefixLen;
- const char* valuepos;
- const char* datapos;
- const char* dataend;
- TPacker Packer;
- const char* EmptyValue;
- bool result;
-
- bool Next();
-
-public:
+#include "comptrie_trie.h"
+
+// Iterates over all prefixes of the given key in the trie.
+template <class TTrie>
+class TPrefixIterator {
+public:
+ using TSymbol = typename TTrie::TSymbol;
+ using TPacker = typename TTrie::TPacker;
+ using TData = typename TTrie::TData;
+
+private:
+ const TTrie& Trie;
+ const TSymbol* key;
+ size_t keylen;
+ const TSymbol* keyend;
+ size_t prefixLen;
+ const char* valuepos;
+ const char* datapos;
+ const char* dataend;
+ TPacker Packer;
+ const char* EmptyValue;
+ bool result;
+
+ bool Next();
+
+public:
TPrefixIterator(const TTrie& trie, const TSymbol* aKey, size_t aKeylen)
- : Trie(trie)
+ : Trie(trie)
, key(aKey)
, keylen(aKeylen)
, keyend(aKey + aKeylen)
- , prefixLen(0)
- , valuepos(nullptr)
- , datapos(trie.DataHolder.AsCharPtr())
- , dataend(datapos + trie.DataHolder.Length())
- {
- result = Next();
- }
-
+ , prefixLen(0)
+ , valuepos(nullptr)
+ , datapos(trie.DataHolder.AsCharPtr())
+ , dataend(datapos + trie.DataHolder.Length())
+ {
+ result = Next();
+ }
+
operator bool() const {
- return result;
- }
-
+ return result;
+ }
+
TPrefixIterator& operator++() {
- result = Next();
- return *this;
- }
-
- size_t GetPrefixLen() const {
- return prefixLen;
- }
-
- void GetValue(TData& to) const {
- Trie.Packer.UnpackLeaf(valuepos, to);
- }
-};
-
-template <class TTrie>
-bool TPrefixIterator<TTrie>::Next() {
- using namespace NCompactTrie;
- if (!key || datapos == dataend)
- return false;
-
- if ((key == keyend - keylen) && !valuepos && Trie.EmptyValue) {
- valuepos = Trie.EmptyValue;
- return true;
- }
-
- while (datapos && key != keyend) {
- TSymbol label = *(key++);
- if (!Advance(datapos, dataend, valuepos, label, Packer)) {
- return false;
- }
- if (valuepos) { // There is a value at the end of this symbol.
- prefixLen = keylen - (keyend - key);
- return true;
- }
- }
-
- return false;
-}
-
-template <class TTrie>
-TPrefixIterator<TTrie> MakePrefixIterator(const TTrie& trie, const typename TTrie::TSymbol* key, size_t keylen) {
- return TPrefixIterator<TTrie>(trie, key, keylen);
-}
+ result = Next();
+ return *this;
+ }
+
+ size_t GetPrefixLen() const {
+ return prefixLen;
+ }
+
+ void GetValue(TData& to) const {
+ Trie.Packer.UnpackLeaf(valuepos, to);
+ }
+};
+
+template <class TTrie>
+bool TPrefixIterator<TTrie>::Next() {
+ using namespace NCompactTrie;
+ if (!key || datapos == dataend)
+ return false;
+
+ if ((key == keyend - keylen) && !valuepos && Trie.EmptyValue) {
+ valuepos = Trie.EmptyValue;
+ return true;
+ }
+
+ while (datapos && key != keyend) {
+ TSymbol label = *(key++);
+ if (!Advance(datapos, dataend, valuepos, label, Packer)) {
+ return false;
+ }
+ if (valuepos) { // There is a value at the end of this symbol.
+ prefixLen = keylen - (keyend - key);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+template <class TTrie>
+TPrefixIterator<TTrie> MakePrefixIterator(const TTrie& trie, const typename TTrie::TSymbol* key, size_t keylen) {
+ return TPrefixIterator<TTrie>(trie, key, keylen);
+}