blob: 608e081df63c76db987264329c1be2be4a3c7f8b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#ifndef PREFIX_TREE_HH
#define PREFIX_TREE_HH
#include <memory>
#include <optional>
#include <string>
#include <string_view>
namespace prefix_tree {
class Builder {
public:
virtual ~Builder() = default;
Builder(Builder const&) = delete;
Builder& operator=(Builder const&) = delete;
virtual void add(std::string_view str) = 0;
[[nodiscard]]
virtual std::optional<std::string> build() const = 0;
protected:
Builder() = default;
};
[[nodiscard]]
std::unique_ptr<Builder> builder();
// Returns the length of the prefix of str that exists in tree.
// Returns nullopt if prefix of str doesn't match any string in tree.
[[nodiscard]]
std::optional<size_t> lookup(std::string_view tree, std::string_view str);
} // namespace prefix_tree
#endif // PREFIX_TREE_HH
|