100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth range given to batch 22), each with at least one independent contract-edge defect and plain public docs. Claude reviewed 100/100 USABLE against current digests; no ID or source overlap with main or batch 22. Difficulty is unmeasured. progress.md records the wrap-up: all Codex sessions and Qwen schedulers stopped for the user's rollout, Qwen results so far (57 HARD of 373), and what is left on each batch branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
2.5 KiB
C++
90 lines
2.5 KiB
C++
#include "durable.hpp"
|
|
namespace durable {
|
|
void Histories::attach(int id, Number generation, int topic, int durability, int depth)
|
|
{
|
|
const Key key{id, generation};
|
|
HistoryEntry entry;
|
|
entry.topic = topic;
|
|
entry.durability = durability;
|
|
entry.depth = depth;
|
|
entries_.emplace(key, std::move(entry));
|
|
}
|
|
void Histories::release(int id, Number generation)
|
|
{
|
|
const Key key{id, generation};
|
|
auto found = entries_.find(key);
|
|
if (found != entries_.end()) {
|
|
entries_.erase(found);
|
|
}
|
|
}
|
|
void Histories::remember(const Sample &sample)
|
|
{
|
|
const Key key{static_cast<int>(sample.writer), sample.generation};
|
|
auto found = entries_.find(key);
|
|
if (found == entries_.end()) {
|
|
return;
|
|
}
|
|
HistoryEntry &entry = found->second;
|
|
if (entry.durability == 0) {
|
|
return;
|
|
}
|
|
if (entry.samples.size() < static_cast<std::size_t>(entry.depth)) {
|
|
entry.samples.push_back(sample);
|
|
}
|
|
}
|
|
void Histories::resize(int id, Number generation, int depth)
|
|
{
|
|
const Key key{id, generation};
|
|
auto found = entries_.find(key);
|
|
if (found == entries_.end()) {
|
|
return;
|
|
}
|
|
HistoryEntry &entry = found->second;
|
|
entry.depth = depth;
|
|
while (entry.samples.size() > static_cast<std::size_t>(depth)) {
|
|
entry.samples.pop_front();
|
|
}
|
|
}
|
|
std::vector<Sample> Histories::read(int id, Number generation) const
|
|
{
|
|
const Key key{id, generation};
|
|
const auto found = entries_.find(key);
|
|
if (found == entries_.end()) {
|
|
return {};
|
|
}
|
|
const auto &samples = found->second.samples;
|
|
return std::vector<Sample>(samples.begin(), samples.end());
|
|
}
|
|
std::vector<Sample> Histories::replay(int topic) const
|
|
{
|
|
std::vector<Sample> result;
|
|
for (const auto &item : entries_) {
|
|
const HistoryEntry &entry = item.second;
|
|
if (entry.topic != topic || entry.durability == 0) {
|
|
continue;
|
|
}
|
|
for (const Sample &stored : entry.samples) {
|
|
Sample delivered = stored;
|
|
delivered.replayed = 1;
|
|
result.push_back(delivered);
|
|
}
|
|
}
|
|
std::sort(result.begin(), result.end(), [](const Sample &left, const Sample &right) {
|
|
return left.sequence < right.sequence;
|
|
});
|
|
return result;
|
|
}
|
|
Number Histories::count() const
|
|
{
|
|
Number total = 0;
|
|
for (const auto &item : entries_) {
|
|
total += static_cast<Number>(item.second.samples.size());
|
|
}
|
|
return total;
|
|
}
|
|
void Histories::reset()
|
|
{
|
|
entries_.clear();
|
|
}
|
|
}
|