Harden and fully cover the C++ translation

Add an exhaustive readable-instance sweep and a coverage gate requiring
100% line coverage of the summarised implementation. Delete branches that
are unreachable under `Readable`, centralise and assert the 32-bit offset
contract at the public entry points, and stop materialising `n` zero bytes
when deciding `keyAfterN n k < upper`.

Also add the extreme-offset regression test, harden the corpus parsers,
remove unused model helpers, document the literal-total / fast-readable
split, and refresh the validation and benchmark numbers.
This commit is contained in:
andrew committed 2026-11-17 18:46:24 -05:00
1 parent e32e42d933
commit 3bb5d062ff
15 files changed
+620 -196

No files matched your search

+14 -3
View File
@@ -48,7 +48,8 @@ inline Key randomKey(Bytes& b, std::size_t maxLen) {
std::size_t len = b.u8() % (maxLen + 1);
Key k;
k.reserve(len);
for (std::size_t i = 0; i < len; ++i) k.push_back(weightedByte(b));
for (std::size_t i = 0; i < len; ++i)
k.push_back(static_cast<char>(weightedByte(b)));
return k;
}
@@ -82,7 +83,7 @@ inline OptKey resolve(const std::vector<Key>& db, const Selector& s) {
anchor = static_cast<Int>(below) + s.offset - 1;
}
if (anchor < 0) return OptKey{Key{}};
if (static_cast<std::size_t>(anchor) >= db.size()) return std::nullopt;
if (anchor >= static_cast<Int>(db.size())) return std::nullopt;
return OptKey{db[static_cast<std::size_t>(anchor)]};
}
@@ -112,7 +113,17 @@ struct Instance {
bool reverse = false;
bool more = false;
// Must be called once `keys` is final; safe again after a move.
Instance() = default;
// Move-only: `views` borrow from `keys`. Moving a `std::vector` keeps its
// elements at the same addresses, so the views remain valid; a copy would
// leave the new instance's views pointing into the source's storage.
Instance(const Instance&) = delete;
Instance& operator=(const Instance&) = delete;
Instance(Instance&&) = default;
Instance& operator=(Instance&&) = default;
// Must be called once `keys` is final; call again after mutating `keys` or
// after moving keys in by hand.
void finish() {
views.clear();
views.reserve(keys.size());