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

@ -1,3 +1,11 @@
/// @file dpf/rotation_iterable.hpp
/// @brief A rotated view of an iterator range.
/// @details `begin()` starts `distance` elements into the wrapped range and
/// wraps back to the original begin. Indexing is O(1) when the
/// wrapped iterator is random-access.
/// @copyright Copyright (c) 2019-2026 Ryan Henry and [others](@ref authors)
/// @license Released under a GNU General Public v2.0 (GPLv2) license.
#ifndef LIBDPF_INCLUDE_DPF_ROTATED_VIEW_HPP__
#define LIBDPF_INCLUDE_DPF_ROTATED_VIEW_HPP__
@ -30,20 +38,14 @@ struct rotation_iterable
constexpr rotation_iterable(wrapped_iterator begin, wrapped_iterator end,
difference_type distance)
: size_{std::distance(begin, end)},
distance_{
[this, &distance]()
{
distance %= this->size_;
if (distance < 0)
{
distance += this->size_;
}
return distance;
}()},
begin_{std::next(begin, static_cast<difference_type>(distance_))},
distance_{normalize_distance(distance, size_)},
begin_{size_ == 0 ? begin : std::next(begin, distance_)},
wrap_to_{begin},
wrap_after_{std::next(end, -difference_type(distance_ > 0))},
end_after_{std::next(wrap_to_, static_cast<difference_type>(distance_-1))},
wrap_after_{size_ == 0 || distance_ == 0
? end : std::next(end, difference_type{-1})},
end_after_{size_ == 0 ? begin
: (distance_ == 0 ? std::next(end, difference_type{-1})
: std::next(begin, distance_ - 1))},
end_{end}
{ }
@ -52,11 +54,11 @@ struct rotation_iterable
constexpr rotation_iterable(wrapped_iterator begin, wrapped_iterator end,
wrapped_iterator middle)
: size_{std::distance(begin, end)},
distance_{std::distance(begin, middle)},
distance_{size_ == 0 ? difference_type{0} : std::distance(begin, middle)},
begin_{middle},
wrap_to_{begin},
wrap_after_{std::next(end, difference_type(-1))},
end_after_{std::next(middle, difference_type(-1))},
wrap_after_{size_ == 0 ? end : std::next(end, difference_type{-1})},
end_after_{size_ == 0 ? begin : std::next(middle, difference_type{-1})},
end_{end}
{ }
@ -136,6 +138,19 @@ struct rotation_iterable
}
private:
HEDLEY_CONST
HEDLEY_NO_THROW
static constexpr difference_type normalize_distance(difference_type distance,
difference_type size) noexcept
{
if (size == 0)
return difference_type{0};
distance %= size;
if (distance < 0)
distance += size;
return distance;
}
difference_type size_;
difference_type distance_;
wrapped_iterator begin_;
@ -163,6 +178,7 @@ struct rotation_iterator_base
std::add_const_t<reference>>;
using pointer = typename std::iterator_traits<WrappedIterator>::pointer;
HEDLEY_NO_THROW
rotation_iterator_base(const rotation_iterable<wrapped_iterator> & iterable_,
wrapped_iterator iterator) noexcept
: iterable{iterable_}, it{iterator} { }
@ -256,6 +272,7 @@ struct rotation_iterator final
using wrapped_iterator = WrappedIterator;
using reference = typename base::reference;
HEDLEY_NO_THROW
rotation_iterator(const rotation_iterable<WrappedIterator> & iterable,
wrapped_iterator iterator) noexcept
: base{iterable, iterator} {}
@ -277,6 +294,7 @@ struct rotation_const_iterator final
using wrapped_iterator = WrappedIterator;
using const_reference = typename base::const_reference;
HEDLEY_NO_THROW
rotation_const_iterator(const rotation_iterable<WrappedIterator> & iterable,
wrapped_iterator iterator) noexcept
: base{iterable, iterator} {}