diff options
author | onpopov <onpopov@yandex-team.ru> | 2022-02-10 16:50:38 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:38 +0300 |
commit | 84a29dd4980d5b39615e453f289bd1a81213296d (patch) | |
tree | 5e320f10d6b5863e0d5ab1a8caa9eefbdaa5195f /library/cpp/containers/comptrie/search_iterator.h | |
parent | 1717072c6635948128dad7b015a0ec05acbe913b (diff) | |
download | ydb-84a29dd4980d5b39615e453f289bd1a81213296d.tar.gz |
Restoring authorship annotation for <onpopov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/containers/comptrie/search_iterator.h')
-rw-r--r-- | library/cpp/containers/comptrie/search_iterator.h | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/library/cpp/containers/comptrie/search_iterator.h b/library/cpp/containers/comptrie/search_iterator.h index 247f7e5936..17f6c2bb00 100644 --- a/library/cpp/containers/comptrie/search_iterator.h +++ b/library/cpp/containers/comptrie/search_iterator.h @@ -1,38 +1,38 @@ -#pragma once +#pragma once -#include "comptrie_trie.h" +#include "comptrie_trie.h" #include "first_symbol_iterator.h" - + #include <util/str_stl.h> #include <util/digest/numeric.h> #include <util/digest/multi.h> -// Iterator for incremental searching. -// All Advance() methods shift the iterator using specifed key/char. -// The subsequent Advance() call starts searching from the previous state. -// The Advance() returns 'true' if specified key part exists in the trie and -// returns 'false' for unsuccessful search. In case of 'false' result -// all subsequent calls also will return 'false'. -// If current iterator state is final then GetValue() method returns 'true' and -// associated value. - -template <class TTrie> -class TSearchIterator { -public: - using TData = typename TTrie::TData; - using TSymbol = typename TTrie::TSymbol; - using TKeyBuf = typename TTrie::TKeyBuf; - +// Iterator for incremental searching. +// All Advance() methods shift the iterator using specifed key/char. +// The subsequent Advance() call starts searching from the previous state. +// The Advance() returns 'true' if specified key part exists in the trie and +// returns 'false' for unsuccessful search. In case of 'false' result +// all subsequent calls also will return 'false'. +// If current iterator state is final then GetValue() method returns 'true' and +// associated value. + +template <class TTrie> +class TSearchIterator { +public: + using TData = typename TTrie::TData; + using TSymbol = typename TTrie::TSymbol; + using TKeyBuf = typename TTrie::TKeyBuf; + TSearchIterator() = default; - explicit TSearchIterator(const TTrie& trie) - : Trie(&trie) - , DataPos(trie.DataHolder.AsCharPtr()) - , DataEnd(DataPos + trie.DataHolder.Length()) + explicit TSearchIterator(const TTrie& trie) + : Trie(&trie) + , DataPos(trie.DataHolder.AsCharPtr()) + , DataEnd(DataPos + trie.DataHolder.Length()) , ValuePos(trie.EmptyValue) - { - } - + { + } + explicit TSearchIterator(const TTrie& trie, const TTrie& subTrie) : Trie(&trie) , DataPos(subTrie.Data().AsCharPtr()) @@ -52,33 +52,33 @@ public: return !(*this == other); } - inline bool Advance(TSymbol label) { + inline bool Advance(TSymbol label) { Y_ASSERT(Trie); - if (DataPos == nullptr || DataPos >= DataEnd) { - return false; - } - return NCompactTrie::Advance(DataPos, DataEnd, ValuePos, label, Trie->Packer); - } - inline bool Advance(const TKeyBuf& key) { + if (DataPos == nullptr || DataPos >= DataEnd) { + return false; + } + return NCompactTrie::Advance(DataPos, DataEnd, ValuePos, label, Trie->Packer); + } + inline bool Advance(const TKeyBuf& key) { return Advance(key.data(), key.size()); - } - bool Advance(const TSymbol* key, size_t keylen); - bool GetValue(TData* value = nullptr) const; + } + bool Advance(const TSymbol* key, size_t keylen); + bool GetValue(TData* value = nullptr) const; bool HasValue() const; inline size_t GetHash() const; - -private: + +private: const TTrie* Trie = nullptr; const char* DataPos = nullptr; const char* DataEnd = nullptr; const char* ValuePos = nullptr; -}; - +}; + template <class TTrie> -inline TSearchIterator<TTrie> MakeSearchIterator(const TTrie& trie) { - return TSearchIterator<TTrie>(trie); -} - +inline TSearchIterator<TTrie> MakeSearchIterator(const TTrie& trie) { + return TSearchIterator<TTrie>(trie); +} + template <class TTrie> struct THash<TSearchIterator<TTrie>> { inline size_t operator()(const TSearchIterator<TTrie>& item) { @@ -86,42 +86,42 @@ struct THash<TSearchIterator<TTrie>> { } }; -//---------------------------------------------------------------------------- - -template <class TTrie> -bool TSearchIterator<TTrie>::Advance(const TSymbol* key, size_t keylen) { +//---------------------------------------------------------------------------- + +template <class TTrie> +bool TSearchIterator<TTrie>::Advance(const TSymbol* key, size_t keylen) { Y_ASSERT(Trie); - if (!key || DataPos == nullptr || DataPos >= DataEnd) { - return false; - } - if (!keylen) { - return true; - } - - const TSymbol* keyend = key + keylen; - while (key != keyend && DataPos != nullptr) { - if (!NCompactTrie::Advance(DataPos, DataEnd, ValuePos, *(key++), Trie->Packer)) { - return false; - } - if (key == keyend) { - return true; - } - } - return false; -} - -template <class TTrie> -bool TSearchIterator<TTrie>::GetValue(TData* value) const { + if (!key || DataPos == nullptr || DataPos >= DataEnd) { + return false; + } + if (!keylen) { + return true; + } + + const TSymbol* keyend = key + keylen; + while (key != keyend && DataPos != nullptr) { + if (!NCompactTrie::Advance(DataPos, DataEnd, ValuePos, *(key++), Trie->Packer)) { + return false; + } + if (key == keyend) { + return true; + } + } + return false; +} + +template <class TTrie> +bool TSearchIterator<TTrie>::GetValue(TData* value) const { Y_ASSERT(Trie); - bool result = false; - if (value) { - if (ValuePos) { - result = true; - Trie->Packer.UnpackLeaf(ValuePos, *value); - } - } - return result; -} + bool result = false; + if (value) { + if (ValuePos) { + result = true; + Trie->Packer.UnpackLeaf(ValuePos, *value); + } + } + return result; +} template <class TTrie> bool TSearchIterator<TTrie>::HasValue() const { |