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,6 +1,13 @@
/// @file dpf/sequence_memoizer.hpp
/// @brief
/// @details
/// @brief Workspaces for a `sequence_recipe` traversal.
/// @details The memoizer stores a reference to the recipe it was built from
/// and later calls must pass that same object (`std::logic_error`
/// otherwise). The factories unwrap `party_key`.
///
/// `inplace_reversing_sequence_memoizer` keeps one level.
/// `double_space_sequence_memoizer` keeps two and is the default
/// inside `eval_sequence(key, recipe, buffer)`.
/// `full_tree_sequence_memoizer` keeps every level.
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
/// @author Christopher Jiang <christopher.jiang@ucalgary.ca>
/// @copyright Copyright (c) 2019-2024 Ryan Henry and [others](@ref authors)
@ -22,6 +29,7 @@
#include <stdexcept>
#include <optional>
#include "dpf/secret_share.hpp"
#include "dpf/sequence_recipe.hpp"
namespace dpf
@ -42,10 +50,13 @@ struct sequence_recipe_memoizer_base : public sequence_memoizer_tag_
// level 0 should access the root
// level goes up to (and including) depth
HEDLEY_NO_THROW
virtual return_type operator[](std::size_t) const noexcept = 0;
// iterators should access most recently completed level
HEDLEY_NO_THROW
virtual return_type begin() const noexcept = 0;
HEDLEY_NO_THROW
virtual return_type end() const noexcept = 0;
virtual std::size_t assign_dpf(const dpf_type & dpf, const sequence_recipe & r)
@ -210,11 +221,13 @@ struct pointer_facade
return *this;
}
HEDLEY_NO_THROW
pointer_facade operator+(std::size_t n) const noexcept
{
return pointer_facade(flip_, it_ + n, rit_ + n);
}
HEDLEY_NO_THROW
pointer_facade & operator-=(std::size_t n) noexcept
{
it_ -= n;
@ -222,11 +235,13 @@ struct pointer_facade
return *this;
}
HEDLEY_NO_THROW
pointer_facade operator-(std::size_t n) const noexcept
{
return pointer_facade(flip_, it_ - n, rit_ - n);
}
HEDLEY_NO_THROW
difference_type operator-(pointer_facade rhs) const noexcept
{
return std::make_pair(it_ - rhs.it_, rit_ - rhs.rit_);
@ -235,7 +250,7 @@ struct pointer_facade
HEDLEY_ALWAYS_INLINE
HEDLEY_NO_THROW
HEDLEY_PURE
reference operator[](std::size_t i)
reference operator[](std::size_t i) noexcept
{
return flip_ ? rit_[i] : it_[i];
}
@ -243,7 +258,7 @@ struct pointer_facade
HEDLEY_ALWAYS_INLINE
HEDLEY_NO_THROW
HEDLEY_PURE
const_reference operator[](std::size_t i) const
const_reference operator[](std::size_t i) const noexcept
{
return flip_ ? rit_[i] : it_[i];
}
@ -270,6 +285,8 @@ struct pointer_facade
} // namespace detail
/// One level. The buffer is traversed in the opposite direction on
/// alternate levels.
template <typename DpfKey,
typename Allocator = aligned_allocator<typename DpfKey::interior_node>>
struct inplace_reversing_sequence_memoizer final
@ -364,6 +381,8 @@ HEDLEY_PRAGMA(GCC diagnostic pop)
unique_ptr buf;
};
/// Two levels, so a level can be built while the previous level is still
/// intact. Default workspace for `eval_sequence` on a recipe.
template <typename DpfKey,
typename Allocator = aligned_allocator<typename DpfKey::interior_node>>
struct double_space_sequence_memoizer final
@ -416,6 +435,7 @@ HEDLEY_PRAGMA(GCC diagnostic pop)
unique_ptr buf;
};
/// Every level of the recipe's traversal.
template <typename DpfKey,
typename Allocator = aligned_allocator<typename DpfKey::interior_node>>
struct full_tree_sequence_memoizer final
@ -482,10 +502,15 @@ auto make_sequence_memoizer(const sequence_recipe & recipe)
HEDLEY_PRAGMA(GCC diagnostic push)
HEDLEY_PRAGMA(GCC diagnostic ignored "-Wignored-attributes")
/// One-level sequence workspace bound to `recipe`.
/// @param recipe The object later passed to `eval_sequence`. The memoizer
/// holds a reference to it.
/// @snippet evaluation/memoizers.cpp sequence-memoizer
template <typename DpfKey>
inline auto make_inplace_reversing_sequence_memoizer(const sequence_recipe & recipe)
{
return detail::make_sequence_memoizer<inplace_reversing_sequence_memoizer<DpfKey>>(recipe);
using key_t = unwrap_party_key_t<DpfKey>;
return detail::make_sequence_memoizer<inplace_reversing_sequence_memoizer<key_t>>(recipe);
}
template <typename DpfKey>
@ -494,10 +519,13 @@ inline auto make_inplace_reversing_sequence_memoizer(const DpfKey &, const seque
return make_inplace_reversing_sequence_memoizer<DpfKey>(recipe);
}
/// Two-level sequence workspace bound to `recipe`.
/// @snippet evaluation/eval_sequence.cpp eval-sequence-recipe
template <typename DpfKey>
inline auto make_double_space_sequence_memoizer(const sequence_recipe & recipe)
{
return detail::make_sequence_memoizer<double_space_sequence_memoizer<DpfKey>>(recipe);
using key_t = unwrap_party_key_t<DpfKey>;
return detail::make_sequence_memoizer<double_space_sequence_memoizer<key_t>>(recipe);
}
template <typename DpfKey>
@ -506,10 +534,12 @@ inline auto make_double_space_sequence_memoizer(const DpfKey &, const sequence_r
return make_double_space_sequence_memoizer<DpfKey>(recipe);
}
/// Full-tree sequence workspace bound to `recipe`.
template <typename DpfKey>
inline auto make_full_tree_sequence_memoizer(const sequence_recipe & recipe)
{
return detail::make_sequence_memoizer<full_tree_sequence_memoizer<DpfKey>>(recipe);
using key_t = unwrap_party_key_t<DpfKey>;
return detail::make_sequence_memoizer<full_tree_sequence_memoizer<key_t>>(recipe);
}
template <typename DpfKey>