diff options
author | Yuri Gorshenin <y@maps.me> | 2016-06-09 12:00:59 +0300 |
---|---|---|
committer | Yuri Gorshenin <y@maps.me> | 2016-06-09 13:20:37 +0300 |
commit | 5f8ac14b9495abd06ede4938825d5523773b86ac (patch) | |
tree | 3ffecac2e8397d977c0649a3c31877fe3423c3da /indexer/string_set.hpp | |
parent | 033e4094cb602190ab1a8854e319f8ae42e17580 (diff) |
Review fixes.
Diffstat (limited to 'indexer/string_set.hpp')
-rw-r--r-- | indexer/string_set.hpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/indexer/string_set.hpp b/indexer/string_set.hpp index dde65e5daf..c705b62bcf 100644 --- a/indexer/string_set.hpp +++ b/indexer/string_set.hpp @@ -8,6 +8,14 @@ namespace search { +// A trie. TChar is a type of string characters, OutDegree is an +// expected branching factor. Therefore, both Add(s) and Has(s) have +// expected complexity O(OutDegree * Length(s)). For small values of +// OutDegree this is quite fast, but if OutDegree can be large and you +// need guaranteed O(Log(AlphabetSize) * Length(s)), refactor this +// class. +// +// TODO (@y): unify this with my::MemTrie. template <typename TChar, size_t OutDegree> class StringSet { @@ -43,6 +51,8 @@ private: { Node() : m_isLeaf(false) {} + // Tries to move from the current node by |c|. If the move can't + // be made, returns nullptr. Node const * Move(TChar c) const { for (auto const & p : m_moves) @@ -53,6 +63,8 @@ private: return nullptr; } + // Tries to move from the current node by [|begin|, |end|). If the + // move can't be made, returns nullptr. template <typename TIt> Node const * Move(TIt begin, TIt end) const { @@ -62,6 +74,8 @@ private: return cur; } + // Moves from the current node by |c|. If the move can't be made, + // creates a new sub-tree and moves to it. Node & MakeMove(TChar c) { for (auto const & p : m_moves) @@ -73,6 +87,9 @@ private: return *m_moves.back().second; } + // Moves from the current node by [|begin|, |end|). If there were + // no path from the current node labeled by [|begin|, |end|), this + // method will create it. template <typename TIt> Node & MakeMove(TIt begin, TIt end) { |