tetengo 1.9.2
A multipurpose library set
Loading...
Searching...
No Matches
double_array.hpp
Go to the documentation of this file.
1
6
7#if !defined(TETENGO_TRIE_DOUBLEARRAY_HPP)
8#define TETENGO_TRIE_DOUBLEARRAY_HPP
9
10#include <cstddef>
11#include <cstdint>
12#include <functional>
13#include <memory>
14#include <optional>
15#include <string>
16#include <string_view>
17#include <utility>
18#include <vector>
19
20#include <boost/core/noncopyable.hpp>
21
22namespace tetengo::trie
23{
25
26 class storage;
27
28
32 class double_array : private boost::noncopyable
33 {
34 public:
35 // tyes
36
39 {
46 std::function<void(const std::pair<std::string_view, std::int32_t>& element)> adding;
47
51 std::function<void()> done;
52 };
53
54
55 // static functions
56
63
69 [[nodiscard]] static std::size_t default_density_factor();
70
76 [[nodiscard]] static char key_terminator();
77
83 [[nodiscard]] static std::uint8_t vacant_check_value();
84
85
86 // constructors and destructor
87
92
102 explicit double_array(
103 const std::vector<std::pair<std::string_view, std::int32_t>>& elements,
104 const building_observer_set_type& building_observer_set = null_building_observer_set(),
105 std::size_t density_factor = default_density_factor());
106
116 explicit double_array(
117 const std::vector<std::pair<std::string, std::int32_t>>& elements,
118 const building_observer_set_type& building_observer_set = null_building_observer_set(),
119 std::size_t density_factor = default_density_factor());
120
133 template <typename InputIterator>
135 InputIterator first,
136 InputIterator last,
137 const building_observer_set_type& building_observer_set = null_building_observer_set(),
138 std::size_t density_factor = default_density_factor()) :
139 double_array{ std::vector<typename InputIterator::value_type>{ first, last },
140 building_observer_set,
141 density_factor }
142 {}
143
150 double_array(std::unique_ptr<storage>&& p_storage, std::size_t root_base_check_index);
151
156
157
158 // functions
159
167 [[nodiscard]] std::optional<std::int32_t> find(const std::string_view& key) const;
168
174 [[nodiscard]] double_array_iterator begin() const;
175
181 [[nodiscard]] double_array_iterator end() const;
182
191 [[nodiscard]] std::unique_ptr<double_array> subtrie(const std::string_view& key_prefix) const;
192
198 [[nodiscard]] const storage& get_storage() const;
199
205 [[nodiscard]] storage& get_storage();
206
207
208 private:
209 // types
210
211 class impl;
212
213
214 // variables
215
216 const std::unique_ptr<impl> m_p_impl;
217 };
218
219
220}
221
222
223#endif
A double array iterator.
Definition double_array_iterator.hpp:32
std::optional< std::int32_t > find(const std::string_view &key) const
Finds the value correspoinding the given key.
static char key_terminator()
Returns the key terminator.
static std::uint8_t vacant_check_value()
Returns the check value for a vacant element.
double_array(const std::vector< std::pair< std::string, std::int32_t > > &elements, const building_observer_set_type &building_observer_set=null_building_observer_set(), std::size_t density_factor=default_density_factor())
Creates a double array.
double_array_iterator end() const
Returns a last iterator.
static const building_observer_set_type & null_building_observer_set()
Returns the null building observer set.
const storage & get_storage() const
Returns the storage.
std::unique_ptr< double_array > subtrie(const std::string_view &key_prefix) const
Returns a subtrie.
static std::size_t default_density_factor()
Returns the default density factor.
double_array(std::unique_ptr< storage > &&p_storage, std::size_t root_base_check_index)
Creates a double array.
double_array_iterator begin() const
Returns a first iterator.
double_array(InputIterator first, InputIterator last, const building_observer_set_type &building_observer_set=null_building_observer_set(), std::size_t density_factor=default_density_factor())
Creates a double array.
Definition double_array.hpp:134
~double_array()
Destroys the double array.
storage & get_storage()
Returns the storage.
double_array()
Creates a double array.
double_array(const std::vector< std::pair< std::string_view, std::int32_t > > &elements, const building_observer_set_type &building_observer_set=null_building_observer_set(), std::size_t density_factor=default_density_factor())
Creates a double array.
A storage.
Definition storage.hpp:28
A trie library.
The building observer set type.
Definition double_array.hpp:39
std::function< void(const std::pair< std::string_view, std::int32_t > &element)> adding
Called when a key is adding.
Definition double_array.hpp:46
std::function< void()> done
Called when the building is done.
Definition double_array.hpp:51