9 template <
typename Label,
typename Base>
24 template <
typename Label,
typename Base>
27 template <
typename Label1,
typename Base1>
30 template <
typename Label1,
typename Base1>
33 template <
typename Label1,
typename Base1>
37 using base_type = Base;
39 using typename base_type::index_type;
40 using typename base_type::node_type;
41 using typename base_type::container;
43 using unsigned_type = std::make_unsigned_t<Label>;
46 using difference_type = std::ptrdiff_t;
47 using value_type = Label;
48 using pointer = value_type*;
49 using reference = value_type&;
50 using iterator_category = std::input_iterator_tag;
52 static constexpr std::uint16_t null_value = 256u;
53 static std::uint32_t constexpr coefficient =
sizeof(value_type) /
sizeof(
typename base_type::value_type);
55 static_assert(1 <= coefficient);
58 using base_type::operator bool;
59 using base_type::operator!;
62 using base_type::value;
63 using base_type::limit;
64 using base_type::find;
67 using base_type::m_index;
87 value_type operator*()
const
89 assert(1 < m_index && m_index < limit());
91 value_type result = 0;
93 if constexpr (coefficient == 1)
return base_type::value();
96 node_type
const* d = m_c->data();
97 index_type idx = m_index;
99 for (std::uint32_t i = 0; i < coefficient; ++i)
101 index_type
parent = (d + idx)->m_check;
104 index_type base = (d +
parent)->m_base;
105 assert(1 <= base && base < limit());
107 result += (idx - base) << (i * 8);
145 if constexpr (coefficient == 1) idx = base_type::at_index(label);
148 index_type
parent = m_index;
151 node_type
const* d = m_c->data();
152 for (std::uint32_t i = 0; i < coefficient; ++i)
154 std::uint8_t ch =
static_cast<unsigned_type
>(label) >> (coefficient - i - 1) * 8 & 0xFFu;
155 index_type base = (d +
parent)->m_base;
164 if ((d + idx)->m_check !=
parent)
179 if constexpr (coefficient == 1) base_type::advance();
183 std::uint32_t lv = 0;
185 node_type
const* d = m_c->data();
188 for (index_type i = m_index; lv < coefficient; ++lv)
190 index_type
parent = (d + i)->m_check;
191 index_type base = (d +
parent)->m_base;
208 index_type base = (d + idx)->m_base;
220 const_trie_iterator operator++(
int)
251 template <
typename String>
255 for (
auto p = *
this; 1 < p.m_index; p = p.parent()) result.push_back(*p);
256 std::reverse(std::begin(result), std::end(result));
281 index_type idx = m_index;
283 if constexpr (coefficient == 1) idx = base_type::parent_index();
286 for (std::uint32_t lv = 0; lv < coefficient; ++lv)
288 idx = (m_c->data() + idx)->m_check;
289 assert(1 <= idx && idx < limit());
298 index_type idx = m_index;
300 if constexpr (coefficient == 1) idx = base_type::begin_index();
303 std::uint32_t lv = 0;
306 while (lv < coefficient && idx != 0)
308 index_type base = (d + idx)->m_base;
310 ?
find(base, base + null_value, idx)
315 idx = (lv == coefficient)
320 return const_trie_iterator(*m_c, idx);
323 const_trie_iterator
end()
const
325 return const_trie_iterator(*m_c, 0);
329 template <
typename Label1,
typename Base1>
330 inline bool operator==(const_trie_iterator<Label1, Base1>
const& lhs, const_trie_iterator<Label1, Base1>
const& rhs)
332 assert(lhs.m_c == rhs.m_c);
333 return lhs.m_index == rhs.m_index;
336 template <
typename Label1,
typename Base1>
337 inline bool operator!=(const_trie_iterator<Label1, Base1>
const& lhs, const_trie_iterator<Label1, Base1>
const& rhs)
339 return !(lhs == rhs);