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:
parent
875f09fec1
commit
0d8a5a8131
97 changed files with 9212 additions and 1159 deletions
|
|
@ -26,15 +26,61 @@
|
|||
namespace dpf
|
||||
{
|
||||
|
||||
template <typename Beta>
|
||||
struct ic_pack;
|
||||
|
||||
template <typename T>
|
||||
struct is_ic_pack : std::false_type {};
|
||||
|
||||
template <typename Beta>
|
||||
struct is_ic_pack<ic_pack<Beta>> : std::true_type {};
|
||||
|
||||
template <typename ...Ts>
|
||||
inline constexpr bool no_ic_pack_v =
|
||||
(!is_ic_pack<std::decay_t<Ts>>::value && ...);
|
||||
|
||||
/// Comparison kind for the optional DCF channel on a key.
|
||||
/// `lt`/`leq`/`gt`/`geq` are the comparison predicates. The later kinds are
|
||||
/// path paints: one constant on each sibling subtree of the secret point,
|
||||
/// evaluated by the same value-correction walk.
|
||||
enum class cmp_kind : uint8_t
|
||||
{
|
||||
lt = 0,
|
||||
leq = 1,
|
||||
gt = 2,
|
||||
geq = 3
|
||||
geq = 3,
|
||||
lcp = 4, // common-prefix length
|
||||
prefix = 5, // matched prefix, in the lane's high bits
|
||||
mask = 6, // high-bit mask of that length
|
||||
one_hot = 7, // 2^{length} (0 when the bit does not fit)
|
||||
break_bit = 8, // secret bit at the first difference
|
||||
prefix_with_length = 9, // (low-aligned prefix << length_bits) | length
|
||||
paint = 10 // caller-supplied unit plant
|
||||
};
|
||||
|
||||
/// True for the path-paint kinds. Comparisons stay `lt`/`leq`/`gt`/`geq`.
|
||||
HEDLEY_NO_THROW
|
||||
inline constexpr bool is_paint_kind(cmp_kind kind) noexcept
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case cmp_kind::lcp:
|
||||
case cmp_kind::prefix:
|
||||
case cmp_kind::mask:
|
||||
case cmp_kind::one_hot:
|
||||
case cmp_kind::break_bit:
|
||||
case cmp_kind::prefix_with_length:
|
||||
case cmp_kind::paint:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Unit plant for `path_paint`. `prefix` is the in-lane matched prefix.
|
||||
using paint_callback = uint64_t (*)(std::size_t matched, uint64_t prefix,
|
||||
bool leaf, const void * ctx);
|
||||
|
||||
enum class cmp_trivial : uint8_t
|
||||
{
|
||||
none = 0,
|
||||
|
|
@ -48,6 +94,7 @@ namespace dcf_impl
|
|||
{
|
||||
|
||||
template <typename Beta>
|
||||
HEDLEY_NO_THROW
|
||||
Beta default_false() noexcept
|
||||
{
|
||||
if constexpr (std::is_same_v<Beta, dpf::bit>)
|
||||
|
|
@ -57,6 +104,7 @@ Beta default_false() noexcept
|
|||
}
|
||||
|
||||
template <typename Beta>
|
||||
HEDLEY_NO_THROW
|
||||
uint64_t beta_delta_u64(const Beta & if_true, const Beta & if_false,
|
||||
uint64_t mask) noexcept
|
||||
{
|
||||
|
|
@ -79,6 +127,7 @@ uint64_t beta_delta_u64(const Beta & if_true, const Beta & if_false,
|
|||
}
|
||||
|
||||
template <typename Beta>
|
||||
HEDLEY_NO_THROW
|
||||
uint64_t beta_to_u64_simple(const Beta & beta, uint64_t mask) noexcept
|
||||
{
|
||||
if constexpr (std::is_same_v<Beta, dpf::bit>)
|
||||
|
|
@ -88,6 +137,7 @@ uint64_t beta_to_u64_simple(const Beta & beta, uint64_t mask) noexcept
|
|||
}
|
||||
|
||||
template <typename Beta>
|
||||
HEDLEY_NO_THROW
|
||||
Beta sub_beta(const Beta & a, const Beta & b) noexcept
|
||||
{
|
||||
if constexpr (std::is_same_v<Beta, dpf::bit>)
|
||||
|
|
@ -99,6 +149,7 @@ Beta sub_beta(const Beta & a, const Beta & b) noexcept
|
|||
}
|
||||
|
||||
template <typename Beta>
|
||||
HEDLEY_NO_THROW
|
||||
Beta u64_to_beta(uint64_t v) noexcept
|
||||
{
|
||||
if constexpr (std::is_same_v<Beta, dpf::bit>)
|
||||
|
|
@ -107,7 +158,10 @@ Beta u64_to_beta(uint64_t v) noexcept
|
|||
return static_cast<Beta>(v);
|
||||
}
|
||||
|
||||
inline uint64_t default_mask_for_bits(std::size_t out_bits) noexcept
|
||||
HEDLEY_CONST
|
||||
HEDLEY_NO_THROW
|
||||
HEDLEY_ALWAYS_INLINE
|
||||
constexpr uint64_t default_mask_for_bits(std::size_t out_bits) noexcept
|
||||
{
|
||||
if (out_bits >= 64)
|
||||
return ~0ULL;
|
||||
|
|
@ -116,14 +170,18 @@ inline uint64_t default_mask_for_bits(std::size_t out_bits) noexcept
|
|||
return (1ULL << out_bits) - 1ULL;
|
||||
}
|
||||
|
||||
HEDLEY_CONST
|
||||
HEDLEY_NO_THROW
|
||||
HEDLEY_ALWAYS_INLINE
|
||||
uint64_t neg_m(uint64_t x, uint64_t mask) noexcept
|
||||
constexpr uint64_t neg_m(uint64_t x, uint64_t mask) noexcept
|
||||
{
|
||||
return (0ULL - x) & mask;
|
||||
}
|
||||
|
||||
HEDLEY_CONST
|
||||
HEDLEY_NO_THROW
|
||||
HEDLEY_ALWAYS_INLINE
|
||||
uint64_t sgn_m(uint8_t t1, uint64_t x, uint64_t mask) noexcept
|
||||
constexpr uint64_t sgn_m(uint8_t t1, uint64_t x, uint64_t mask) noexcept
|
||||
{
|
||||
return t1 ? neg_m(x, mask) : x;
|
||||
}
|
||||
|
|
@ -143,6 +201,7 @@ uint64_t convert_node(simde__m128i n, uint64_t mask) noexcept
|
|||
/// same block source so their keys stay byte-identical (matched tapes).
|
||||
template <typename BlockSampler>
|
||||
HEDLEY_ALWAYS_INLINE
|
||||
HEDLEY_NO_THROW
|
||||
uint64_t sample_addend_blind(uint64_t mask, BlockSampler && sample) noexcept
|
||||
{
|
||||
return convert_node(dpf::unset_lo_2bits(sample()), mask);
|
||||
|
|
@ -150,6 +209,7 @@ uint64_t sample_addend_blind(uint64_t mask, BlockSampler && sample) noexcept
|
|||
|
||||
/// One level of value CW on GGM children. Updates running `Va`.
|
||||
/// `ai` is the keep-path bit of the (effective) threshold.
|
||||
HEDLEY_NO_THROW
|
||||
inline uint64_t make_value_cw(simde__m128i c0L, simde__m128i c0R,
|
||||
simde__m128i c1L, simde__m128i c1R, uint8_t t0, uint8_t t1, int ai,
|
||||
uint64_t & Va, uint64_t beta, uint64_t mask) noexcept
|
||||
|
|
@ -179,8 +239,127 @@ inline uint64_t make_value_cw(simde__m128i c0L, simde__m128i c0R,
|
|||
return vcw;
|
||||
}
|
||||
|
||||
/// Same recurrence as `make_value_cw`, planting `plant` on the lose child
|
||||
/// in both directions. `plant == 0` leaves the correction unchanged.
|
||||
HEDLEY_NO_THROW
|
||||
inline uint64_t make_value_cw_planted(simde__m128i c0L, simde__m128i c0R,
|
||||
simde__m128i c1L, simde__m128i c1R, uint8_t t0, uint8_t t1, int ai,
|
||||
uint64_t & Va, uint64_t plant, uint64_t mask) noexcept
|
||||
{
|
||||
(void)t0;
|
||||
uint64_t v0K, v1K, v0Lo, v1Lo;
|
||||
if (ai == 0)
|
||||
{
|
||||
v0K = convert_node(c0L, mask);
|
||||
v1K = convert_node(c1L, mask);
|
||||
v0Lo = convert_node(c0R, mask);
|
||||
v1Lo = convert_node(c1R, mask);
|
||||
}
|
||||
else
|
||||
{
|
||||
v0K = convert_node(c0R, mask);
|
||||
v1K = convert_node(c1R, mask);
|
||||
v0Lo = convert_node(c0L, mask);
|
||||
v1Lo = convert_node(c1L, mask);
|
||||
}
|
||||
uint64_t vcw = sgn_m(t1,
|
||||
(v1Lo + neg_m(v0Lo, mask) + neg_m(Va, mask)) & mask, mask);
|
||||
vcw = (vcw + sgn_m(t1, plant, mask)) & mask;
|
||||
Va = (Va + neg_m(v1K, mask) + v0K + sgn_m(t1, vcw, mask)) & mask;
|
||||
return vcw;
|
||||
}
|
||||
|
||||
HEDLEY_NO_THROW
|
||||
inline unsigned __int128 paint_lane_mask(std::size_t nbits) noexcept
|
||||
{
|
||||
using u128 = unsigned __int128;
|
||||
if (nbits == 0)
|
||||
return 0;
|
||||
if (nbits >= 128)
|
||||
return ~u128{0};
|
||||
return (u128{1} << nbits) - 1;
|
||||
}
|
||||
|
||||
/// High `d` bits of an `nbits`-wide lane, in that lane's own positions.
|
||||
HEDLEY_NO_THROW
|
||||
inline unsigned __int128 paint_high_bits(unsigned __int128 alpha,
|
||||
std::size_t nbits, std::size_t d) noexcept
|
||||
{
|
||||
alpha &= paint_lane_mask(nbits);
|
||||
if (d == 0 || nbits == 0)
|
||||
return 0;
|
||||
if (d >= nbits)
|
||||
return alpha;
|
||||
const std::size_t drop = nbits - d;
|
||||
return (alpha >> drop) << drop;
|
||||
}
|
||||
|
||||
HEDLEY_NO_THROW
|
||||
inline unsigned __int128 paint_low_aligned(unsigned __int128 alpha,
|
||||
std::size_t nbits, std::size_t d) noexcept
|
||||
{
|
||||
alpha &= paint_lane_mask(nbits);
|
||||
if (d == 0 || nbits == 0)
|
||||
return 0;
|
||||
if (d >= nbits)
|
||||
return alpha;
|
||||
return alpha >> (nbits - d);
|
||||
}
|
||||
|
||||
/// Unit (β = 1) lose-subtree or leaf plant. The caller scales by δ.
|
||||
/// `matched` is the number of leading bits already shared with α. A lose
|
||||
/// subtree at that depth reconstructs to this value; `leaf` is the full match.
|
||||
inline uint64_t paint_unit(cmp_kind kind, std::size_t matched,
|
||||
unsigned __int128 alpha, std::size_t nbits, std::size_t length_bits,
|
||||
bool leaf, paint_callback fn, const void * ctx)
|
||||
{
|
||||
if (nbits == 0)
|
||||
return 0;
|
||||
const std::size_t d = leaf ? nbits : matched;
|
||||
switch (kind)
|
||||
{
|
||||
case cmp_kind::lcp:
|
||||
return static_cast<uint64_t>(d);
|
||||
case cmp_kind::prefix:
|
||||
return static_cast<uint64_t>(paint_high_bits(alpha, nbits, d));
|
||||
case cmp_kind::mask:
|
||||
return static_cast<uint64_t>(
|
||||
paint_high_bits(paint_lane_mask(nbits), nbits, d));
|
||||
case cmp_kind::one_hot:
|
||||
return d >= 64 ? 0ULL : (1ULL << d);
|
||||
case cmp_kind::break_bit:
|
||||
if (leaf || matched >= nbits)
|
||||
return 0;
|
||||
return static_cast<uint64_t>(
|
||||
(alpha >> (nbits - 1 - matched)) & 1);
|
||||
case cmp_kind::prefix_with_length:
|
||||
{
|
||||
if (length_bits >= 128)
|
||||
return static_cast<uint64_t>(d);
|
||||
unsigned __int128 packed =
|
||||
paint_low_aligned(alpha, nbits, d) << length_bits;
|
||||
packed |= static_cast<unsigned __int128>(d);
|
||||
return static_cast<uint64_t>(packed);
|
||||
}
|
||||
case cmp_kind::paint:
|
||||
if (fn == nullptr)
|
||||
return 0;
|
||||
return fn(d, static_cast<uint64_t>(paint_high_bits(alpha, nbits, d)),
|
||||
leaf, ctx);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
HEDLEY_NO_THROW
|
||||
inline uint64_t scale_plant(uint64_t unit, uint64_t scale, uint64_t mask) noexcept
|
||||
{
|
||||
return (unit * scale) & mask;
|
||||
}
|
||||
|
||||
/// Final leaf value CW. `on_path` is the payload reconstructed when the query
|
||||
/// stays on α's path through all levels (0 for strict lt/geq; β for leq/gt).
|
||||
HEDLEY_NO_THROW
|
||||
inline uint64_t make_final_cw(simde__m128i s0, simde__m128i s1, uint8_t t1,
|
||||
uint64_t Va, uint64_t mask, uint64_t on_path = 0) noexcept
|
||||
{
|
||||
|
|
@ -206,7 +385,11 @@ struct cmp_meta
|
|||
bool eval_as_ge = false; // invert path-sum (geq / gt)
|
||||
bool include_eq = false; // plant δ on the α-path leaf (leq / gt)
|
||||
bool active = false;
|
||||
bool incremental = false; // final correction saved at every depth
|
||||
int block_width = 0; // 0 = per-level path-sum
|
||||
int tail_bits = 0; // residual q; 0 when the tree covers every bit
|
||||
|
||||
HEDLEY_NO_THROW
|
||||
bool empty() const noexcept { return !active; }
|
||||
};
|
||||
|
||||
|
|
@ -225,6 +408,7 @@ struct cmp_pack
|
|||
static constexpr bool is_cmp = true;
|
||||
static constexpr cmp_kind kind = Kind;
|
||||
static constexpr std::size_t prefix = 0;
|
||||
static constexpr std::size_t block_width = 0;
|
||||
using beta_type = Beta;
|
||||
Beta if_true;
|
||||
Beta if_false;
|
||||
|
|
@ -239,6 +423,7 @@ struct cmp_at_pack
|
|||
static constexpr bool is_cmp = true;
|
||||
static constexpr cmp_kind kind = Kind;
|
||||
static constexpr std::size_t prefix = N;
|
||||
static constexpr std::size_t block_width = 0;
|
||||
using beta_type = Beta;
|
||||
Beta if_true;
|
||||
Beta if_false;
|
||||
|
|
@ -289,6 +474,228 @@ inline auto geq_at(Beta t, Beta f = detail::dcf_impl::default_false<std::decay_t
|
|||
return cmp_at_pack<N, cmp_kind::geq, std::decay_t<Beta>>(std::move(t), std::move(f));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Path paints. Same channel and same (if_true, if_false) scale as a comparison:
|
||||
// the reconstructed value is if_false + (if_true − if_false) · unit(x).
|
||||
// `unit` is the common-prefix length, the matched prefix, a mask, and so on.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct spec_is_incremental : std::false_type {};
|
||||
template <typename T>
|
||||
struct spec_is_incremental<T, std::void_t<decltype(T::incremental)>>
|
||||
: std::bool_constant<T::incremental> {};
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct spec_length_bits : std::integral_constant<std::size_t, 0> {};
|
||||
template <typename T>
|
||||
struct spec_length_bits<T, std::void_t<decltype(T::length_bits)>>
|
||||
: std::integral_constant<std::size_t, T::length_bits> {};
|
||||
|
||||
template <cmp_kind Kind, typename Beta, std::size_t LengthBits = 0>
|
||||
struct paint_pack
|
||||
{
|
||||
static constexpr bool is_cmp = true;
|
||||
static constexpr cmp_kind kind = Kind;
|
||||
static constexpr std::size_t prefix = 0;
|
||||
static constexpr std::size_t block_width = 0;
|
||||
static constexpr std::size_t length_bits = LengthBits;
|
||||
static constexpr bool incremental = false;
|
||||
using beta_type = Beta;
|
||||
Beta if_true;
|
||||
Beta if_false;
|
||||
|
||||
explicit paint_pack(Beta t, Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
: if_true{std::move(t)}, if_false{std::move(f)} { }
|
||||
};
|
||||
|
||||
template <std::size_t N, cmp_kind Kind, typename Beta, std::size_t LengthBits = 0>
|
||||
struct paint_at_pack
|
||||
{
|
||||
static constexpr bool is_cmp = true;
|
||||
static constexpr cmp_kind kind = Kind;
|
||||
static constexpr std::size_t prefix = N;
|
||||
static constexpr std::size_t block_width = 0;
|
||||
static constexpr std::size_t length_bits = LengthBits;
|
||||
static constexpr bool incremental = false;
|
||||
using beta_type = Beta;
|
||||
Beta if_true;
|
||||
Beta if_false;
|
||||
|
||||
explicit paint_at_pack(Beta t, Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
: if_true{std::move(t)}, if_false{std::move(f)} { }
|
||||
};
|
||||
|
||||
template <typename Beta = uint64_t>
|
||||
inline auto lcp(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_pack<cmp_kind::lcp, Beta>(std::move(t), std::move(f));
|
||||
}
|
||||
template <std::size_t N, typename Beta = uint64_t>
|
||||
inline auto lcp_at(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_at_pack<N, cmp_kind::lcp, Beta>(std::move(t), std::move(f));
|
||||
}
|
||||
|
||||
template <typename Beta = uint64_t>
|
||||
inline auto common_prefix(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_pack<cmp_kind::prefix, Beta>(std::move(t), std::move(f));
|
||||
}
|
||||
template <std::size_t N, typename Beta = uint64_t>
|
||||
inline auto common_prefix_at(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_at_pack<N, cmp_kind::prefix, Beta>(std::move(t), std::move(f));
|
||||
}
|
||||
|
||||
template <typename Beta = uint64_t>
|
||||
inline auto prefix_mask(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_pack<cmp_kind::mask, Beta>(std::move(t), std::move(f));
|
||||
}
|
||||
template <std::size_t N, typename Beta = uint64_t>
|
||||
inline auto prefix_mask_at(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_at_pack<N, cmp_kind::mask, Beta>(std::move(t), std::move(f));
|
||||
}
|
||||
|
||||
template <typename Beta = uint64_t>
|
||||
inline auto diverge_one_hot(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_pack<cmp_kind::one_hot, Beta>(std::move(t), std::move(f));
|
||||
}
|
||||
template <std::size_t N, typename Beta = uint64_t>
|
||||
inline auto diverge_one_hot_at(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_at_pack<N, cmp_kind::one_hot, Beta>(std::move(t), std::move(f));
|
||||
}
|
||||
|
||||
template <typename Beta = uint64_t>
|
||||
inline auto break_bit(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_pack<cmp_kind::break_bit, Beta>(std::move(t), std::move(f));
|
||||
}
|
||||
template <std::size_t N, typename Beta = uint64_t>
|
||||
inline auto break_bit_at(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_at_pack<N, cmp_kind::break_bit, Beta>(std::move(t), std::move(f));
|
||||
}
|
||||
|
||||
/// Low `LengthBits` hold the common-prefix length. Above them sits the
|
||||
/// matched prefix packed into the low bits of the lane (`α >> (N − d)`).
|
||||
template <std::size_t LengthBits = 8, typename Beta = uint64_t>
|
||||
inline auto prefix_with_length(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_pack<cmp_kind::prefix_with_length, Beta, LengthBits>(
|
||||
std::move(t), std::move(f));
|
||||
}
|
||||
template <std::size_t N, std::size_t LengthBits = 8, typename Beta = uint64_t>
|
||||
inline auto prefix_with_length_at(Beta t = Beta{1},
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_at_pack<N, cmp_kind::prefix_with_length, Beta, LengthBits>(
|
||||
std::move(t), std::move(f));
|
||||
}
|
||||
|
||||
/// Arbitrary unit plant. `fn(matched, in_lane_prefix, leaf)` returns the β = 1
|
||||
/// value of that sibling subtree (`leaf` is the full match, `matched == N`).
|
||||
/// The result is scaled by `if_true − if_false` like the canned recipes.
|
||||
template <typename Beta, typename Fn>
|
||||
struct paint_fn_pack
|
||||
{
|
||||
static constexpr bool is_cmp = true;
|
||||
static constexpr cmp_kind kind = cmp_kind::paint;
|
||||
static constexpr std::size_t prefix = 0;
|
||||
static constexpr std::size_t block_width = 0;
|
||||
static constexpr std::size_t length_bits = 0;
|
||||
static constexpr bool incremental = false;
|
||||
using beta_type = Beta;
|
||||
Beta if_true;
|
||||
Beta if_false;
|
||||
Fn fn;
|
||||
|
||||
paint_fn_pack(Beta t, Beta f, Fn g)
|
||||
: if_true{std::move(t)}, if_false{std::move(f)}, fn{std::move(g)} { }
|
||||
};
|
||||
|
||||
template <std::size_t N, typename Beta, typename Fn>
|
||||
struct paint_fn_at_pack
|
||||
{
|
||||
static constexpr bool is_cmp = true;
|
||||
static constexpr cmp_kind kind = cmp_kind::paint;
|
||||
static constexpr std::size_t prefix = N;
|
||||
static constexpr std::size_t block_width = 0;
|
||||
static constexpr std::size_t length_bits = 0;
|
||||
static constexpr bool incremental = false;
|
||||
using beta_type = Beta;
|
||||
Beta if_true;
|
||||
Beta if_false;
|
||||
Fn fn;
|
||||
|
||||
paint_fn_at_pack(Beta t, Beta f, Fn g)
|
||||
: if_true{std::move(t)}, if_false{std::move(f)}, fn{std::move(g)} { }
|
||||
};
|
||||
|
||||
template <typename Fn, typename Beta>
|
||||
inline auto path_paint(Fn fn, Beta t,
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_fn_pack<std::decay_t<Beta>, std::decay_t<Fn>>(
|
||||
std::move(t), std::move(f), std::move(fn));
|
||||
}
|
||||
template <typename Fn>
|
||||
inline auto path_paint(Fn fn)
|
||||
{
|
||||
return path_paint(std::move(fn), uint64_t{1});
|
||||
}
|
||||
template <std::size_t N, typename Fn, typename Beta>
|
||||
inline auto path_paint_at(Fn fn, Beta t,
|
||||
Beta f = detail::dcf_impl::default_false<Beta>())
|
||||
{
|
||||
return paint_fn_at_pack<N, std::decay_t<Beta>, std::decay_t<Fn>>(
|
||||
std::move(t), std::move(f), std::move(fn));
|
||||
}
|
||||
|
||||
/// Incremental comparison: the same predicate, correct at every prefix length.
|
||||
/// Evaluate the full point with `cmp`, and a prefix with `cmp_prefix<L>`.
|
||||
template <typename Spec>
|
||||
struct idcf_pack
|
||||
{
|
||||
static constexpr bool is_cmp = true;
|
||||
static constexpr bool incremental = true;
|
||||
static constexpr cmp_kind kind = Spec::kind;
|
||||
static constexpr std::size_t prefix = Spec::prefix;
|
||||
static constexpr std::size_t block_width = Spec::block_width;
|
||||
static constexpr std::size_t length_bits = spec_length_bits<Spec>::value;
|
||||
using beta_type = typename Spec::beta_type;
|
||||
beta_type if_true;
|
||||
beta_type if_false;
|
||||
|
||||
explicit idcf_pack(Spec spec)
|
||||
: if_true{std::move(spec.if_true)}, if_false{std::move(spec.if_false)} { }
|
||||
};
|
||||
|
||||
template <typename Spec>
|
||||
inline auto idcf(Spec spec)
|
||||
{
|
||||
static_assert(is_paint_kind(Spec::kind) == false,
|
||||
"idcf wraps lt/leq/gt/geq; path paints are already one full-domain value");
|
||||
static_assert(Spec::block_width == 0,
|
||||
"idcf uses the per-level path, not blocked checkpoints");
|
||||
return idcf_pack<Spec>{std::move(spec)};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Equality specs: eq / eq_at
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
@ -330,10 +737,54 @@ inline auto eq_at(Beta t, Beta f = detail::dcf_impl::default_false<std::decay_t<
|
|||
return eq_at_pack<N, std::decay_t<Beta>>(std::move(t), std::move(f));
|
||||
}
|
||||
|
||||
template <std::size_t BlockWidth, typename Spec>
|
||||
struct block_width_pack
|
||||
{
|
||||
static_assert(BlockWidth >= 1, "block_width<B> needs B >= 1");
|
||||
static_assert(Spec::block_width == 0, "comparison is already block_width");
|
||||
static constexpr bool is_cmp = true;
|
||||
static constexpr std::size_t block_width = BlockWidth;
|
||||
static constexpr cmp_kind kind = Spec::kind;
|
||||
static constexpr std::size_t prefix = Spec::prefix;
|
||||
static constexpr bool incremental = spec_is_incremental<Spec>::value;
|
||||
static constexpr std::size_t length_bits = spec_length_bits<Spec>::value;
|
||||
using beta_type = typename Spec::beta_type;
|
||||
beta_type if_true;
|
||||
beta_type if_false;
|
||||
|
||||
explicit block_width_pack(Spec spec)
|
||||
: if_true{std::move(spec.if_true)}, if_false{std::move(spec.if_false)} { }
|
||||
};
|
||||
|
||||
template <std::size_t BlockWidth>
|
||||
struct block_width_fn
|
||||
{
|
||||
template <typename Spec>
|
||||
constexpr auto operator()(Spec spec) const
|
||||
{
|
||||
return block_width_pack<BlockWidth, Spec>{std::move(spec)};
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t BlockWidth>
|
||||
inline constexpr block_width_fn<BlockWidth> block_width{};
|
||||
|
||||
template <typename T> struct is_cmp_spec : std::false_type {};
|
||||
template <cmp_kind K, typename B> struct is_cmp_spec<cmp_pack<K, B>> : std::true_type {};
|
||||
template <std::size_t N, cmp_kind K, typename B>
|
||||
struct is_cmp_spec<cmp_at_pack<N, K, B>> : std::true_type {};
|
||||
template <cmp_kind K, typename B, std::size_t L>
|
||||
struct is_cmp_spec<paint_pack<K, B, L>> : std::true_type {};
|
||||
template <std::size_t N, cmp_kind K, typename B, std::size_t L>
|
||||
struct is_cmp_spec<paint_at_pack<N, K, B, L>> : std::true_type {};
|
||||
template <typename B, typename Fn>
|
||||
struct is_cmp_spec<paint_fn_pack<B, Fn>> : std::true_type {};
|
||||
template <std::size_t N, typename B, typename Fn>
|
||||
struct is_cmp_spec<paint_fn_at_pack<N, B, Fn>> : std::true_type {};
|
||||
template <typename Spec>
|
||||
struct is_cmp_spec<idcf_pack<Spec>> : std::true_type {};
|
||||
template <std::size_t B, typename Spec>
|
||||
struct is_cmp_spec<block_width_pack<B, Spec>> : std::true_type {};
|
||||
template <typename T>
|
||||
inline constexpr bool is_cmp_spec_v = is_cmp_spec<T>::value;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue