amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
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>
2026-10-27 17:52:13 +08:00

114 lines
2.7 KiB
C++

#ifndef PRIORITY_MAILQUEUE_HPP
#define PRIORITY_MAILQUEUE_HPP
#include <cstdint>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <vector>
namespace mq {
using Number = std::uint64_t;
constexpr Number clock_limit = 1000000000000ULL;
struct Config {
Number count = 8;
Number bytes = 1024;
Number body = 256;
Number priority = 31;
};
struct Input {
Number id = 0;
Number priority = 0;
Number ttl = 0;
std::string body;
};
struct Record {
Number id = 0;
Number priority = 0;
Number ticket = 0;
Number expires = 0;
std::string body;
};
struct Edit {
int kind = 0;
Input input;
};
struct Counters {
Number sent = 0;
Number sent_bytes = 0;
Number received = 0;
Number received_bytes = 0;
Number canceled = 0;
Number expired = 0;
Number reprioritized = 0;
Number revision = 0;
};
struct View {
Config config;
Number now = 0;
Number count = 0;
Number bytes = 0;
Number next_ticket = 1;
Counters counters;
bool closed = false;
};
class Mailbox {
public:
Mailbox() = default;
~Mailbox() = default;
Mailbox(const Mailbox &) = default;
Mailbox &operator=(const Mailbox &) = default;
Mailbox(Mailbox &&other) noexcept;
Mailbox &operator=(Mailbox &&other) noexcept;
int configure(const Config &config);
int resize(const Config &config);
void reset();
int send(const Input &input, Number &ticket_out);
int peek(Record &out) const;
int receive(Record &out);
int cancel(Number id);
int reprioritize(Number id, Number priority);
int advance(Number delta);
int inspect_id(Number id, Record &out) const;
int renew(Number id, Number ttl, Number &old_expiry_out);
int cancel_priority(Number priority, std::vector<Number> &ids_out);
void set_closed(bool closed);
bool closed() const;
int drain(Number limit, Number budget, std::vector<Record> &out);
int batch(const std::vector<Edit> &edits, std::vector<Number> &tickets_out);
void snapshot(std::vector<Record> &out) const;
View inspect() const;
private:
Config config_;
Number now_ = 0;
Number used_bytes_ = 0;
Number next_ticket_ = 1;
Counters counters_;
bool closed_ = false;
std::map<Number, std::list<Record>, std::greater<Number>> buckets_;
static int validate(const Config &config);
static void add(Number &counter, Number amount);
Record *find(Number id);
const Record *find(Number id) const;
Number size() const;
int empty_status() const;
void remove(Number id);
void swap_state(Mailbox &other) noexcept;
int apply(const Edit &edit, Number &ticket_out);
};
}
#endif