3 #include <wordring/compatibility.hpp>
4 #include <wordring/trie/trie.hpp>
12 template <
typename String,
typename Allocator>
27 template <
typename String,
typename Allocator = std::allocator<detail::trie_node>>
30 template <
typename String1,
typename Allocator1>
33 template <
typename String1,
typename Allocator1>
36 template <
typename String1,
typename Allocator1>
42 using typename base_type::container;
43 using typename base_type::index_type;
44 using typename base_type::node_type;
47 using string_type = String;
48 using label_type =
typename string_type::value_type;
50 using base_type::operator bool;
51 using base_type::operator !;
52 using base_type::string;
56 using base_type::m_index;
114 operator std::uint32_t()
const
116 typename base_type::index_type idx = 0;
120 node_type
const* d = m_c->data();
122 idx = (d + m_index)->m_base + base_type::null_value;
123 assert(1 < idx && idx < base_type::limit());
124 assert((d + idx)->m_check == m_index);
150 operator string_type()
const
153 base_type::string(result);
182 string_type&
string(string_type& result)
const
184 if(m_index != 0) base_type::string(result);
206 template <
typename String1,
typename Allocator1>
207 inline bool operator==(basic_atom<String1, Allocator1>
const& lhs, basic_atom<String1, Allocator1>
const& rhs)
209 assert(lhs.m_c == rhs.m_c);
211 return lhs.m_index == rhs.m_index;
230 template <
typename String1,
typename Allocator1>
231 inline bool operator!=(basic_atom<String1, Allocator1>
const& lhs, basic_atom<String1, Allocator1>
const& rhs)
233 assert(lhs.m_c == rhs.m_c);
235 return lhs.m_index != rhs.m_index;
262 template <
typename String,
typename Allocator = std::allocator<detail::trie_node>>
263 class basic_atom_set :
public stable_trie<typename String::value_type>
266 using base_type = stable_trie<typename String::value_type>;
269 using allocator_type = Allocator;
271 using key_type = String;
272 using value_type = detail::basic_atom<key_type>;
273 using label_type =
typename String::value_type;
275 using typename base_type::serialize_iterator;
277 using base_type::get_allocator;
279 using base_type::ibegin;
280 using base_type::iend;
281 using base_type::clear;
284 using base_type::null_value;
342 template <typename InputIterator, typename std::enable_if_t<std::is_integral_v<typename std::iterator_traits<InputIterator>::value_type>, std::nullptr_t> =
nullptr>
343 basic_atom_set(InputIterator first, InputIterator last, allocator_type
const& alloc = allocator_type())
370 template <typename InputIterator, typename std::enable_if_t<std::negation_v<std::is_integral<typename std::iterator_traits<InputIterator>::value_type>>, std::nullptr_t> =
nullptr>
371 basic_atom_set(InputIterator first, InputIterator last, allocator_type
const& alloc = allocator_type())
386 basic_atom_set(std::initializer_list<detail::trie_node> il, allocator_type
const& alloc = allocator_type())
414 template <typename InputIterator, typename std::enable_if_t<std::is_integral_v<typename std::iterator_traits<InputIterator>::value_type>, std::nullptr_t> =
nullptr>
415 void assign(InputIterator first, InputIterator last)
440 template <typename InputIterator, typename std::enable_if_t<std::negation_v<std::is_integral<typename std::iterator_traits<InputIterator>::value_type>>, std::nullptr_t> =
nullptr>
441 void assign(InputIterator first, InputIterator last)
443 while (first != last)
insert(*first++);
474 typename base_type::node_type
const* d = base_type::m_c.data();
476 typename base_type::index_type idx = (d + id)->m_check;
477 assert(1 < idx && idx <
static_cast<int>(base_type::m_c.size()));
478 assert((d + idx)->m_base + base_type::null_value ==
id);
506 template <
typename InputIterator>
535 return at(sv.begin(), sv.end());
560 if (!it) it =
insert(sv.begin(), sv.end());
587 template <
typename InputIterator>
592 typename base_type::index_type idx;
624 return insert(sv.begin(), sv.end());
673 template <
typename InputIterator>
674 void erase(InputIterator first, InputIterator last)
697 void erase(std::basic_string_view<label_type> sv)
699 erase(sv.begin(), sv.end());
711 template <
typename InputIterator>
712 bool contains(InputIterator first, InputIterator last)
const
736 bool contains(std::basic_string_view<label_type> sv)
const
738 return contains(sv.begin(), sv.end());
742 template <
typename Allocator = std::allocator<detail::trie_node>>
743 using u8atom_set = basic_atom_set<std::u8string, Allocator>;
745 template <
typename Allocator = std::allocator<detail::trie_node>>
746 using u16atom_set = basic_atom_set<std::u16string, Allocator>;
748 template <
typename Allocator = std::allocator<detail::trie_node>>
749 using u32atom_set = basic_atom_set<std::u32string, Allocator>;