12namespace hi::inline v1 {
18 static constexpr std::size_t size_mask = (1_uz << size_bit) - 1;
23 _value(
static_cast<uint32_t
>((first << size_bit) | (last - first)))
25 hi_axiom(last >= first);
26 hi_axiom(last - first <= capacity());
34 [[nodiscard]]
static constexpr std::size_t capacity()
noexcept
39 [[nodiscard]]
constexpr std::size_t size()
const noexcept
41 return static_cast<std::size_t>(_value & size_mask);
44 [[nodiscard]]
constexpr bool empty()
const noexcept
49 [[nodiscard]]
constexpr bool full()
const noexcept
51 return size() == capacity();
54 [[nodiscard]]
constexpr std::size_t room()
const noexcept
56 return capacity() - size();
59 [[nodiscard]]
constexpr char32_t begin()
const noexcept
61 return static_cast<char32_t>(_value >> size_bit);
64 [[nodiscard]]
constexpr char32_t end()
const noexcept
66 return begin() +
static_cast<char32_t>(size());
71 return *
this =
unicode_mask_entry{begin(),
static_cast<char32_t>(end() + num_code_points)};
76 return *
this =
unicode_mask_entry{
static_cast<char32_t>(begin() + num_code_points), end()};
79 [[nodiscard]]
constexpr bool contains(
char32_t rhs)
const noexcept
81 return (begin() <= rhs) and (rhs < end());
109 [[nodiscard]]
constexpr std::size_t size()
const noexcept
116 [[nodiscard]]
bool contains(
char32_t c)
const noexcept;
139 void add(
char32_t first,
char32_t last)
noexcept;
146 r._entries.
reserve(lhs._entries.size() * 2 + rhs._entries.size() * 2);
148 auto lhs_it = begin(lhs._entries);
149 auto rhs_it = begin(rhs._entries);
150 hilet lhs_end = end(lhs._entries);
151 hilet rhs_end = end(rhs._entries);
153 while (lhs_it != lhs_end or rhs_it != rhs_end) {
156 (lhs_it == lhs_end) ? rhs_it :
157 (rhs_it == rhs_end) ? lhs_it :
158 (lhs_it->begin() < rhs_it->begin()) ? lhs_it : rhs_it;
161 hilet new_begin = r._entries.empty() ? it->begin() :
std::max(r._entries.back().end(), it->begin());
162 hilet new_end = it->end();
163 if (new_begin < new_end) {
164 r._entries.emplace_back(new_begin, new_end);
165 r._size += new_end - new_begin;
178 return *
this = *
this | rhs;
185 void shrink_to_fit() noexcept;
189 [[nodiscard]]
bool holds_invariant() const noexcept;
192 using
entry_type = detail::unicode_mask_entry;
195 using const_iterator = typename
entries_type::const_iterator;
197 std::
size_t _size = 0;
This file includes required definitions.
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:41
Definition unicode_mask.hpp:15
A mask of unicode code-points.
Definition unicode_mask.hpp:101
bool contains(char32_t c) const noexcept
Check if the given code point is covered by this mask.
bool contains_decomposed(grapheme g) const noexcept
Check if the full grapheme normalized to NFD is covered by this mask.
bool contains(unicode_mask const &other) const noexcept
Check if all the code-points in other are covered by this mask.
bool contains_composed(grapheme g) const noexcept
Check if the full grapheme normalized to NFC is covered by this mask.
void add(char32_t first, char32_t last) noexcept
Add a range of unicode code points to this mask.
friend unicode_mask operator|(unicode_mask const &lhs, unicode_mask const &rhs) noexcept
Combine two masks.
Definition unicode_mask.hpp:143
unicode_mask & operator|=(unicode_mask const &rhs) noexcept
Combine two masks.
Definition unicode_mask.hpp:176
bool contains(grapheme g) const noexcept
Check if the full grapheme is covered by this mask.
void optimize() noexcept
Optimize storage.