Annotate noexcept and constexpr with HEDLEY, and add interval containment, ChaCha, and the dyadic range tables.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ryan Henry 2026-09-24 20:44:07 -06:00
parent 875f09fec1
commit 0d8a5a8131
97 changed files with 9212 additions and 1159 deletions

View file

@ -43,7 +43,10 @@ class setbit_index_iterable
explicit setbit_index_iterable(iter it) noexcept
: it_{std::move(it)},
begin_{it_.it_.word_ptr_},
end_{begin_ + it_.buf_size_},
// `buf_size_` is a bit count (`bit_array::size()`). The sentinel word
// sits one past the last data word, and the end iterator has to land
// on it rather than `buf_size_` words later.
end_{begin_ + utils::quotient_ceiling(it_.buf_size_, bits_per_word)},
base_index_{calc_base_index(it_)},
length_{calc_length(it_)}
{
@ -89,6 +92,7 @@ class setbit_index_iterable
return it.outputs_ == 0 ? it.from_ : utils::quotient_floor(it.from_, it.outputs_) * it.outputs_;
}
HEDLEY_NO_THROW
static constexpr size_type calc_length(const iter & it) noexcept
{
return it.outputs_ == 0 ? utils::quotient_ceiling(it.to_, bits_per_word) * bits_per_word : utils::quotient_ceiling(it.to_, it.outputs_) * it.outputs_;
@ -102,7 +106,7 @@ class setbit_index_iterable
// while other words just need some bits to be masked out
constexpr void update_bit_array()
{
if (it_.outputs_ == 0)
if (it_.outputs_ == 0 || begin_ == end_)
{
return;
}
@ -124,11 +128,16 @@ class setbit_index_iterable
cur = end_-1;
loc = it_.to_ % it_.outputs_;
while (loc < it_.outputs_ - bits_per_word)
// `outputs_ - bits_per_word` underflows when a leaf is narrower than
// a word, and the loop then walks off the front of the buffer.
if (it_.outputs_ > bits_per_word)
{
*cur = zero;
--cur;
loc += bits_per_word;
while (loc < it_.outputs_ - bits_per_word)
{
*cur = zero;
--cur;
loc += bits_per_word;
}
}
*cur &= mask;
}
@ -151,12 +160,16 @@ class const_setbit_iterator
using difference_type = std::ptrdiff_t;
static constexpr auto bits_per_word = array_type::bits_per_word;
HEDLEY_NO_THROW
HEDLEY_ALWAYS_INLINE
constexpr const_setbit_iterator(const_setbit_iterator &&) noexcept = default;
HEDLEY_NO_THROW
HEDLEY_ALWAYS_INLINE
constexpr const_setbit_iterator(const const_setbit_iterator &) noexcept = default;
HEDLEY_NO_THROW
~const_setbit_iterator() noexcept = default;
HEDLEY_NO_THROW
const_setbit_iterator & operator=(const_setbit_iterator &&) noexcept = default;
const_setbit_iterator & operator=(const const_setbit_iterator &) = default;
@ -279,6 +292,7 @@ class const_setbit_iterator
struct const_iterator_end_tag final {};
struct const_iterator_begin_tag final {};
HEDLEY_NO_THROW
HEDLEY_ALWAYS_INLINE
HEDLEY_NON_NULL()
explicit constexpr const_setbit_iterator(word_pointer word_ptr,
@ -290,6 +304,7 @@ class const_setbit_iterator
seek_to_next_bit();
}
HEDLEY_NO_THROW
HEDLEY_ALWAYS_INLINE
HEDLEY_NON_NULL()
explicit constexpr const_setbit_iterator(word_pointer word_ptr,
@ -303,13 +318,16 @@ class const_setbit_iterator
word_type current_word_;
size_type base_index_;
HEDLEY_NO_THROW
friend const_setbit_iterator setbit_index_iterable<ChildT, WordT>::begin() const noexcept;
HEDLEY_NO_THROW
friend const_setbit_iterator setbit_index_iterable<ChildT, WordT>::end() const noexcept;
}; // class dpf::const_setbit_iterator
template <typename ChildT,
typename WordT>
HEDLEY_ALWAYS_INLINE
HEDLEY_NO_THROW
dpf::setbit_index_iterable<ChildT, WordT> indices_set_in(const subinterval_iterable<bit_iterator<ChildT, WordT>> & iter) noexcept
{
return dpf::setbit_index_iterable<ChildT, WordT>{iter};
@ -318,6 +336,7 @@ dpf::setbit_index_iterable<ChildT, WordT> indices_set_in(const subinterval_itera
template <typename ChildT,
typename WordT>
HEDLEY_ALWAYS_INLINE
HEDLEY_NO_THROW
dpf::setbit_index_iterable<ChildT, WordT> indices_set_in(subinterval_iterable<bit_iterator<ChildT, WordT>> && iter) noexcept
{
return dpf::setbit_index_iterable<ChildT, WordT>{std::forward<subinterval_iterable<bit_iterator<ChildT, WordT>>>(iter)};