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

130 lines
3.0 KiB
C

#include "row.h"
#include <stddef.h>
static int field_ok(int field)
{
return field >= 0 && field < ROW_FIELDS;
}
static unsigned count_fields(const Row *row)
{
unsigned count = 0;
int field;
if (row == NULL) return 0;
for (field = 0; field < ROW_FIELDS; ++field) {
if (row->fields[field] != NULL) ++count;
}
return count;
}
void row_init(Row *row)
{
int field;
if (row == NULL) return;
for (field = 0; field < ROW_FIELDS; ++field) row->fields[field] = NULL;
row->occupied = 0;
row->revision = 0;
}
int row_take(Row *row, int field, OwnedValue *incoming)
{
if (incoming == NULL) return -1;
if (row == NULL || !field_ok(field)) {
owned_release(incoming);
return -1;
}
/* The incoming handle is fresh and is not already stored in any row. */
owned_release(row->fields[field]);
row->fields[field] = incoming;
row->occupied = count_fields(row);
++row->revision;
return 0;
}
int row_erase(Row *row, int field)
{
if (row == NULL || !field_ok(field)) return -1;
if (row->fields[field] == NULL) return 1;
owned_release(row->fields[field]);
row->fields[field] = NULL;
row->occupied = count_fields(row);
++row->revision;
return 0;
}
void row_clear(Row *row)
{
int field;
int changed = 0;
if (row == NULL) return;
for (field = 0; field < ROW_FIELDS; ++field) {
if (row->fields[field] != NULL) {
owned_release(row->fields[field]);
row->fields[field] = NULL;
changed = 1;
}
}
row->occupied = 0;
if (changed) ++row->revision;
}
int row_has(const Row *row, int field)
{
if (row == NULL || !field_ok(field)) return 0;
return row->fields[field] != NULL;
}
int row_key(const Row *row, int field)
{
if (row == NULL || !field_ok(field)) return 0;
return owned_key(row->fields[field]);
}
int row_amount(const Row *row, int field)
{
if (row == NULL || !field_ok(field)) return 0;
return owned_amount(row->fields[field]);
}
unsigned row_occupied(const Row *row)
{
return count_fields(row);
}
int64_t row_total(const Row *row)
{
int field;
int64_t total = 0;
if (row == NULL) return 0;
for (field = 0; field < ROW_FIELDS; ++field) {
if (row->fields[field] != NULL) total += owned_amount(row->fields[field]);
}
return total;
}
static uint64_t contribution(const OwnedValue *value, int field)
{
uint64_t key, amount, serial;
if (value == NULL) return 0;
key = (uint64_t)(int64_t)owned_key(value);
amount = (uint64_t)(int64_t)owned_amount(value);
serial = owned_serial(value);
return (uint64_t)(field + 1) * (key * 17u + amount * 31u + serial * 7u);
}
uint64_t row_signature(const Row *row)
{
int field;
uint64_t result = 0;
if (row == NULL) return 0;
for (field = 0; field < ROW_FIELDS; ++field) {
result += contribution(row->fields[field], field);
}
return result;
}
uint64_t row_revision(const Row *row)
{
return row == NULL ? 0 : row->revision;
}