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,17 +1,54 @@
#include <cstdint>
#include <iostream>
#include "dpf.hpp"
int main(int arc, char * argv[])
/// One input. `*eval_point` is that party's share of output 0.
/// Reconstruct with `dpf::reconstruct` (leaf outputs are subtractive).
int main()
{
uint16_t x = 42;
auto [dpf0, dpf1] = dpf::make_dpf(x);
const std::uint8_t alpha = 42;
const std::uint64_t beta = 7;
auto [k0, k1] = dpf::make_dpf(alpha, beta);
using key_t = dpf::unwrap_party_key_t<std::decay_t<decltype(k0)>>;
auto res = dpf::eval_point(dpf0, x);
//! [eval-point]
auto y0 = *dpf::eval_point(k0, alpha);
auto y1 = *dpf::eval_point(k1, alpha);
std::uint64_t opened = dpf::reconstruct(y0, y1);
//! [eval-point]
if (opened != beta)
{
std::cerr << "eval_point at the programmed input\n";
return 1;
}
std::cout << *dpf::eval_point(dpf0, 41) << " ^ " << *dpf::eval_point(dpf1, 41) << " = " << (*dpf::eval_point(dpf0, 41) ^ *dpf::eval_point(dpf1, 41)) << "\n"; // = 0
std::cout << *dpf::eval_point(dpf0, x) << " ^ " << *dpf::eval_point(dpf1, x) << " = " << (*dpf::eval_point(dpf0, x) ^ *dpf::eval_point(dpf1, x)) << "\n"; // = 1
std::cout << *dpf::eval_point(dpf0, 43) << " ^ " << *dpf::eval_point(dpf1, 43) << " = " << (*dpf::eval_point(dpf0, 43) ^ *dpf::eval_point(dpf1, 43)) << "\n"; // = 0
auto off0 = *dpf::eval_point(k0, std::uint8_t{41});
auto off1 = *dpf::eval_point(k1, std::uint8_t{41});
if (dpf::reconstruct(off0, off1) != 0)
{
std::cerr << "eval_point off the programmed input\n";
return 1;
}
//! [eval-point-memo]
// One mutable memoizer per key. Nearby points reuse the common prefix.
auto path0 = dpf::make_basic_path_memoizer<key_t>();
auto path1 = dpf::make_basic_path_memoizer<key_t>();
for (int x = 40; x <= 44; ++x)
{
auto s0 = *dpf::eval_point(k0, static_cast<std::uint8_t>(x), path0);
auto s1 = *dpf::eval_point(k1, static_cast<std::uint8_t>(x), path1);
std::uint64_t got = dpf::reconstruct(s0, s1);
std::uint64_t expect = (static_cast<std::uint8_t>(x) == alpha) ? beta : 0;
if (got != expect)
{
std::cerr << "path memoizer\n";
return 1;
}
}
//! [eval-point-memo]
std::cout << opened << "\n";
return 0;
}
}