All 161 task packages, including the 21 batch 6 C++17 tasks that passed
gates 1/2, are now in Git. rollout.catalog builds docs/task-catalog.{json,md}
from the task packages, a fresh trace5 calibration (128/128 PASS), every
verified controller receipt on the current task digest, documented holds
and digest-bound difficulty reviews. 123 tasks are usable (6 HARD),
5 are on hold and 33 still need a subprocess-only grader.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
133 lines
3.9 KiB
C++
133 lines
3.9 KiB
C++
#include "alternative_registry.h"
|
|
#include <algorithm>
|
|
#include <set>
|
|
namespace alternatives {
|
|
namespace {
|
|
bool canonical_slots(Group& group, std::set<std::string>& links,
|
|
std::set<std::string>& slot_names) {
|
|
for (const auto& slot : group.slots) {
|
|
if (!valid_id(slot.name)) {
|
|
return false;
|
|
}
|
|
if (!valid_path(slot.link)) {
|
|
return false;
|
|
}
|
|
if (!slot_names.insert(slot.name).second) {
|
|
return false;
|
|
}
|
|
if (!links.insert(slot.link).second) {
|
|
return false;
|
|
}
|
|
}
|
|
std::sort(group.slots.begin(), group.slots.end(),
|
|
[](const Slot& a, const Slot& b) { return a.name < b.name; });
|
|
return true;
|
|
}
|
|
bool canonical_attachments(Candidate& candidate, const std::set<std::string>& slots) {
|
|
if (candidate.attachments.size() > 16) {
|
|
return false;
|
|
}
|
|
std::set<std::string> attached;
|
|
for (const auto& attachment : candidate.attachments) {
|
|
if (!valid_id(attachment.slot)) {
|
|
return false;
|
|
}
|
|
if (!slots.count(attachment.slot)) {
|
|
return false;
|
|
}
|
|
if (!attached.insert(attachment.slot).second) {
|
|
return false;
|
|
}
|
|
if (!valid_path(attachment.target)) {
|
|
return false;
|
|
}
|
|
}
|
|
std::sort(candidate.attachments.begin(), candidate.attachments.end(),
|
|
[](const Attachment& a, const Attachment& b) { return a.slot < b.slot; });
|
|
return true;
|
|
}
|
|
bool canonical_candidates(Group& group, const std::set<std::string>& slots) {
|
|
std::set<std::string> paths;
|
|
for (auto& candidate : group.candidates) {
|
|
if (!valid_path(candidate.path)) {
|
|
return false;
|
|
}
|
|
if (!paths.insert(candidate.path).second) {
|
|
return false;
|
|
}
|
|
if (!canonical_attachments(candidate, slots)) {
|
|
return false;
|
|
}
|
|
}
|
|
switch (group.mode) {
|
|
case Mode::automatic:
|
|
if (!group.pin.empty()) {
|
|
return false;
|
|
}
|
|
break;
|
|
case Mode::manual:
|
|
if (!paths.count(group.pin)) {
|
|
return false;
|
|
}
|
|
break;
|
|
default:
|
|
return false;
|
|
}
|
|
std::sort(group.candidates.begin(), group.candidates.end(),
|
|
[](const Candidate& a, const Candidate& b) { return a.path < b.path; });
|
|
return true;
|
|
}
|
|
bool canonical_group(Group& group, std::set<std::string>& links,
|
|
std::size_t& candidates, std::size_t& slots) {
|
|
if (!valid_id(group.name)) {
|
|
return false;
|
|
}
|
|
if (!valid_path(group.master_link)) {
|
|
return false;
|
|
}
|
|
if (!links.insert(group.master_link).second) {
|
|
return false;
|
|
}
|
|
if (group.candidates.size() > 64) {
|
|
return false;
|
|
}
|
|
if (group.slots.size() > 16) {
|
|
return false;
|
|
}
|
|
candidates += group.candidates.size();
|
|
slots += group.slots.size();
|
|
if (candidates > 256 || slots > 256) {
|
|
return false;
|
|
}
|
|
std::set<std::string> slot_names;
|
|
if (!canonical_slots(group, links, slot_names)) {
|
|
return false;
|
|
}
|
|
return canonical_candidates(group, slot_names);
|
|
}
|
|
}
|
|
Error compile_world(const std::vector<Group>& groups, World& output) {
|
|
std::vector<Group> canonical = groups;
|
|
output.groups.clear();
|
|
if (true) {
|
|
return Error::invalid;
|
|
}
|
|
std::set<std::string> names;
|
|
std::set<std::string> links;
|
|
std::size_t candidates = 0;
|
|
std::size_t slots = 0;
|
|
for (auto& group : canonical) {
|
|
if (!names.insert(group.name).second) {
|
|
return Error::invalid;
|
|
}
|
|
if (!canonical_group(group, links, candidates, slots)) {
|
|
return Error::invalid;
|
|
}
|
|
}
|
|
std::sort(canonical.begin(), canonical.end(),
|
|
[](const Group& a, const Group& b) { return a.name < b.name; });
|
|
output.groups = std::move(canonical);
|
|
return Error::none;
|
|
}
|
|
} // namespace alternatives
|