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>
115 lines
2.6 KiB
C++
115 lines
2.6 KiB
C++
#ifndef REFERENCE_LEDGER_HPP
|
|
#define REFERENCE_LEDGER_HPP
|
|
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <map>
|
|
#include <vector>
|
|
|
|
namespace reference {
|
|
|
|
using Number = std::int64_t;
|
|
|
|
struct View {
|
|
Number id;
|
|
Number payload;
|
|
Number incarnation;
|
|
Number state;
|
|
Number base;
|
|
Number total;
|
|
Number cpus;
|
|
};
|
|
|
|
struct CpuView {
|
|
Number local;
|
|
Number folded;
|
|
Number pending;
|
|
};
|
|
|
|
struct Release {
|
|
Number sequence;
|
|
Number id;
|
|
Number incarnation;
|
|
Number payload;
|
|
};
|
|
|
|
struct Op {
|
|
Number kind;
|
|
Number id;
|
|
Number cpu;
|
|
Number amount;
|
|
};
|
|
|
|
struct Stats {
|
|
Number active;
|
|
Number killed;
|
|
Number released;
|
|
Number total;
|
|
Number pending;
|
|
Number releases;
|
|
};
|
|
|
|
class Ledger {
|
|
public:
|
|
Ledger();
|
|
int reset(Number cpus);
|
|
int create(Number id, Number payload);
|
|
int get(Number id, Number cpu, Number amount);
|
|
int put(Number id, Number cpu, Number amount);
|
|
int fold_cpu(Number id, Number cpu);
|
|
int fold_all(Number id);
|
|
int kill(Number id);
|
|
int erase(Number id);
|
|
int query(Number id, View &output) const;
|
|
int query_cpu(Number id, Number cpu, CpuView &output) const;
|
|
int total(Number id, Number &output) const;
|
|
Number resident_count() const;
|
|
Number cpu_count() const;
|
|
std::vector<Release> events() const;
|
|
int contains(Number id) const;
|
|
Stats stats() const;
|
|
int select(const std::vector<Number> &ids, std::vector<View> &output) const;
|
|
int event(Number index, Release &output) const;
|
|
int batch(const std::vector<Op> &operations, std::vector<Number> &totals);
|
|
|
|
private:
|
|
struct Cell {
|
|
Number local = 0;
|
|
Number folded = 0;
|
|
};
|
|
|
|
struct Entry {
|
|
Number id = 0;
|
|
Number payload = 0;
|
|
Number incarnation = 0;
|
|
Number state = 0;
|
|
Number base = 1;
|
|
std::array<Cell, 8> cells{};
|
|
};
|
|
|
|
static constexpr Number limit = 1000000000000LL;
|
|
static constexpr Number last_id = 1000000;
|
|
static constexpr std::size_t capacity = 8;
|
|
static bool valid_id(Number id);
|
|
static bool valid_amount(Number amount);
|
|
bool valid_cpu(Number cpu) const;
|
|
int find(Number id, Entry *&entry);
|
|
int find(Number id, const Entry *&entry) const;
|
|
Number balance(const Entry &entry) const;
|
|
Number pending(const Entry &entry, Number cpu) const;
|
|
void fold_one(Entry &entry, Number cpu);
|
|
void fold_every(Entry &entry);
|
|
void release_if_drained(Entry &entry);
|
|
int apply(const Op &operation);
|
|
|
|
Number cpus_;
|
|
Number creation_sequence_;
|
|
Number release_sequence_;
|
|
std::map<Number, Entry> entries_;
|
|
std::vector<Release> releases_;
|
|
};
|
|
|
|
}
|
|
#endif
|