One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
111 lines
3.8 KiB
C++
111 lines
3.8 KiB
C++
#include "cache.hpp"
|
|
namespace tile {
|
|
long long Ledger::allocate(std::size_t length) {
|
|
++created;
|
|
live_bytes += static_cast<long long>(length);
|
|
return created;
|
|
}
|
|
void Ledger::resized(std::size_t before, std::size_t after) {
|
|
live_bytes -= static_cast<long long>(before);
|
|
live_bytes += static_cast<long long>(after);
|
|
}
|
|
void Ledger::release(long long serial, std::size_t length) {
|
|
++destroyed;
|
|
live_bytes -= static_cast<long long>(length);
|
|
deaths.push_back(serial);
|
|
}
|
|
long long Ledger::live() const {
|
|
return created - destroyed;
|
|
}
|
|
unsigned char Payload::pattern(std::size_t index, unsigned seed) {
|
|
const std::size_t square = (index * index) % 251;
|
|
const std::size_t value = seed + 17 * index + square;
|
|
return static_cast<unsigned char>(value % 256);
|
|
}
|
|
Payload::Payload(std::shared_ptr<Ledger> ledger, std::size_t size, unsigned seed)
|
|
: ledger_(std::move(ledger)), bytes_(size), serial_(0) {
|
|
for (std::size_t index = 0; index < size; ++index) {
|
|
bytes_[index] = pattern(index, seed);
|
|
}
|
|
serial_ = ledger_->allocate(size);
|
|
}
|
|
Payload::~Payload() {
|
|
ledger_->release(serial_, bytes_.size());
|
|
}
|
|
long long Payload::serial() const {
|
|
return serial_;
|
|
}
|
|
std::size_t Payload::size() const {
|
|
return bytes_.size();
|
|
}
|
|
long long Payload::checksum() const {
|
|
constexpr long long modulus = 1000000007;
|
|
long long total = 0;
|
|
for (std::size_t index = 0; index < bytes_.size(); ++index) {
|
|
const long long weight = static_cast<long long>(index + 1);
|
|
const long long value = static_cast<long long>(bytes_[index]);
|
|
total = (total + weight * value) % modulus;
|
|
}
|
|
return total;
|
|
}
|
|
bool Payload::write(std::size_t offset, unsigned value) {
|
|
if (offset >= bytes_.size() || value > 255) {
|
|
return false;
|
|
}
|
|
bytes_[offset] = static_cast<unsigned char>(value);
|
|
return true;
|
|
}
|
|
bool Payload::fill(std::size_t offset, std::size_t count, unsigned value) {
|
|
if (offset > bytes_.size() || count > bytes_.size() - offset || value > 255) {
|
|
return false;
|
|
}
|
|
const auto first = bytes_.begin() + static_cast<std::ptrdiff_t>(offset);
|
|
const auto last = first + static_cast<std::ptrdiff_t>(count);
|
|
std::fill(first, last, static_cast<unsigned char>(value));
|
|
return true;
|
|
}
|
|
void Payload::resize(std::size_t length, unsigned seed) {
|
|
const std::size_t before = bytes_.size();
|
|
bytes_.resize(length);
|
|
for (std::size_t index = before; index < length; ++index) {
|
|
bytes_[index] = pattern(index, seed);
|
|
}
|
|
ledger_->resized(before, length);
|
|
}
|
|
bool Payload::read(std::size_t offset, std::size_t count, Numbers& output) const {
|
|
if (offset > bytes_.size() || count > bytes_.size() - offset) {
|
|
return false;
|
|
}
|
|
output = {0, static_cast<long long>(count)};
|
|
output.reserve(count + 2);
|
|
for (std::size_t index = offset; index < offset + count; ++index) {
|
|
output.push_back(bytes_[index]);
|
|
}
|
|
return true;
|
|
}
|
|
bool Payload::copy_range(std::size_t source_offset, Payload& target,
|
|
std::size_t target_offset, std::size_t count) const {
|
|
if (source_offset > bytes_.size()) {
|
|
return false;
|
|
}
|
|
if (count > bytes_.size() - source_offset) {
|
|
return false;
|
|
}
|
|
if (target_offset > target.bytes_.size()) {
|
|
return false;
|
|
}
|
|
if (count > target.bytes_.size() - target_offset) {
|
|
return false;
|
|
}
|
|
const auto first = bytes_.begin() + static_cast<std::ptrdiff_t>(source_offset);
|
|
const auto last = first + static_cast<std::ptrdiff_t>(count);
|
|
const std::vector<unsigned char> snapshot(first, last);
|
|
const auto destination = target.bytes_.begin() + static_cast<std::ptrdiff_t>(target_offset);
|
|
std::copy(snapshot.begin(), snapshot.end(), destination);
|
|
return true;
|
|
}
|
|
bool Payload::same_bytes(const Payload& other) const {
|
|
return bytes_ == other.bytes_;
|
|
}
|
|
}
|