Store public selector offsets as int32
This commit is contained in:
1 parent
c8e49aead8
commit
24f28dd9c8
10 files changed
+236
-216
No files matched your search
+8
-9
@@ -35,15 +35,14 @@ them in place. `ConflictRange` returns owned `std::string`s because the decision
|
||||
procedure can synthesise endpoints (`keyAfter`, clamp bounds) that are not
|
||||
present in the input.
|
||||
|
||||
Caller-supplied selector offsets must fit in `std::int32_t`. Internally they are
|
||||
stored as `Int = std::int64_t`, because the closed form also builds derived
|
||||
selectors whose offsets (for example `end.offset - residualT`) need not fit in
|
||||
32 bits. All intermediate `Int` arithmetic assumes 64-bit signed integers do not
|
||||
overflow; with 32-bit input offsets and in-memory key counts that is far from
|
||||
the limit. The corpus parsers reject offsets outside the 32-bit input range, and
|
||||
both public `closedForm` entry points assert the same contract in debug builds.
|
||||
The assertion lives at the API boundary rather than in `Selector`, because
|
||||
derived selectors legitimately exceed the input range.
|
||||
Selector offsets are `std::int32_t`, matching the caller contract. The closed
|
||||
form converts the public `RangeRead` to `detail::RangeRead`, whose offsets are
|
||||
`Int = std::int64_t`, before deriving selectors (for example
|
||||
`end.offset - residualT`). All intermediate `Int` arithmetic assumes 64-bit
|
||||
signed integers do not overflow; with 32-bit input offsets and in-memory key
|
||||
counts that is far from the limit. The corpus parsers read offsets into a wider
|
||||
integer and reject values outside the 32-bit range before narrowing to
|
||||
`Selector`.
|
||||
|
||||
## Scope of the two implementations
|
||||
|
||||
|
||||
+19
-18
@@ -20,6 +20,8 @@
|
||||
namespace cr::fast {
|
||||
namespace {
|
||||
|
||||
using WideRead = detail::RangeRead;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Observational summary
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -46,7 +48,7 @@ struct Obs {
|
||||
// Facts that only depend on the read and on the *multiset* of reported keys.
|
||||
// They are therefore invariant under reversing the view.
|
||||
struct Ctx {
|
||||
const RangeRead* r = nullptr;
|
||||
const WideRead* r = nullptr;
|
||||
std::size_t n = 0;
|
||||
std::size_t below = 0; // number of reported keys < begin.key
|
||||
std::size_t t = 0; // number of reported keys >= end.key
|
||||
@@ -105,7 +107,7 @@ std::size_t countLess(std::span<const KeyView> ks, OptKeyView x,
|
||||
return n - lo;
|
||||
}
|
||||
|
||||
Ctx makeCtx(const RangeRead& r, const Obs& o) {
|
||||
Ctx makeCtx(const WideRead& r, const Obs& o) {
|
||||
Ctx c;
|
||||
c.r = &r;
|
||||
c.n = o.n;
|
||||
@@ -322,7 +324,7 @@ struct Impl {
|
||||
ConflictRange closedFormNegCrossCompleteResidual(const Ctx& c, const Obs& o) const {
|
||||
// Keep the synthesised end key alive while `rp` borrows it.
|
||||
OptKey reducedEnd = after(o.lastK());
|
||||
RangeRead rp = *c.r;
|
||||
WideRead rp = *c.r;
|
||||
rp.end_.key = optView(reducedEnd);
|
||||
rp.end_.offset = rp.end_.offset - static_cast<Int>(c.t);
|
||||
Ctx cp = makeCtx(rp, o);
|
||||
@@ -463,15 +465,15 @@ struct Impl {
|
||||
return mk(crossedBegin(c), topKey());
|
||||
}
|
||||
|
||||
RangeRead zeroBeginAnchor(const Ctx& c, const Obs& o) const {
|
||||
RangeRead out = *c.r;
|
||||
WideRead zeroBeginAnchor(const Ctx& c, const Obs& o) const {
|
||||
WideRead out = *c.r;
|
||||
out.begin.key = asKey(o.firstK());
|
||||
out.begin.offset = 1;
|
||||
return out;
|
||||
}
|
||||
|
||||
ConflictRange zeroCrossLongAnchor(const Ctx& c, const Obs& o) const {
|
||||
RangeRead a = zeroBeginAnchor(c, o);
|
||||
WideRead a = zeroBeginAnchor(c, o);
|
||||
Ctx ca = makeCtx(a, o);
|
||||
if (oLtK(c.r->end_.key, o.firstK()))
|
||||
return completeForwardCrossedGeneral(ca, o);
|
||||
@@ -493,7 +495,7 @@ struct Impl {
|
||||
}
|
||||
|
||||
ConflictRange closedFormZeroCrossUnderEnd(const Ctx& c, const Obs& o) const {
|
||||
RangeRead a = zeroBeginAnchor(c, o);
|
||||
WideRead a = zeroBeginAnchor(c, o);
|
||||
Ctx ca = makeCtx(a, o);
|
||||
return closedFormOffsetOne(ca, o);
|
||||
}
|
||||
@@ -511,7 +513,7 @@ struct Impl {
|
||||
}
|
||||
|
||||
ConflictRange closedFormZeroCrossCompleteRev(const Ctx& c, const Obs& o) const {
|
||||
RangeRead r2 = *c.r;
|
||||
WideRead r2 = *c.r;
|
||||
r2.reverse = false;
|
||||
Obs o2 = o;
|
||||
o2.reversed = true;
|
||||
@@ -538,7 +540,7 @@ struct Impl {
|
||||
|
||||
// ----- empty result ------------------------------------------------------
|
||||
|
||||
bool AlwaysEmpty(const RangeRead& r) const {
|
||||
bool AlwaysEmpty(const WideRead& r) const {
|
||||
NatInf gap = intervalCard(r.begin.key, r.end_.key);
|
||||
std::uint64_t b = noPinB(gap, r.begin.offset, r.end_.offset);
|
||||
std::uint64_t e = cELo(r.begin.offset, r.end_.offset);
|
||||
@@ -568,18 +570,18 @@ struct Impl {
|
||||
return !inner;
|
||||
}
|
||||
|
||||
ConflictRange emptyRange(const RangeRead& r) const {
|
||||
ConflictRange emptyRange(const WideRead& r) const {
|
||||
return mk(r.begin.key, r.begin.key);
|
||||
}
|
||||
|
||||
ConflictRange crossedRangeGeneral(const RangeRead& r) const {
|
||||
ConflictRange crossedRangeGeneral(const WideRead& r) const {
|
||||
NatInf diff = niSub(NatInf::of(residualE(r)), NatInf::of(residualB(r)));
|
||||
if (niLe(diff, intervalCard(r.end_.key, r.begin.key)))
|
||||
return mk(r.end_.key, topKey());
|
||||
return mk(r.begin.key, topKey());
|
||||
}
|
||||
|
||||
ConflictRange emptyValue(const RangeRead& r) const {
|
||||
ConflictRange emptyValue(const WideRead& r) const {
|
||||
if (AlwaysEmpty(r)) return emptyRange(r);
|
||||
if (r.begin.offset <= 0) {
|
||||
if (r.end_.offset >= 2) return mk(bottomKey(), topKey());
|
||||
@@ -593,7 +595,7 @@ struct Impl {
|
||||
return crossedRangeGeneral(r);
|
||||
}
|
||||
|
||||
ConflictRange topRange(const RangeRead& r) const {
|
||||
ConflictRange topRange(const WideRead& r) const {
|
||||
return mk(r.begin.key, topKey());
|
||||
}
|
||||
|
||||
@@ -624,7 +626,7 @@ struct Impl {
|
||||
|
||||
ConflictRange closedFormComplete(const Ctx& c, const Obs& o) const {
|
||||
if (!c.r->reverse) return closedFormCompleteForward(c, o);
|
||||
RangeRead r2 = *c.r;
|
||||
WideRead r2 = *c.r;
|
||||
r2.reverse = false;
|
||||
Obs o2 = o;
|
||||
o2.reversed = true;
|
||||
@@ -886,7 +888,7 @@ struct Impl {
|
||||
ConflictRange closedFormCrossed(const Ctx& c, const Obs& o) const {
|
||||
if (!o.more) {
|
||||
if (!c.r->reverse) return closedFormCrossedComplete(c, o);
|
||||
RangeRead r2 = *c.r;
|
||||
WideRead r2 = *c.r;
|
||||
r2.reverse = false;
|
||||
Obs o2 = o;
|
||||
o2.reversed = true;
|
||||
@@ -912,7 +914,7 @@ struct Impl {
|
||||
|
||||
// ----- entry point ------------------------------------------------------
|
||||
|
||||
ConflictRange closedForm(const RangeRead& r, const Result& res) const {
|
||||
ConflictRange closedForm(const WideRead& r, const Result& res) const {
|
||||
if (res.keys.empty()) return emptyValue(r);
|
||||
Obs o;
|
||||
o.keys = res.keys;
|
||||
@@ -930,8 +932,7 @@ struct Impl {
|
||||
} // namespace
|
||||
|
||||
ConflictRange closedForm(const RangeRead& r, const Result& res) {
|
||||
assertInputOffsetsFitInt32(r);
|
||||
return Impl{}.closedForm(r, res);
|
||||
return Impl{}.closedForm(detail::widen(r), res);
|
||||
}
|
||||
|
||||
} // namespace cr::fast
|
||||
+132
-131
@@ -12,10 +12,11 @@
|
||||
namespace cr::literal {
|
||||
namespace {
|
||||
|
||||
using WideRead = cr::detail::RangeRead;
|
||||
|
||||
using cr::afterFirst;
|
||||
using cr::afterLast;
|
||||
using cr::asKey;
|
||||
using cr::assertInputOffsetsFitInt32;
|
||||
using cr::beginSlack;
|
||||
using cr::bottomKey;
|
||||
using cr::clampNonposD;
|
||||
@@ -59,13 +60,13 @@ ConflictRange mkRange(B&& b, E&& e) {
|
||||
// Arithmetic helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
NatInf clampCap(const RangeRead& r) { return intervalCard(r.end_.key, r.begin.key); }
|
||||
NatInf clampCap(const WideRead& r) { return intervalCard(r.end_.key, r.begin.key); }
|
||||
|
||||
std::uint64_t clampSlack(const RangeRead& r, const Result& res) {
|
||||
std::uint64_t clampSlack(const WideRead& r, const Result& res) {
|
||||
return natSub(beginSlack(r) + 1, reportedBelowBegin(r, res));
|
||||
}
|
||||
|
||||
OptKey clampEndOneUpper(const RangeRead& r, const Result& res) {
|
||||
OptKey clampEndOneUpper(const WideRead& r, const Result& res) {
|
||||
NatInf slack = NatInf::of(clampSlack(r, res));
|
||||
NatInf cap = clampCap(r);
|
||||
if (niLe(slack, cap) && (niLt(slack, cap) || first(res) != bottomKeyView()))
|
||||
@@ -73,25 +74,25 @@ OptKey clampEndOneUpper(const RangeRead& r, const Result& res) {
|
||||
return ownKey(r.end_.key);
|
||||
}
|
||||
|
||||
NatInf clampHighCap(const RangeRead& r, const Result& res) {
|
||||
NatInf clampHighCap(const WideRead& r, const Result& res) {
|
||||
return intervalCard(afterLast(res), r.begin.key);
|
||||
}
|
||||
|
||||
std::uint64_t clampHighThresh(const RangeRead& r, const Result& res) {
|
||||
std::uint64_t clampHighThresh(const WideRead& r, const Result& res) {
|
||||
return clampSlack(r, res) + (isBottom(r.end_.key) ? 1 : 0);
|
||||
}
|
||||
|
||||
OptKey clampHighU(const RangeRead& r, const Result& res) {
|
||||
OptKey clampHighU(const WideRead& r, const Result& res) {
|
||||
if (niLe(NatInf::of(clampHighThresh(r, res)), clampHighCap(r, res)))
|
||||
return ownKey(r.begin.key);
|
||||
return afterLast(res);
|
||||
}
|
||||
|
||||
std::uint64_t clampLongC(const RangeRead& r, const Result& res) {
|
||||
std::uint64_t clampLongC(const WideRead& r, const Result& res) {
|
||||
return natSub(natSub(beginSlack(r), reportedBelowBegin(r, res)), clampNonposD(r));
|
||||
}
|
||||
|
||||
OptKey clampLongUpper(const RangeRead& r, const Result& res) {
|
||||
OptKey clampLongUpper(const WideRead& r, const Result& res) {
|
||||
NatInf cap = clampCap(r);
|
||||
NatInf c = NatInf::of(clampLongC(r, res));
|
||||
if (niLt(cap, c) || (niEq(cap, c) && first(res) == bottomKeyView()))
|
||||
@@ -99,19 +100,19 @@ OptKey clampLongUpper(const RangeRead& r, const Result& res) {
|
||||
return ownKey(r.begin.key);
|
||||
}
|
||||
|
||||
bool clampNonposBottom(const RangeRead& r, const Result& res) {
|
||||
bool clampNonposBottom(const WideRead& r, const Result& res) {
|
||||
NatInf lhs = niAdd(NatInf::of(reportedBelowBegin(r, res)),
|
||||
niSub(NatInf::of(clampNonposD(r) + 1),
|
||||
intervalCard(r.begin.key, r.end_.key)));
|
||||
return niLe(lhs, NatInf::of(beginSlack(r)));
|
||||
}
|
||||
|
||||
bool clampedNonpos(const RangeRead& r, const Result& res) {
|
||||
bool clampedNonpos(const WideRead& r, const Result& res) {
|
||||
return r.begin.offset <= 0 &&
|
||||
optLe(r.begin.key, leastReportedOpt(r, res));
|
||||
}
|
||||
|
||||
bool clampsToBottom(const RangeRead& r, const Result& res) {
|
||||
bool clampsToBottom(const WideRead& r, const Result& res) {
|
||||
return r.begin.offset <= 0 && optLe(r.begin.key, first(res));
|
||||
}
|
||||
|
||||
@@ -129,36 +130,36 @@ std::uint64_t noPinB(NatInf KBE, Int oB, Int oE) {
|
||||
return lo > KBE.n ? lo - KBE.n : 0;
|
||||
}
|
||||
|
||||
std::uint64_t residualD(const RangeRead& r, NatInf g) {
|
||||
std::uint64_t residualD(const WideRead& r, NatInf g) {
|
||||
if (g.inf) return 0;
|
||||
return natSub(residualB(r), g.n);
|
||||
}
|
||||
|
||||
std::uint64_t closedFormDeficit(const RangeRead& r) {
|
||||
std::uint64_t closedFormDeficit(const WideRead& r) {
|
||||
return residualD(r, intervalCard(r.begin.key, r.end_.key));
|
||||
}
|
||||
|
||||
bool allBelowEnd(const RangeRead& r, const Result& res) {
|
||||
bool allBelowEnd(const WideRead& r, const Result& res) {
|
||||
for (KeyView k : res.keys)
|
||||
if (!optLt(asKey(k), r.end_.key)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool anyAtOrAboveEnd(const RangeRead& r, const Result& res) {
|
||||
bool anyAtOrAboveEnd(const WideRead& r, const Result& res) {
|
||||
for (KeyView k : res.keys)
|
||||
if (optLe(r.end_.key, asKey(k))) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::uint64_t gapOvershoot(const RangeRead& r, const Result& res) {
|
||||
std::uint64_t gapOvershoot(const WideRead& r, const Result& res) {
|
||||
return natSub(residualE(r), residualT(r, res));
|
||||
}
|
||||
|
||||
std::uint64_t crossedOvershootGeneral(const RangeRead& r, const Result& res) {
|
||||
std::uint64_t crossedOvershootGeneral(const WideRead& r, const Result& res) {
|
||||
return natSub(natSub(residualE(r), residualT(r, res)), residualB(r));
|
||||
}
|
||||
|
||||
OptKeyView crossedBegin(const RangeRead& r, const Result& res) {
|
||||
OptKeyView crossedBegin(const WideRead& r, const Result& res) {
|
||||
if (niLe(NatInf::of(crossedOvershootGeneral(r, res)),
|
||||
intervalCard(r.end_.key, r.begin.key)))
|
||||
return r.end_.key;
|
||||
@@ -169,39 +170,39 @@ OptKeyView crossedBegin(const RangeRead& r, const Result& res) {
|
||||
// Crossed complete cases
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
bool negCrossClampEndOne(const RangeRead& r, const Result& res) {
|
||||
bool negCrossClampEndOne(const WideRead& r, const Result& res) {
|
||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||
r.end_.offset == 1 && optLt(first(res), r.begin.key) &&
|
||||
reportedBelowBegin(r, res) <= beginSlack(r);
|
||||
}
|
||||
|
||||
bool negCrossHeadBottom(const RangeRead& r, const Result& res) {
|
||||
bool negCrossHeadBottom(const WideRead& r, const Result& res) {
|
||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||
r.end_.offset <= 0 && optLe(r.begin.key, r.end_.key) &&
|
||||
first(res) == bottomKeyView();
|
||||
}
|
||||
|
||||
bool negCrossClampNonposLastGe(const RangeRead& r, const Result& res) {
|
||||
bool negCrossClampNonposLastGe(const WideRead& r, const Result& res) {
|
||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||
r.end_.offset <= 0 && optLt(first(res), r.begin.key) &&
|
||||
optLe(r.begin.key, last(res)) &&
|
||||
reportedBelowBegin(r, res) <= beginSlack(r);
|
||||
}
|
||||
|
||||
bool negCrossClampNonposBottom(const RangeRead& r, const Result& res) {
|
||||
bool negCrossClampNonposBottom(const WideRead& r, const Result& res) {
|
||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||
r.end_.offset <= 0 && optLe(r.begin.key, r.end_.key) &&
|
||||
optLt(first(res), r.begin.key) && clampNonposBottom(r, res);
|
||||
}
|
||||
|
||||
bool negCrossClampLongNonpos(const RangeRead& r, const Result& res) {
|
||||
bool negCrossClampLongNonpos(const WideRead& r, const Result& res) {
|
||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||
r.end_.offset <= 0 && optLt(first(res), r.begin.key) &&
|
||||
reportedBelowBegin(r, res) <= beginSlack(r) &&
|
||||
clampNonposBottom(r, res) && optLt(r.end_.key, r.begin.key);
|
||||
}
|
||||
|
||||
ConflictRange closedFormNegCrossClampUnified(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormNegCrossClampUnified(const WideRead& r, const Result& res) {
|
||||
OptKey end;
|
||||
if (negCrossClampEndOne(r, res))
|
||||
end = clampEndOneUpper(r, res);
|
||||
@@ -213,31 +214,31 @@ ConflictRange closedFormNegCrossClampUnified(const RangeRead& r, const Result& r
|
||||
return mkRange(bottomKey(), std::move(end));
|
||||
}
|
||||
|
||||
OptKey negCrossCompleteHighM(const RangeRead& r, const Result& res) {
|
||||
OptKey negCrossCompleteHighM(const WideRead& r, const Result& res) {
|
||||
return optMax(r.begin.key, afterLast(res));
|
||||
}
|
||||
|
||||
std::uint64_t negCrossHighD(const RangeRead& r, const Result& res) {
|
||||
std::uint64_t negCrossHighD(const WideRead& r, const Result& res) {
|
||||
return natSub(residualE(r), res.keys.size());
|
||||
}
|
||||
|
||||
NatInf negCrossHighGapCap(const RangeRead& r, const Result& res) {
|
||||
NatInf negCrossHighGapCap(const WideRead& r, const Result& res) {
|
||||
return intervalCard(r.end_.key, first(res));
|
||||
}
|
||||
|
||||
bool negCrossHighUsesEnd(const RangeRead& r, const Result& res) {
|
||||
bool negCrossHighUsesEnd(const WideRead& r, const Result& res) {
|
||||
NatInf d = NatInf::of(negCrossHighD(r, res));
|
||||
NatInf gap = negCrossHighGapCap(r, res);
|
||||
return niLt(d, gap) || (niLe(d, gap) && optLt(r.begin.key, topKey()));
|
||||
}
|
||||
|
||||
bool negCrossCompleteHigh(const RangeRead& r, const Result& res) {
|
||||
bool negCrossCompleteHigh(const WideRead& r, const Result& res) {
|
||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||
r.end_.offset >= 2 && optLt(first(res), r.begin.key) &&
|
||||
optLt(r.end_.key, first(res));
|
||||
}
|
||||
|
||||
ConflictRange closedFormNegCrossCompleteHigh(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormNegCrossCompleteHigh(const WideRead& r, const Result& res) {
|
||||
if (reportedBelowBegin(r, res) <= beginSlack(r)) {
|
||||
if (res.keys.size() == residualE(r)) return mkRange(bottomKey(), clampHighU(r, res));
|
||||
return mkRange(bottomKey(), topKey());
|
||||
@@ -250,23 +251,23 @@ ConflictRange closedFormNegCrossCompleteHigh(const RangeRead& r, const Result& r
|
||||
|
||||
ConflictRange topOfLast(KeyView k) { return mkRange(asKey(k), topKey()); }
|
||||
|
||||
ConflictRange closedFormNegCrossOvershoot(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormNegCrossOvershoot(const WideRead& r, const Result& res) {
|
||||
if (reportedBelowBegin(r, res) <= beginSlack(r))
|
||||
return mkRange(bottomKey(), topKey());
|
||||
return topOfLast(firstKey(res));
|
||||
}
|
||||
|
||||
ConflictRange closedFormNegCrossEndOne(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormNegCrossEndOne(const WideRead& r, const Result& res) {
|
||||
return mkRange(first(res), r.end_.key);
|
||||
}
|
||||
|
||||
ConflictRange closedFormNegCrossEndOneLong(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormNegCrossEndOneLong(const WideRead& r, const Result& res) {
|
||||
return mkRange(first(res), r.begin.key);
|
||||
}
|
||||
|
||||
ConflictRange closedFormNegCrossCompleteResidual(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormNegCrossCompleteResidual(const WideRead& r, const Result& res) {
|
||||
OptKey reducedEnd = afterLast(res);
|
||||
RangeRead rp = r;
|
||||
WideRead rp = r;
|
||||
rp.end_.key = optView(reducedEnd);
|
||||
rp.end_.offset = r.end_.offset - static_cast<Int>(residualT(r, res));
|
||||
if (rp.end_.offset >= 2)
|
||||
@@ -278,17 +279,17 @@ ConflictRange closedFormNegCrossCompleteResidual(const RangeRead& r, const Resul
|
||||
return closedFormNegCrossEndOneLong(rp, res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormNegCrossCompleteHighResidual(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormNegCrossCompleteHighResidual(const WideRead& r, const Result& res) {
|
||||
if (negCrossCompleteHigh(r, res))
|
||||
return closedFormNegCrossCompleteHigh(r, res);
|
||||
return closedFormNegCrossCompleteResidual(r, res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormNegCrossNonclampUnified(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormNegCrossNonclampUnified(const WideRead& r, const Result& res) {
|
||||
return mkRange(first(res), optMax(r.end_.key, r.begin.key));
|
||||
}
|
||||
|
||||
ConflictRange closedFormNegCrossTopUnified(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormNegCrossTopUnified(const WideRead& r, const Result& res) {
|
||||
OptKeyView begin = reportedBelowBegin(r, res) <= beginSlack(r)
|
||||
? bottomKeyView()
|
||||
: leastReportedOpt(r, res);
|
||||
@@ -299,7 +300,7 @@ ConflictRange closedFormNegCrossTopUnified(const RangeRead& r, const Result& res
|
||||
// Crossed truncated cases
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
bool negCrossTruncNonposGap(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncNonposGap(const WideRead& r, const Result& res) {
|
||||
return res.more && !r.reverse && r.begin.offset < 0 &&
|
||||
optLt(leastReportedOpt(r, res), r.begin.key) &&
|
||||
r.end_.offset <= 0 &&
|
||||
@@ -312,12 +313,12 @@ bool negCrossTruncNonposGap(const RangeRead& r, const Result& res) {
|
||||
NatInf::of(clampNonposD(r) + 1)));
|
||||
}
|
||||
|
||||
bool negCrossTruncNonposGapA2aBottom(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncNonposGapA2aBottom(const WideRead& r, const Result& res) {
|
||||
return negCrossTruncNonposGap(r, res) && optLt(r.end_.key, r.begin.key) &&
|
||||
clampNonposBottom(r, res);
|
||||
}
|
||||
|
||||
bool negCrossTruncNonposGapA2aBottomHigh(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncNonposGapA2aBottomHigh(const WideRead& r, const Result& res) {
|
||||
std::uint64_t extra = isBottom(first(res)) ? 1 : 0;
|
||||
NatInf lhs = NatInf::of(beginSlack(r) + 1 + extra);
|
||||
NatInf rhs = niAdd(NatInf::of(res.keys.size()),
|
||||
@@ -325,26 +326,26 @@ bool negCrossTruncNonposGapA2aBottomHigh(const RangeRead& r, const Result& res)
|
||||
return negCrossTruncNonposGapA2aBottom(r, res) && niLe(lhs, rhs);
|
||||
}
|
||||
|
||||
ConflictRange closedFormNegCrossTruncNonposGapA2aBottom(const RangeRead& r,
|
||||
ConflictRange closedFormNegCrossTruncNonposGapA2aBottom(const WideRead& r,
|
||||
const Result& res) {
|
||||
if (negCrossTruncNonposGapA2aBottomHigh(r, res))
|
||||
return mkRange(bottomKey(), r.begin.key);
|
||||
return mkRange(bottomKey(), r.end_.key);
|
||||
}
|
||||
|
||||
bool finiteUnderCond(const RangeRead& r, const Result& res) {
|
||||
bool finiteUnderCond(const WideRead& r, const Result& res) {
|
||||
NatInf lhs = niAdd(NatInf::of(natSub(reportedBelowBegin(r, res), 1)),
|
||||
intervalCard(afterFirst(res), r.begin.key));
|
||||
return niLe(lhs, NatInf::of(beginSlack(r)));
|
||||
}
|
||||
|
||||
bool negCrossTruncRevResidualFiniteOver(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncRevResidualFiniteOver(const WideRead& r, const Result& res) {
|
||||
return res.more && r.reverse && r.begin.offset < 0 && r.end_.offset >= 2 &&
|
||||
optLt(r.end_.key, last(res)) && optLt(last(res), r.begin.key) &&
|
||||
residualT(r, res) == residualE(r);
|
||||
}
|
||||
|
||||
ConflictRange closedFormNegCrossTruncRevResidualFiniteUnified(const RangeRead& r,
|
||||
ConflictRange closedFormNegCrossTruncRevResidualFiniteUnified(const WideRead& r,
|
||||
const Result& res) {
|
||||
OptKeyView L = last(res);
|
||||
OptKey U = finiteUnderCond(r, res) ? afterFirst(res) : ownKey(r.begin.key);
|
||||
@@ -353,7 +354,7 @@ ConflictRange closedFormNegCrossTruncRevResidualFiniteUnified(const RangeRead& r
|
||||
return mkRange(std::move(L), std::move(U));
|
||||
}
|
||||
|
||||
bool sentinelLargeTight(const RangeRead& r, const Result& res) {
|
||||
bool sentinelLargeTight(const WideRead& r, const Result& res) {
|
||||
NatInf lhs = NatInf::of(residualE(r));
|
||||
NatInf rhs = niAdd(intervalCard(r.end_.key, last(res)),
|
||||
NatInf::of(res.keys.size()));
|
||||
@@ -361,7 +362,7 @@ bool sentinelLargeTight(const RangeRead& r, const Result& res) {
|
||||
return niEq(lhs, rhs) && nPlusBegin == 1;
|
||||
}
|
||||
|
||||
bool negCrossTruncRevResidualTopLarge(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncRevResidualTopLarge(const WideRead& r, const Result& res) {
|
||||
if (!(res.more && r.reverse && r.begin.offset < 0 && r.end_.offset >= 2 &&
|
||||
optLt(r.end_.key, last(res)) && residualT(r, res) < residualE(r)))
|
||||
return false;
|
||||
@@ -371,11 +372,11 @@ bool negCrossTruncRevResidualTopLarge(const RangeRead& r, const Result& res) {
|
||||
return niLe(lhs, rhs);
|
||||
}
|
||||
|
||||
bool negCrossTruncRevResidualTopLargeSentinel(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncRevResidualTopLargeSentinel(const WideRead& r, const Result& res) {
|
||||
return negCrossTruncRevResidualTopLarge(r, res) && isTop(r.begin.key);
|
||||
}
|
||||
|
||||
ConflictRange closedFormNegCrossTruncRevResidualTopLargeUnified(const RangeRead& r,
|
||||
ConflictRange closedFormNegCrossTruncRevResidualTopLargeUnified(const WideRead& r,
|
||||
const Result& res) {
|
||||
OptKeyView L = last(res);
|
||||
if (negCrossTruncRevResidualTopLargeSentinel(r, res) &&
|
||||
@@ -384,7 +385,7 @@ ConflictRange closedFormNegCrossTruncRevResidualTopLargeUnified(const RangeRead&
|
||||
return mkRange(r.end_.key, topKey());
|
||||
}
|
||||
|
||||
ConflictRange truncatedRangeRev(const RangeRead& r, KeyView lastReported) {
|
||||
ConflictRange truncatedRangeRev(const WideRead& r, KeyView lastReported) {
|
||||
return mkRange(asKey(lastReported), r.end_.key);
|
||||
}
|
||||
|
||||
@@ -393,7 +394,7 @@ ConflictRange truncatedRangeRev(const RangeRead& r, KeyView lastReported) {
|
||||
// Complete and offset-one cases
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
ConflictRange closedFormReverseTruncatedZero(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormReverseTruncatedZero(const WideRead& r, const Result& res) {
|
||||
if (r.end_.offset <= 1) return truncatedRangeRev(r, lastKey(res));
|
||||
OptKeyView L = last(res);
|
||||
if (residualT(r, res) == residualE(r)) {
|
||||
@@ -409,18 +410,18 @@ ConflictRange closedFormReverseTruncatedZero(const RangeRead& r, const Result& r
|
||||
return mkRange(std::move(L), topKey());
|
||||
}
|
||||
|
||||
ConflictRange truncatedRange(const RangeRead& r, KeyView lastReported) {
|
||||
ConflictRange truncatedRange(const WideRead& r, KeyView lastReported) {
|
||||
return mkRange(r.begin.key, asKey(keyAfter(lastReported)));
|
||||
}
|
||||
|
||||
ConflictRange truncatedForwardClosed(const RangeRead& r, const Result& res) {
|
||||
ConflictRange truncatedForwardClosed(const WideRead& r, const Result& res) {
|
||||
NatInf cap = intervalCard(r.end_.key, r.begin.key);
|
||||
NatInf room = NatInf::of(natSub(residualE(r), res.keys.size()));
|
||||
if (niLe(cap, room)) return truncatedRange(r, lastKey(res));
|
||||
return mkRange(r.end_.key, afterLast(res));
|
||||
}
|
||||
|
||||
ConflictRange completeClosedWith(const OptKey& endKey, const RangeRead& r,
|
||||
ConflictRange completeClosedWith(const OptKey& endKey, const WideRead& r,
|
||||
const Result& res) {
|
||||
OptKeyView begin = r.begin.key;
|
||||
if (optLt(r.end_.key, r.begin.key) &&
|
||||
@@ -434,48 +435,48 @@ ConflictRange completeClosedWith(const OptKey& endKey, const RangeRead& r,
|
||||
return mkRange(std::move(begin), topKey());
|
||||
}
|
||||
|
||||
ConflictRange completeReversedClosed(const RangeRead& r, const Result& res) {
|
||||
ConflictRange completeReversedClosed(const WideRead& r, const Result& res) {
|
||||
return completeClosedWith(afterFirst(res), r, res);
|
||||
}
|
||||
ConflictRange completeForwardClosed(const RangeRead& r, const Result& res) {
|
||||
ConflictRange completeForwardClosed(const WideRead& r, const Result& res) {
|
||||
return completeClosedWith(afterLast(res), r, res);
|
||||
}
|
||||
ConflictRange completeClosed(const RangeRead& r, const Result& res) {
|
||||
ConflictRange completeClosed(const WideRead& r, const Result& res) {
|
||||
return r.reverse ? completeReversedClosed(r, res) : completeForwardClosed(r, res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormOffsetOneTruncated(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormOffsetOneTruncated(const WideRead& r, const Result& res) {
|
||||
if (r.end_.offset <= 0) return mkRange(r.begin.key, r.end_.key);
|
||||
return truncatedRange(r, lastKey(res));
|
||||
}
|
||||
|
||||
ConflictRange topRange(const RangeRead& r) { return mkRange(r.begin.key, topKey()); }
|
||||
ConflictRange topRange(const WideRead& r) { return mkRange(r.begin.key, topKey()); }
|
||||
|
||||
ConflictRange closedFormOffsetOneWith(KeyView endKey, const RangeRead& r,
|
||||
ConflictRange closedFormOffsetOneWith(KeyView endKey, const WideRead& r,
|
||||
const Result& res) {
|
||||
if (r.end_.offset <= 1) return mkRange(r.begin.key, r.end_.key);
|
||||
if (residualT(r, res) == residualE(r)) return truncatedRange(r, endKey);
|
||||
return topRange(r);
|
||||
}
|
||||
|
||||
ConflictRange closedFormOffsetOneRev(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormOffsetOneRev(const WideRead& r, const Result& res) {
|
||||
return closedFormOffsetOneWith(firstKey(res), r, res);
|
||||
}
|
||||
ConflictRange closedFormOffsetOne(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormOffsetOne(const WideRead& r, const Result& res) {
|
||||
return closedFormOffsetOneWith(lastKey(res), r, res);
|
||||
}
|
||||
ConflictRange closedFormOffsetOneAny(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormOffsetOneAny(const WideRead& r, const Result& res) {
|
||||
return r.reverse ? closedFormOffsetOneRev(r, res) : closedFormOffsetOne(r, res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormOffsetOneUniversal(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormOffsetOneUniversal(const WideRead& r, const Result& res) {
|
||||
if (res.more)
|
||||
return r.reverse ? closedFormReverseTruncatedZero(r, res)
|
||||
: closedFormOffsetOneTruncated(r, res);
|
||||
return closedFormOffsetOneAny(r, res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormOffsetOneTotal(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormOffsetOneTotal(const WideRead& r, const Result& res) {
|
||||
if (optLt(r.end_.key, r.begin.key)) {
|
||||
if (res.more)
|
||||
return r.reverse ? closedFormReverseTruncatedZero(r, res)
|
||||
@@ -485,7 +486,7 @@ ConflictRange closedFormOffsetOneTotal(const RangeRead& r, const Result& res) {
|
||||
return closedFormOffsetOneUniversal(r, res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormZeroCrossEndOneLong(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormZeroCrossEndOneLong(const WideRead& r, const Result& res) {
|
||||
return mkRange(leastReportedOpt(r, res), r.begin.key);
|
||||
}
|
||||
|
||||
@@ -493,31 +494,31 @@ ConflictRange closedFormZeroCrossEndOneLong(const RangeRead& r, const Result& re
|
||||
// Zero-crossed cases
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
ConflictRange closedFormZeroCrossEnd(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormZeroCrossEnd(const WideRead& r, const Result& res) {
|
||||
return mkRange(leastReportedOpt(r, res), r.end_.key);
|
||||
}
|
||||
|
||||
ConflictRange completeForwardCrossedGeneral(const RangeRead& r, const Result& res) {
|
||||
ConflictRange completeForwardCrossedGeneral(const WideRead& r, const Result& res) {
|
||||
if (r.end_.offset <= 1) return mkRange(r.begin.key, r.end_.key);
|
||||
if (residualT(r, res) + residualB(r) == residualE(r))
|
||||
return mkRange(r.end_.key, afterLast(res));
|
||||
return mkRange(crossedBegin(r, res), topKey());
|
||||
}
|
||||
|
||||
RangeRead zeroBeginAnchor(const RangeRead& r, const Result& res) {
|
||||
RangeRead out = r;
|
||||
WideRead zeroBeginAnchor(const WideRead& r, const Result& res) {
|
||||
WideRead out = r;
|
||||
out.begin.key = first(res);
|
||||
out.begin.offset = 1;
|
||||
return out;
|
||||
}
|
||||
|
||||
ConflictRange zeroCrossLongAnchor(const RangeRead& r, const Result& res) {
|
||||
ConflictRange zeroCrossLongAnchor(const WideRead& r, const Result& res) {
|
||||
if (optLt(r.end_.key, first(res)))
|
||||
return completeForwardCrossedGeneral(zeroBeginAnchor(r, res), res);
|
||||
return closedFormOffsetOne(zeroBeginAnchor(r, res), res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormZeroCrossLong(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormZeroCrossLong(const WideRead& r, const Result& res) {
|
||||
if (isTop(r.begin.key)) {
|
||||
OptKeyView H = first(res);
|
||||
std::uint64_t e = residualE(r);
|
||||
@@ -531,11 +532,11 @@ ConflictRange closedFormZeroCrossLong(const RangeRead& r, const Result& res) {
|
||||
return mkRange(a.begin, optMax(a.end_, r.begin.key));
|
||||
}
|
||||
|
||||
ConflictRange closedFormZeroCrossUnderEnd(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormZeroCrossUnderEnd(const WideRead& r, const Result& res) {
|
||||
return closedFormOffsetOneTotal(zeroBeginAnchor(r, res), res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormZeroCrossComplete(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormZeroCrossComplete(const WideRead& r, const Result& res) {
|
||||
if (r.end_.offset <= 0) return closedFormZeroCrossEnd(r, res);
|
||||
if (r.end_.offset == 1) {
|
||||
if (optLt(r.end_.key, r.begin.key))
|
||||
@@ -547,23 +548,23 @@ ConflictRange closedFormZeroCrossComplete(const RangeRead& r, const Result& res)
|
||||
return closedFormZeroCrossUnderEnd(r, res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormZeroCrossCompleteRev(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormZeroCrossCompleteRev(const WideRead& r, const Result& res) {
|
||||
std::vector<KeyView> rev = reversedKeys(res);
|
||||
return closedFormZeroCrossComplete(forwardRead(r), Result{rev, false});
|
||||
}
|
||||
|
||||
bool zeroCrossUnderEnd(const RangeRead& r, const Result& res) {
|
||||
bool zeroCrossUnderEnd(const WideRead& r, const Result& res) {
|
||||
return r.begin.offset == 0 && !res.more && !r.reverse &&
|
||||
r.end_.offset >= 2 && optLt(leastReportedOpt(r, res), r.begin.key) &&
|
||||
optLe(r.begin.key, r.end_.key);
|
||||
}
|
||||
|
||||
ConflictRange closedFormZeroCrossResidual(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormZeroCrossResidual(const WideRead& r, const Result& res) {
|
||||
if (zeroCrossUnderEnd(r, res)) return closedFormZeroCrossUnderEnd(r, res);
|
||||
return closedFormZeroCrossLong(r, res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormZeroCrossTruncRevCrossed(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormZeroCrossTruncRevCrossed(const WideRead& r, const Result& res) {
|
||||
Result complete = res;
|
||||
complete.more = false;
|
||||
return closedFormZeroCrossCompleteRev(r, complete);
|
||||
@@ -573,7 +574,7 @@ ConflictRange closedFormZeroCrossTruncRevCrossed(const RangeRead& r, const Resul
|
||||
// Empty result
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
bool AlwaysEmpty(const RangeRead& r) {
|
||||
bool AlwaysEmpty(const WideRead& r) {
|
||||
NatInf gap = intervalCard(r.begin.key, r.end_.key);
|
||||
std::uint64_t b = noPinB(gap, r.begin.offset, r.end_.offset);
|
||||
std::uint64_t e = cELo(r.begin.offset, r.end_.offset);
|
||||
@@ -603,18 +604,18 @@ bool AlwaysEmpty(const RangeRead& r) {
|
||||
return !inner;
|
||||
}
|
||||
|
||||
ConflictRange emptyRange(const RangeRead& r) {
|
||||
ConflictRange emptyRange(const WideRead& r) {
|
||||
return mkRange(r.begin.key, r.begin.key);
|
||||
}
|
||||
|
||||
ConflictRange crossedRangeGeneral(const RangeRead& r) {
|
||||
ConflictRange crossedRangeGeneral(const WideRead& r) {
|
||||
NatInf diff = niSub(NatInf::of(residualE(r)), NatInf::of(residualB(r)));
|
||||
if (niLe(diff, intervalCard(r.end_.key, r.begin.key)))
|
||||
return mkRange(r.end_.key, topKey());
|
||||
return mkRange(r.begin.key, topKey());
|
||||
}
|
||||
|
||||
ConflictRange emptyValue(const RangeRead& r) {
|
||||
ConflictRange emptyValue(const WideRead& r) {
|
||||
if (AlwaysEmpty(r)) return emptyRange(r);
|
||||
if (r.begin.offset <= 0) {
|
||||
if (r.end_.offset >= 2) return mkRange(bottomKey(), topKey());
|
||||
@@ -632,15 +633,15 @@ ConflictRange emptyValue(const RangeRead& r) {
|
||||
// Complete and forward-truncated results
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
OptKeyView closedFormBegin(const RangeRead& r, const Result& res) {
|
||||
OptKeyView closedFormBegin(const WideRead& r, const Result& res) {
|
||||
return clampsToBottom(r, res) ? bottomKeyView() : r.begin.key;
|
||||
}
|
||||
|
||||
bool closedFormFinite(const RangeRead& r, const Result& res) {
|
||||
bool closedFormFinite(const WideRead& r, const Result& res) {
|
||||
return closedFormDeficit(r) + residualT(r, res) == residualE(r);
|
||||
}
|
||||
|
||||
ConflictRange closedFormCompleteForward(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormCompleteForward(const WideRead& r, const Result& res) {
|
||||
OptKeyView begin = closedFormBegin(r, res);
|
||||
if (r.end_.offset <= 1) return mkRange(begin, r.end_.key);
|
||||
if (clampsToBottom(r, res) || optLe(r.begin.key, r.end_.key)) {
|
||||
@@ -654,18 +655,18 @@ ConflictRange closedFormCompleteForward(const RangeRead& r, const Result& res) {
|
||||
return mkRange(crossedBegin(r, res), topKey());
|
||||
}
|
||||
|
||||
ConflictRange closedFormComplete(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormComplete(const WideRead& r, const Result& res) {
|
||||
if (!r.reverse) return closedFormCompleteForward(forwardRead(r), res);
|
||||
std::vector<KeyView> rev = reversedKeys(res);
|
||||
return closedFormCompleteForward(forwardRead(r), Result{rev, false});
|
||||
}
|
||||
|
||||
NatInf closedFormForwardCapacity(const RangeRead& r, const Result& res) {
|
||||
NatInf closedFormForwardCapacity(const WideRead& r, const Result& res) {
|
||||
if (clampsToBottom(r, res)) return NatInf::of(0);
|
||||
return intervalCard(r.end_.key, r.begin.key);
|
||||
}
|
||||
|
||||
ConflictRange closedFormForwardTruncated(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormForwardTruncated(const WideRead& r, const Result& res) {
|
||||
OptKeyView begin = closedFormBegin(r, res);
|
||||
if (r.end_.offset <= 0) return mkRange(begin, r.end_.key);
|
||||
std::uint64_t room = natSub(natSub(residualE(r), res.keys.size()), residualB(r));
|
||||
@@ -678,22 +679,22 @@ ConflictRange closedFormForwardTruncated(const RangeRead& r, const Result& res)
|
||||
// Reversed truncation
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
std::uint64_t closedFormReverseCount(const RangeRead& r, const Result& res) {
|
||||
std::uint64_t closedFormReverseCount(const WideRead& r, const Result& res) {
|
||||
if (optLt(r.end_.key, r.begin.key))
|
||||
return static_cast<std::uint64_t>(res.keys.size());
|
||||
return residualT(r, res);
|
||||
}
|
||||
|
||||
bool closedFormReverseFinite(const RangeRead& r, const Result& res) {
|
||||
bool closedFormReverseFinite(const WideRead& r, const Result& res) {
|
||||
return closedFormDeficit(r) + closedFormReverseCount(r, res) == residualE(r);
|
||||
}
|
||||
|
||||
bool closedFormCrossedRoom(const RangeRead& r, const Result& res) {
|
||||
bool closedFormCrossedRoom(const WideRead& r, const Result& res) {
|
||||
NatInf lhs = NatInf::of(natSub(residualE(r), res.keys.size()));
|
||||
return niLe(lhs, intervalCard(r.end_.key, last(res)));
|
||||
}
|
||||
|
||||
ConflictRange closedFormReverseTruncatedSkip(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormReverseTruncatedSkip(const WideRead& r, const Result& res) {
|
||||
if (r.end_.offset <= 1) return mkRange(r.begin.key, r.end_.key);
|
||||
if (allBelowEnd(r, res)) return topRange(r);
|
||||
if (closedFormReverseFinite(r, res)) {
|
||||
@@ -706,12 +707,12 @@ ConflictRange closedFormReverseTruncatedSkip(const RangeRead& r, const Result& r
|
||||
return mkRange(begin, topKey());
|
||||
}
|
||||
|
||||
ConflictRange closedFormReverseTruncated(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormReverseTruncated(const WideRead& r, const Result& res) {
|
||||
if (residualB(r) == 0) return closedFormReverseTruncatedZero(r, res);
|
||||
return closedFormReverseTruncatedSkip(r, res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormPositive(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormPositive(const WideRead& r, const Result& res) {
|
||||
if (!res.more) return closedFormComplete(r, res);
|
||||
if (!r.reverse) return closedFormForwardTruncated(r, res);
|
||||
return closedFormReverseTruncated(r, res);
|
||||
@@ -721,25 +722,25 @@ ConflictRange closedFormPositive(const RangeRead& r, const Result& res) {
|
||||
// Crossed table
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
bool overshoot(const RangeRead& r, const Result& res) {
|
||||
bool overshoot(const WideRead& r, const Result& res) {
|
||||
return r.end_.offset >= 2 && allBelowEnd(r, res);
|
||||
}
|
||||
|
||||
bool zeroCrossOvershootComplete(const RangeRead& r, const Result& res) {
|
||||
bool zeroCrossOvershootComplete(const WideRead& r, const Result& res) {
|
||||
return r.begin.offset == 0 && !res.more && !r.reverse && overshoot(r, res) &&
|
||||
optLt(leastReportedOpt(r, res), r.begin.key);
|
||||
}
|
||||
|
||||
bool negCrossOvershoot(const RangeRead& r, const Result& res) {
|
||||
bool negCrossOvershoot(const WideRead& r, const Result& res) {
|
||||
return !r.reverse && r.begin.offset < 0 && !res.more && overshoot(r, res) &&
|
||||
optLt(first(res), r.begin.key);
|
||||
}
|
||||
|
||||
bool crossedCompleteOvershoot(const RangeRead& r, const Result& res) {
|
||||
bool crossedCompleteOvershoot(const WideRead& r, const Result& res) {
|
||||
return zeroCrossOvershootComplete(r, res) || negCrossOvershoot(r, res);
|
||||
}
|
||||
|
||||
bool crossedCompleteEndLeOne(const RangeRead& r, const Result& res) {
|
||||
bool crossedCompleteEndLeOne(const WideRead& r, const Result& res) {
|
||||
if (!(!r.reverse && !res.more && r.begin.offset <= 0 &&
|
||||
optLt(first(res), r.begin.key)))
|
||||
return false;
|
||||
@@ -750,30 +751,30 @@ bool crossedCompleteEndLeOne(const RangeRead& r, const Result& res) {
|
||||
clampNonposBottom(r, res));
|
||||
}
|
||||
|
||||
bool zeroCrossLongTop(const RangeRead& r, const Result& res) {
|
||||
bool zeroCrossLongTop(const WideRead& r, const Result& res) {
|
||||
return r.begin.offset == 0 && !res.more && !r.reverse &&
|
||||
r.end_.offset >= 2 && isTop(r.begin.key);
|
||||
}
|
||||
|
||||
bool zeroCrossLongFinite(const RangeRead& r, const Result& res) {
|
||||
bool zeroCrossLongFinite(const WideRead& r, const Result& res) {
|
||||
return r.begin.offset == 0 && !res.more && !r.reverse &&
|
||||
r.end_.offset >= 2 && !isTop(r.begin.key) &&
|
||||
optLt(r.end_.key, r.begin.key) &&
|
||||
optLt(leastReportedOpt(r, res), r.begin.key);
|
||||
}
|
||||
|
||||
bool crossedCompleteBeginZero(const RangeRead& r, const Result& res) {
|
||||
bool crossedCompleteBeginZero(const WideRead& r, const Result& res) {
|
||||
return zeroCrossUnderEnd(r, res) || zeroCrossLongTop(r, res) ||
|
||||
zeroCrossLongFinite(r, res);
|
||||
}
|
||||
|
||||
bool crossedCompleteClamp(const RangeRead& r, const Result& res) {
|
||||
bool crossedCompleteClamp(const WideRead& r, const Result& res) {
|
||||
return negCrossClampEndOne(r, res) || negCrossHeadBottom(r, res) ||
|
||||
negCrossClampNonposBottom(r, res) ||
|
||||
negCrossClampLongNonpos(r, res);
|
||||
}
|
||||
|
||||
ConflictRange closedFormCrossedComplete(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormCrossedComplete(const WideRead& r, const Result& res) {
|
||||
if (crossedCompleteOvershoot(r, res))
|
||||
return closedFormNegCrossTopUnified(r, res);
|
||||
if (crossedCompleteEndLeOne(r, res))
|
||||
@@ -785,18 +786,18 @@ ConflictRange closedFormCrossedComplete(const RangeRead& r, const Result& res) {
|
||||
return closedFormNegCrossCompleteHighResidual(r, res);
|
||||
}
|
||||
|
||||
bool zeroCrossTruncRevCrossed(const RangeRead& r, const Result& res) {
|
||||
bool zeroCrossTruncRevCrossed(const WideRead& r, const Result& res) {
|
||||
return r.begin.offset == 0 && r.reverse && res.more &&
|
||||
optLt(leastReportedOpt(r, res), r.begin.key);
|
||||
}
|
||||
|
||||
bool negCrossTruncRevUnder(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncRevUnder(const WideRead& r, const Result& res) {
|
||||
return res.more && r.reverse && r.begin.offset < 0 &&
|
||||
optLt(last(res), r.begin.key) && optLe(r.begin.key, r.end_.key) &&
|
||||
r.end_.offset <= 1;
|
||||
}
|
||||
|
||||
bool negCrossTruncRevCrossedLow(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncRevCrossedLow(const WideRead& r, const Result& res) {
|
||||
return res.more && r.reverse && r.begin.offset < 0 &&
|
||||
optLt(last(res), r.begin.key) && optLt(r.end_.key, r.begin.key) &&
|
||||
r.end_.offset <= 1 &&
|
||||
@@ -806,24 +807,24 @@ bool negCrossTruncRevCrossedLow(const RangeRead& r, const Result& res) {
|
||||
NatInf::of(beginSlack(r) + 1));
|
||||
}
|
||||
|
||||
bool revTruncLeOneLow(const RangeRead& r, const Result& res) {
|
||||
bool revTruncLeOneLow(const WideRead& r, const Result& res) {
|
||||
return negCrossTruncRevUnder(r, res) ||
|
||||
negCrossTruncRevCrossedLow(r, res);
|
||||
}
|
||||
|
||||
bool negCrossTruncRevBelowEnd(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncRevBelowEnd(const WideRead& r, const Result& res) {
|
||||
return res.more && r.reverse && r.begin.offset < 0 &&
|
||||
optLt(last(res), r.begin.key) && overshoot(r, res);
|
||||
}
|
||||
|
||||
bool negCrossTruncRevResidualRoom(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncRevResidualRoom(const WideRead& r, const Result& res) {
|
||||
return res.more && r.reverse && r.begin.offset < 0 &&
|
||||
r.end_.offset >= 2 && anyAtOrAboveEnd(r, res) &&
|
||||
niLe(niAdd(intervalCard(r.end_.key, first(res)), NatInf::of(2)),
|
||||
NatInf::of(residualE(r)));
|
||||
}
|
||||
|
||||
bool negCrossTruncRevResidualTopCrossedSmallGap(const RangeRead& r,
|
||||
bool negCrossTruncRevResidualTopCrossedSmallGap(const WideRead& r,
|
||||
const Result& res) {
|
||||
if (!(res.more && r.reverse && r.begin.offset < 0 &&
|
||||
r.end_.offset >= 2 && optLt(r.end_.key, last(res))))
|
||||
@@ -833,52 +834,52 @@ bool negCrossTruncRevResidualTopCrossedSmallGap(const RangeRead& r,
|
||||
return niLt(lhs, NatInf::of(residualE(r)));
|
||||
}
|
||||
|
||||
bool negCrossTruncRevResidualTopCrossed(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncRevResidualTopCrossed(const WideRead& r, const Result& res) {
|
||||
return res.more && r.reverse && r.begin.offset < 0 &&
|
||||
r.end_.offset >= 2 && optLe(last(res), r.end_.key) &&
|
||||
residualT(r, res) < residualE(r);
|
||||
}
|
||||
|
||||
bool revTruncGeTwoTop(const RangeRead& r, const Result& res) {
|
||||
bool revTruncGeTwoTop(const WideRead& r, const Result& res) {
|
||||
return negCrossTruncRevBelowEnd(r, res) ||
|
||||
negCrossTruncRevResidualRoom(r, res) ||
|
||||
negCrossTruncRevResidualTopCrossedSmallGap(r, res) ||
|
||||
negCrossTruncRevResidualTopCrossed(r, res);
|
||||
}
|
||||
|
||||
bool negCrossTruncRevResidualTopLargeCrossed(const RangeRead& r,
|
||||
bool negCrossTruncRevResidualTopLargeCrossed(const WideRead& r,
|
||||
const Result& res) {
|
||||
return negCrossTruncRevResidualTopLarge(r, res) &&
|
||||
optLt(last(res), r.begin.key) && !isTop(r.begin.key);
|
||||
}
|
||||
|
||||
bool revTruncGeTwoLarge(const RangeRead& r, const Result& res) {
|
||||
bool revTruncGeTwoLarge(const WideRead& r, const Result& res) {
|
||||
return negCrossTruncRevResidualTopLargeCrossed(r, res) ||
|
||||
negCrossTruncRevResidualTopLargeSentinel(r, res);
|
||||
}
|
||||
|
||||
bool negCrossTruncTopTop(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncTopTop(const WideRead& r, const Result& res) {
|
||||
return res.more && !r.reverse && r.begin.offset < 0 &&
|
||||
isTop(r.begin.key) && isTop(r.end_.key) && r.end_.offset <= 0;
|
||||
}
|
||||
|
||||
bool negCrossTruncTopTopEq(const RangeRead& r, const Result& res) {
|
||||
bool negCrossTruncTopTopEq(const WideRead& r, const Result& res) {
|
||||
if (!negCrossTruncTopTop(r, res)) return false;
|
||||
std::uint64_t extra = toNat(1 - r.end_.offset);
|
||||
return res.keys.size() + extra == beginSlack(r) + 1;
|
||||
}
|
||||
|
||||
std::uint64_t closedFormClampSlack(const RangeRead& r, const Result& res) {
|
||||
std::uint64_t closedFormClampSlack(const WideRead& r, const Result& res) {
|
||||
return natSub(beginSlack(r) + 1, res.keys.size()) +
|
||||
(isBottom(first(res)) ? 1 : 0);
|
||||
}
|
||||
|
||||
bool closedFormClampGapSmall(const RangeRead& r, const Result& res) {
|
||||
bool closedFormClampGapSmall(const WideRead& r, const Result& res) {
|
||||
return niLe(intervalCard(asKey(lastKey(res)), r.begin.key),
|
||||
NatInf::of(closedFormClampSlack(r, res)));
|
||||
}
|
||||
|
||||
bool closedFormClampGapExactSaturated(const RangeRead& r, const Result& res) {
|
||||
bool closedFormClampGapExactSaturated(const WideRead& r, const Result& res) {
|
||||
if (!(first(res) != bottomKeyView() && isBottom(r.end_.key) &&
|
||||
residualE(r) == res.keys.size()))
|
||||
return false;
|
||||
@@ -886,24 +887,24 @@ bool closedFormClampGapExactSaturated(const RangeRead& r, const Result& res) {
|
||||
NatInf::of(natSub(beginSlack(r) + 1, res.keys.size())));
|
||||
}
|
||||
|
||||
bool closedFormClampGapLow(const RangeRead& r, const Result& res) {
|
||||
bool closedFormClampGapLow(const WideRead& r, const Result& res) {
|
||||
return closedFormClampGapSmall(r, res) ||
|
||||
closedFormClampGapExactSaturated(r, res);
|
||||
}
|
||||
|
||||
OptKey closedFormClampUpper(const RangeRead& r, const Result& res) {
|
||||
OptKey closedFormClampUpper(const WideRead& r, const Result& res) {
|
||||
if (closedFormClampGapLow(r, res)) return afterLast(res);
|
||||
return ownKey(r.begin.key);
|
||||
}
|
||||
|
||||
bool closedFormForwardSaturated(const RangeRead& r, const Result& res) {
|
||||
bool closedFormForwardSaturated(const WideRead& r, const Result& res) {
|
||||
if (!(residualE(r) > 0 && optLt(r.end_.key, first(res)))) return false;
|
||||
NatInf rhs = niAdd(intervalCard(r.end_.key, first(res)),
|
||||
NatInf::of(res.keys.size()));
|
||||
return niLt(NatInf::of(residualE(r)), rhs);
|
||||
}
|
||||
|
||||
ConflictRange closedFormForwardTruncatedNonpos(const RangeRead& r,
|
||||
ConflictRange closedFormForwardTruncatedNonpos(const WideRead& r,
|
||||
const Result& res) {
|
||||
if (reportedBelowBegin(r, res) <= beginSlack(r)) {
|
||||
if (r.end_.offset <= 0) {
|
||||
@@ -929,7 +930,7 @@ ConflictRange closedFormForwardTruncatedNonpos(const RangeRead& r,
|
||||
return mkRange(begin, optMax(r.begin.key, afterLast(res)));
|
||||
}
|
||||
|
||||
ConflictRange closedFormCrossed(const RangeRead& r, const Result& res) {
|
||||
ConflictRange closedFormCrossed(const WideRead& r, const Result& res) {
|
||||
if (!res.more) {
|
||||
if (!r.reverse) return closedFormCrossedComplete(r, res);
|
||||
std::vector<KeyView> rev = reversedKeys(res);
|
||||
@@ -954,11 +955,11 @@ ConflictRange closedFormCrossed(const RangeRead& r, const Result& res) {
|
||||
} // namespace
|
||||
|
||||
ConflictRange closedForm(const RangeRead& r, const Result& res) {
|
||||
assertInputOffsetsFitInt32(r);
|
||||
if (res.keys.empty()) return emptyValue(r);
|
||||
if (r.begin.offset >= 1 || clampedNonpos(r, res))
|
||||
return closedFormPositive(r, res);
|
||||
return closedFormCrossed(r, res);
|
||||
const WideRead wr = cr::detail::widen(r);
|
||||
if (res.keys.empty()) return emptyValue(wr);
|
||||
if (wr.begin.offset >= 1 || clampedNonpos(wr, res))
|
||||
return closedFormPositive(wr, res);
|
||||
return closedFormCrossed(wr, res);
|
||||
}
|
||||
|
||||
} // namespace cr::literal
|
||||
+52
-34
@@ -18,7 +18,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
@@ -40,16 +39,28 @@ using Key = std::string;
|
||||
using KeyView = std::string_view;
|
||||
using OptKey = std::optional<Key>;
|
||||
using OptKeyView = std::optional<KeyView>;
|
||||
// Lean's unbounded `Int`. Caller-supplied offsets are required to fit in
|
||||
// `std::int32_t` (see `Selector`), so all intermediate arithmetic in `Int`
|
||||
// stays far from overflow; the code below relies on that.
|
||||
// Lean's unbounded `Int`. Public selector offsets are 32-bit; the internal
|
||||
// wide-offset read used by the decision procedure stores derived offsets here.
|
||||
using Int = std::int64_t;
|
||||
|
||||
struct Selector {
|
||||
OptKeyView key;
|
||||
// Offsets supplied by callers must lie in `[INT32_MIN, INT32_MAX]`. They are
|
||||
// stored as `Int` because the closed form also builds derived selectors whose
|
||||
// offsets (for example `end.offset - residualT`) need not fit in 32 bits.
|
||||
// Caller-supplied offsets are `std::int32_t`, matching FoundationDB.
|
||||
std::int32_t offset = 0;
|
||||
};
|
||||
|
||||
struct RangeRead {
|
||||
Selector begin;
|
||||
Selector end_;
|
||||
bool reverse = false;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
// Internal mirror of `RangeRead` whose offsets are wide enough for derived
|
||||
// selectors such as `end.offset - residualT`.
|
||||
struct Selector {
|
||||
OptKeyView key;
|
||||
Int offset = 0;
|
||||
};
|
||||
|
||||
@@ -59,11 +70,17 @@ struct RangeRead {
|
||||
bool reverse = false;
|
||||
};
|
||||
|
||||
// The public offset contract: caller-supplied offsets must fit in
|
||||
// `std::int32_t`. This is checked at the public `closedForm` entry points
|
||||
// (debug builds only) and by the corpus parsers. It is deliberately not
|
||||
// checked in `Selector`, because the decision procedure derives selectors
|
||||
// whose offsets may exceed this range.
|
||||
inline RangeRead widen(const ::cr::RangeRead& r) {
|
||||
return {{r.begin.key, r.begin.offset},
|
||||
{r.end_.key, r.end_.offset},
|
||||
r.reverse};
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// The offset contract shared with the corpus parsers. `Selector::offset` is
|
||||
// already `std::int32_t`, so parsers validate wider parsed values with these
|
||||
// bounds before narrowing.
|
||||
inline constexpr Int kMinInputOffset =
|
||||
std::numeric_limits<std::int32_t>::min();
|
||||
inline constexpr Int kMaxInputOffset =
|
||||
@@ -74,14 +91,6 @@ inline bool offsetsFitInt32(Int begin, Int end) {
|
||||
end >= kMinInputOffset && end <= kMaxInputOffset;
|
||||
}
|
||||
|
||||
inline bool inputOffsetsFitInt32(const RangeRead& r) {
|
||||
return offsetsFitInt32(r.begin.offset, r.end_.offset);
|
||||
}
|
||||
|
||||
inline void assertInputOffsetsFitInt32(const RangeRead& r) {
|
||||
assert(inputOffsetsFitInt32(r));
|
||||
}
|
||||
|
||||
struct Result {
|
||||
// A non-owning view of the reported keys. The caller keeps the underlying
|
||||
// keys alive for the duration of the call.
|
||||
@@ -272,15 +281,18 @@ inline OptKey afterLast(const Result& res) {
|
||||
return asKey(keyAfter(lastKey(res)));
|
||||
}
|
||||
|
||||
inline KeyView leastReported(const RangeRead& r, const Result& res) {
|
||||
template <class R>
|
||||
inline KeyView leastReported(const R& r, const Result& res) {
|
||||
return r.reverse ? lastKey(res) : firstKey(res);
|
||||
}
|
||||
inline OptKeyView leastReportedOpt(const RangeRead& r, const Result& res) {
|
||||
template <class R>
|
||||
inline OptKeyView leastReportedOpt(const R& r, const Result& res) {
|
||||
return asKey(leastReported(r, res));
|
||||
}
|
||||
|
||||
inline RangeRead forwardRead(const RangeRead& r) {
|
||||
RangeRead out = r;
|
||||
template <class R>
|
||||
inline R forwardRead(const R& r) {
|
||||
R out = r;
|
||||
out.reverse = false;
|
||||
return out;
|
||||
}
|
||||
@@ -310,7 +322,8 @@ inline NatInf intervalCard(OptKeyView b, OptKeyView e) {
|
||||
// Result-based counters, in the exact form used by the statement
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
inline std::uint64_t residualT(const RangeRead& r, const Result& res) {
|
||||
template <class R>
|
||||
inline std::uint64_t residualT(const R& r, const Result& res) {
|
||||
if (isTop(r.end_.key)) return 0;
|
||||
std::uint64_t count = 0;
|
||||
for (KeyView k : res.keys)
|
||||
@@ -318,7 +331,8 @@ inline std::uint64_t residualT(const RangeRead& r, const Result& res) {
|
||||
return count;
|
||||
}
|
||||
|
||||
inline std::uint64_t reportedBelowBegin(const RangeRead& r, const Result& res) {
|
||||
template <class R>
|
||||
inline std::uint64_t reportedBelowBegin(const R& r, const Result& res) {
|
||||
if (isTop(r.begin.key)) return static_cast<std::uint64_t>(res.keys.size());
|
||||
std::uint64_t count = 0;
|
||||
for (KeyView k : res.keys)
|
||||
@@ -326,17 +340,21 @@ inline std::uint64_t reportedBelowBegin(const RangeRead& r, const Result& res) {
|
||||
return count;
|
||||
}
|
||||
|
||||
inline std::uint64_t residualB(const RangeRead& r) {
|
||||
return toNat(r.begin.offset - 1);
|
||||
template <class R>
|
||||
inline std::uint64_t residualB(const R& r) {
|
||||
return toNat(static_cast<Int>(r.begin.offset) - 1);
|
||||
}
|
||||
inline std::uint64_t residualE(const RangeRead& r) {
|
||||
return toNat(r.end_.offset - 1);
|
||||
template <class R>
|
||||
inline std::uint64_t residualE(const R& r) {
|
||||
return toNat(static_cast<Int>(r.end_.offset) - 1);
|
||||
}
|
||||
inline std::uint64_t beginSlack(const RangeRead& r) {
|
||||
return toNat(-r.begin.offset);
|
||||
template <class R>
|
||||
inline std::uint64_t beginSlack(const R& r) {
|
||||
return toNat(-static_cast<Int>(r.begin.offset));
|
||||
}
|
||||
inline std::uint64_t clampNonposD(const RangeRead& r) {
|
||||
return toNat(-r.end_.offset);
|
||||
template <class R>
|
||||
inline std::uint64_t clampNonposD(const R& r) {
|
||||
return toNat(-static_cast<Int>(r.end_.offset));
|
||||
}
|
||||
|
||||
} // namespace cr
|
||||
+2
-2
@@ -49,8 +49,8 @@ std::vector<Key> makeDb(std::size_t n, std::size_t len) {
|
||||
return db;
|
||||
}
|
||||
|
||||
Case makeCase(const std::vector<Key>& db, OptKey beginKey, Int beginOff,
|
||||
OptKey endKey, Int endOff, bool reverse, bool truncate,
|
||||
Case makeCase(const std::vector<Key>& db, OptKey beginKey, std::int32_t beginOff,
|
||||
OptKey endKey, std::int32_t endOff, bool reverse, bool truncate,
|
||||
const char* name) {
|
||||
gen::Instance inst;
|
||||
inst.beginKey = std::move(beginKey);
|
||||
|
||||
@@ -104,8 +104,8 @@ int main(int argc, char** argv) {
|
||||
std::vector<KeyView> keyViews;
|
||||
keyViews.reserve(keys.size());
|
||||
for (const Key& k : keys) keyViews.push_back(k);
|
||||
RangeRead r{Selector{optView(beginKey), static_cast<Int>(bo)},
|
||||
Selector{optView(endKey), static_cast<Int>(eo)}, reverse};
|
||||
RangeRead r{Selector{optView(beginKey), static_cast<std::int32_t>(bo)},
|
||||
Selector{optView(endKey), static_cast<std::int32_t>(eo)}, reverse};
|
||||
Result res{keyViews, more != 0};
|
||||
++cases;
|
||||
ConflictRange a = literal::closedForm(r, res);
|
||||
|
||||
@@ -28,7 +28,7 @@ using namespace cr;
|
||||
|
||||
// Offset 5 is what lets the default sweep exercise the last three
|
||||
// short-circuit branch sides in `fast.cpp` (all in crossed subtrees).
|
||||
const Int kOffsets[] = {-3, -2, -1, 0, 1, 2, 3, 4, 5};
|
||||
const std::int32_t kOffsets[] = {-3, -2, -1, 0, 1, 2, 3, 4, 5};
|
||||
|
||||
void check(const RangeRead& r, const Result& res, long long& cases,
|
||||
long long& bad, const char* kind, Int bo, Int eo, bool reverse,
|
||||
@@ -47,8 +47,8 @@ void run(const std::vector<Key>& db, const std::vector<OptKey>& keys,
|
||||
long long& cases, long long& bad) {
|
||||
for (const OptKey& beginKey : keys) {
|
||||
for (const OptKey& endKey : keys) {
|
||||
for (Int beginOffset : kOffsets) {
|
||||
for (Int endOffset : kOffsets) {
|
||||
for (std::int32_t beginOffset : kOffsets) {
|
||||
for (std::int32_t endOffset : kOffsets) {
|
||||
const Selector begin{optView(beginKey), beginOffset};
|
||||
const Selector end{optView(endKey), endOffset};
|
||||
const std::vector<Key> complete = gen::inRange(
|
||||
|
||||
+10
-9
@@ -9,6 +9,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -33,18 +34,18 @@ int main() {
|
||||
owned.push_back(OptKey{Key("a")});
|
||||
owned.push_back(OptKey{Key("\xff\xff", 2)});
|
||||
|
||||
// The public offset contract accepts exactly the 32-bit boundaries; the
|
||||
// entry-point assertions and corpus parsers share this predicate.
|
||||
const RangeRead boundary{Selector{std::nullopt, kMinInputOffset},
|
||||
Selector{std::nullopt, kMaxInputOffset}, false};
|
||||
const RangeRead outside{Selector{std::nullopt, kMinInputOffset - 1},
|
||||
Selector{std::nullopt, 0}, false};
|
||||
if (!inputOffsetsFitInt32(boundary) || inputOffsetsFitInt32(outside)) {
|
||||
// `Selector` stores offsets as `std::int32_t`, so `RangeRead` itself cannot
|
||||
// violate the input contract. The corpus parsers still validate wider
|
||||
// parsed values with `offsetsFitInt32` before narrowing.
|
||||
static_assert(std::is_same_v<decltype(Selector::offset), std::int32_t>,
|
||||
"Selector::offset must match the 32-bit input contract");
|
||||
if (!offsetsFitInt32(kMinInputOffset, kMaxInputOffset) ||
|
||||
offsetsFitInt32(kMinInputOffset - 1, kMaxInputOffset + 1)) {
|
||||
std::fprintf(stderr, "offset contract check failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const Int offs[] = {std::numeric_limits<std::int32_t>::min(),
|
||||
const std::int32_t offs[] = {std::numeric_limits<std::int32_t>::min(),
|
||||
std::numeric_limits<std::int32_t>::min() + 1,
|
||||
-1000000000,
|
||||
-3,
|
||||
@@ -59,7 +60,7 @@ int main() {
|
||||
std::vector<Selector> sels;
|
||||
sels.reserve(owned.size() * (sizeof(offs) / sizeof(offs[0])));
|
||||
for (const OptKey& k : owned)
|
||||
for (Int off : offs) sels.push_back(Selector{optView(k), off});
|
||||
for (std::int32_t off : offs) sels.push_back(Selector{optView(k), off});
|
||||
|
||||
long long cases = 0, bad = 0;
|
||||
for (const Selector& bs : sels)
|
||||
|
||||
@@ -109,8 +109,8 @@ int main(int argc, char** argv) {
|
||||
std::vector<KeyView> keyViews;
|
||||
keyViews.reserve(keys.size());
|
||||
for (const Key& k : keys) keyViews.push_back(k);
|
||||
RangeRead r{Selector{optView(beginKey), static_cast<Int>(bo)},
|
||||
Selector{optView(endKey), static_cast<Int>(eo)}, rev != 0};
|
||||
RangeRead r{Selector{optView(beginKey), static_cast<std::int32_t>(bo)},
|
||||
Selector{optView(endKey), static_cast<std::int32_t>(eo)}, rev != 0};
|
||||
Result res{keyViews, more != 0};
|
||||
OptKey wantBegin, wantEnd;
|
||||
if (!parseKey(ob, wantBegin) || !parseKey(oe, wantEnd)) {
|
||||
|
||||
@@ -61,15 +61,15 @@ inline OptKey randomOptKey(Bytes& b, std::size_t maxLen) {
|
||||
return OptKey{randomKey(b, maxLen)};
|
||||
}
|
||||
|
||||
inline Int randomOffset(Bytes& b) {
|
||||
inline std::int32_t randomOffset(Bytes& b) {
|
||||
// Bias towards the offsets that decide the interesting boundary cases, but
|
||||
// still allow the full [-256, 255] window.
|
||||
std::uint8_t pick = b.u8();
|
||||
if (pick < 192) {
|
||||
static const Int small[] = {-3, -2, -1, 0, 1, 2, 3, 4, 5};
|
||||
static const std::int32_t small[] = {-3, -2, -1, 0, 1, 2, 3, 4, 5};
|
||||
return small[pick % 9];
|
||||
}
|
||||
return static_cast<Int>(b.u16() % 512) - 256;
|
||||
return static_cast<std::int32_t>(b.u16() % 512) - 256;
|
||||
}
|
||||
|
||||
inline OptKey resolve(const std::vector<Key>& db, const Selector& s) {
|
||||
@@ -77,7 +77,7 @@ inline OptKey resolve(const std::vector<Key>& db, const Selector& s) {
|
||||
if (!s.key) {
|
||||
anchor = static_cast<Int>(db.size()) + s.offset - 1;
|
||||
} else if (s.key->empty()) {
|
||||
anchor = s.offset - 1;
|
||||
anchor = static_cast<Int>(s.offset) - 1;
|
||||
} else {
|
||||
std::size_t below = 0;
|
||||
for (const Key& k : db)
|
||||
@@ -110,8 +110,8 @@ struct Instance {
|
||||
// Owned selector keys; `read()` borrows them.
|
||||
OptKey beginKey;
|
||||
OptKey endKey;
|
||||
Int beginOffset = 0;
|
||||
Int endOffset = 0;
|
||||
std::int32_t beginOffset = 0;
|
||||
std::int32_t endOffset = 0;
|
||||
bool reverse = false;
|
||||
bool more = false;
|
||||
|
||||
|
||||
Reference in new issue
Block a user