tetengo 1.8.2
A multipurpose library set
Loading...
Searching...
No Matches
double_array.hpp
Go to the documentation of this file.
1
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
23
24
25namespace tetengo::trie
26{
27 class storage;
28
29
33 class double_array : private boost::noncopyable
34 {
35 public:
36 // tyes
37
40 {
47 std::function<void(const std::pair<std::string_view, std::int32_t>& element)> adding;
48
52 std::function<void()> done;
53 };
54
55
56 // static functions
57
64
70 [[nodiscard]] static std::size_t default_density_factor();
71
77 [[nodiscard]] static char key_terminator();
78
84 [[nodiscard]] static std::uint8_t vacant_check_value();
85
86
87 // constructors and destructor
88
93
103 explicit double_array(
104 const std::vector<std::pair<std::string_view, std::int32_t>>& elements,
105 const building_observer_set_type& building_observer_set = null_building_observer_set(),
106 std::size_t density_factor = default_density_factor());
107
117 explicit double_array(
118 const std::vector<std::pair<std::string, std::int32_t>>& elements,
119 const building_observer_set_type& building_observer_set = null_building_observer_set(),
120 std::size_t density_factor = default_density_factor());
121
134 template <typename InputIterator>
136 InputIterator first,
137 InputIterator last,
138 const building_observer_set_type& building_observer_set = null_building_observer_set(),
139 std::size_t density_factor = default_density_factor()) :
140 double_array{ std::vector<typename InputIterator::value_type>{ first, last },
141 building_observer_set,
142 density_factor }
143 {}
144
151 double_array(std::unique_ptr<storage>&& p_storage, std::size_t root_base_check_index);
152
157
158
159 // functions
160
168 [[nodiscard]] std::optional<std::int32_t> find(const std::string_view& key) const;
169
175 [[nodiscard]] double_array_iterator begin() const;
176
182 [[nodiscard]] double_array_iterator end() const;
183
192 [[nodiscard]] std::unique_ptr<double_array> subtrie(const std::string_view& key_prefix) const;
193
199 [[nodiscard]] const storage& get_storage() const;
200
206 [[nodiscard]] storage& get_storage();
207
208
209 private:
210 // types
211
212 class impl;
213
214
215 // variables
216
217 const std::unique_ptr<impl> m_p_impl;
218 };
219
220
221}
222
223
224#endif
A double array iterator.
Definition double_array_iterator.hpp:32
A double array.
Definition double_array.hpp:34
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:135
~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 double array iterator.
A trie library.
The building observer set type.
Definition double_array.hpp:40
std::function< void(const std::pair< std::string_view, std::int32_t > &element)> adding
Called when a key is adding.
Definition double_array.hpp:47
std::function< void()> done
Called when the building is done.
Definition double_array.hpp:52