amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

115 lines
3.5 KiB
C++

#include "ratio.hpp"
namespace ratio {
Ledger::Ledger() : channels_{} {
}
bool Ledger::has_slot(int slot) {
return slot >= 0 && slot < channel_count;
}
Configuration Ledger::configure(int slot, const Profile& profile) {
Configuration response;
if (!has_slot(slot)) {
response.result = Result::bad_slot;
return response;
}
if (!profile.valid()) {
response.result = Result::bad_value;
return response;
}
Channel& channel = channels_[static_cast<std::size_t>(slot)];
channel.profile = profile;
channel.configured = true;
++channel.generation;
response.generation = channel.generation;
return response;
}
Feed Ledger::feed(int slot, std::int64_t raw, std::int64_t weight) {
Feed response;
if (!has_slot(slot)) {
response.result = Result::bad_slot;
return response;
}
Channel& channel = channels_[static_cast<std::size_t>(slot)];
if (!channel.configured) {
response.result = Result::missing;
return response;
}
if (raw < -raw_limit || raw > raw_limit || weight < 1 || weight > 1000) {
response.result = Result::bad_value;
return response;
}
if (channel.stats.samples >= sample_limit) {
response.result = Result::full;
return response;
}
const Mapped value = map_sample(channel.profile, raw);
channel.stats.add(raw, value, static_cast<std::uint64_t>(weight));
response.mapped = value.value;
response.weight = static_cast<std::uint64_t>(weight);
return response;
}
Snapshot Ledger::snapshot(int slot) const {
Snapshot response;
if (!has_slot(slot)) {
response.result = Result::bad_slot;
return response;
}
const Channel& channel = channels_[static_cast<std::size_t>(slot)];
response.generation = channel.generation;
if (!channel.configured) {
response.result = Result::missing;
return response;
}
response.stats = channel.stats;
return response;
}
Configuration Ledger::drop(int slot) {
Configuration response;
if (!has_slot(slot)) {
response.result = Result::bad_slot;
return response;
}
Channel& channel = channels_[static_cast<std::size_t>(slot)];
response.generation = channel.generation;
if (!channel.configured) {
response.result = Result::missing;
return response;
}
channel.stats.clear();
channel.profile = Profile{};
channel.configured = false;
++channel.generation;
response.generation = channel.generation;
return response;
}
Configuration Ledger::clear(int slot) {
Configuration response;
if (!has_slot(slot)) {
response.result = Result::bad_slot;
return response;
}
Channel& channel = channels_[static_cast<std::size_t>(slot)];
response.generation = channel.generation;
if (!channel.configured) {
response.result = Result::missing;
return response;
}
channel.stats.clear();
return response;
}
Totals Ledger::totals() const {
Totals response;
for (const Channel& channel : channels_) {
if (!channel.configured) {
continue;
}
++response.configured;
response.stats.samples += channel.stats.samples;
response.stats.weight += channel.stats.weight;
response.stats.raw_total += channel.stats.raw_total;
response.stats.mapped_total += channel.stats.mapped_total;
response.stats.clipped += channel.stats.clipped;
}
return response;
}
}