64 __host__ __device__
void Gen(Cw cws[],
const int4 s0s[2], In a) {
66 int4 beta = {0, 0, 0, 0};
67 dpf.
Gen(cws, s0s, a, beta);
96 constexpr size_t N = 1ULL << in_bits;
99 ExpandTree(pt.b, s0, cws, pt.p + (N - 1));
102 for (
size_t j = N - 2; j < N - 1; --j) {
103 pt.p[j] = pt.p[2 * j + 1] ^ pt.p[2 * j + 2];
118 constexpr size_t N = 1ULL << in_bits;
119 In e =
static_cast<In
>(x) + 1;
122 if (e == 0 || e == N)
return pt.p[0];
126 for (
int i = 0; i < in_bits; ++i) {
127 bool e_bit = (e >> (in_bits - 1 - i)) & 1;
129 pi ^= pt.p[2 * cur + 1];
152 void EvalAll(
bool b, int4 s0,
const Cw cws[],
bool ys[]) {
153 constexpr size_t N = 1ULL << in_bits;
156 ExpandTree(b, s0, cws, ys);
161 for (
size_t x = 1; x < N; ++x) {
162 ys[x] = ys[x] ^ ys[x - 1];
175 void ExpandTree(
bool b, int4 s0,
const Cw cws[],
bool t[]) {
177 st = util::SetLsb(st, b);
179 assert(in_bits <
sizeof(
size_t) * 8);
181 size_t r = 1ULL << in_bits;
184 int par_depth_ = util::ResolveParDepth(par_depth);
188 ExpandTreeRec(st, cws, t, l, r, i, par_depth_);
192 int4 st,
const Cw cws[],
bool t[],
size_t l,
size_t r,
int i,
int par_depth_) {
193 bool tc = util::GetLsb(st);
195 s = util::SetLsb(s,
false);
205 bool tl_cw = util::GetLsb(s_cw);
206 s_cw = util::SetLsb(s_cw,
false);
209 auto [sl, sr] = prg.Gen(s);
211 bool tl = util::GetLsb(sl);
212 sl = util::SetLsb(sl,
false);
213 bool tr = util::GetLsb(sr);
214 sr = util::SetLsb(sr,
false);
217 sl = util::Xor(sl, s_cw);
218 sr = util::Xor(sr, s_cw);
224 stl = util::SetLsb(stl, tl);
226 str = util::SetLsb(str, tr);
228 size_t mid = (l + r) / 2;
230 if (i < par_depth_) {
232 ExpandTreeRec(stl, cws, t, l, mid, i + 1, par_depth_);
234 ExpandTreeRec(str, cws, t, mid, r, i + 1, par_depth_);
237 ExpandTreeRec(stl, cws, t, l, mid, i + 1, par_depth_);
238 ExpandTreeRec(str, cws, t, mid, r, i + 1, par_depth_);
static bool Eval(const ParityTree &pt, In x)
Prefix-parity query on the parity segment tree.
Definition grotto_dcf.cuh:117
void Preprocess(ParityTree &pt, int4 s0, const Cw cws[])
Preprocess: expand DPF tree and build parity segment tree.
Definition grotto_dcf.cuh:95
void EvalAll(bool b, int4 s0, const Cw cws[], bool ys[])
Full domain evaluation.
Definition grotto_dcf.cuh:152