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

108 lines
3.8 KiB
C++

#ifndef TILE_CACHE_HPP
#define TILE_CACHE_HPP
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
namespace tile {
using Numbers = std::vector<long long>;
struct Ledger {
long long created = 0;
long long destroyed = 0;
long long live_bytes = 0;
std::vector<long long> deaths;
long long allocate(std::size_t length);
void resized(std::size_t before, std::size_t after);
void release(long long serial, std::size_t length);
long long live() const;
};
class Payload {
public:
Payload(std::shared_ptr<Ledger> ledger, std::size_t size, unsigned seed);
~Payload();
Payload(const Payload&) = delete;
Payload& operator=(const Payload&) = delete;
long long serial() const;
std::size_t size() const;
long long checksum() const;
bool same_bytes(const Payload& other) const;
bool write(std::size_t offset, unsigned value);
bool fill(std::size_t offset, std::size_t count, unsigned value);
void resize(std::size_t length, unsigned seed);
bool read(std::size_t offset, std::size_t count, Numbers& output) const;
bool copy_range(std::size_t source_offset, Payload& target, std::size_t target_offset, std::size_t count) const;
private:
static unsigned char pattern(std::size_t index, unsigned seed);
std::shared_ptr<Ledger> ledger_;
std::vector<unsigned char> bytes_;
long long serial_;
};
struct Key {
std::string tenant;
std::string name;
bool operator<(const Key& other) const;
};
struct Entry {
Key key;
std::weak_ptr<Payload> observed;
std::shared_ptr<Payload> retained;
};
class Registry {
public:
std::shared_ptr<Payload> find(const Key& key) const;
void store(const Key& key, const std::shared_ptr<Payload>& object);
std::size_t erase(const Key& key);
std::size_t retire(const std::string& tenant);
std::size_t clear();
std::size_t sweep();
std::array<long long, 3> counts() const;
private:
static Key index_key(const Key& key);
std::map<Key, Entry> entries_;
};
class Service {
public:
Service();
Numbers acquire(std::size_t slot, const Key& key, std::size_t size, unsigned seed);
Numbers lookup(std::size_t slot, const Key& key);
Numbers copy(std::size_t source, std::size_t destination);
Numbers move(std::size_t source, std::size_t destination);
Numbers drop(std::size_t slot);
Numbers drop_all();
Numbers view(std::size_t slot) const;
Numbers owners(std::size_t slot) const;
Numbers write(std::size_t slot, std::size_t offset, unsigned value);
Numbers fill(std::size_t slot, std::size_t offset, std::size_t count, unsigned value);
Numbers resize(std::size_t slot, std::size_t length, unsigned seed);
Numbers read(std::size_t slot, std::size_t offset, std::size_t count) const;
Numbers copy_range(std::size_t source, std::size_t source_offset, std::size_t destination, std::size_t destination_offset, std::size_t count);
Numbers swap(std::size_t left, std::size_t right);
Numbers compare(std::size_t left, std::size_t right) const;
Numbers erase(const Key& key);
Numbers retire(const std::string& tenant);
Numbers clear();
Numbers sweep();
Numbers cache() const;
Numbers stats() const;
Numbers deaths() const;
Numbers execute(const std::string& line);
private:
static Numbers missing();
static Numbers invalid();
static Numbers object_result(const std::shared_ptr<Payload>& object);
std::size_t occupied() const;
std::shared_ptr<Ledger> ledger_;
Registry registry_;
std::array<std::shared_ptr<Payload>, 32> slots_;
};
std::vector<std::string> tokenize(const std::string& line);
bool decimal(const std::string& token, unsigned long long maximum, unsigned long long& value);
bool name_valid(const std::string& token);
}
#endif