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>
163 lines
4.5 KiB
C
163 lines
4.5 KiB
C
#include "filled_record.h"
|
|
#include <string.h>
|
|
static uint32_t numeric(const uint8_t *data, unsigned size)
|
|
{
|
|
uint32_t value = 0;
|
|
unsigned i;
|
|
for (i = 0; i < size; ++i) {
|
|
value |= (uint32_t)data[i] << (8 * i);
|
|
}
|
|
return value;
|
|
}
|
|
int rf_summarize(const rf_record *record, rf_summary *summary)
|
|
{
|
|
rf_summary temporary;
|
|
unsigned index;
|
|
int result;
|
|
if (summary == NULL) {
|
|
return RF_INVALID;
|
|
}
|
|
result = rf_validate(record);
|
|
if (result != RF_OK) {
|
|
return result;
|
|
}
|
|
memset(&temporary, 0, sizeof(temporary));
|
|
temporary.tag_fold = UINT32_C(2166136261);
|
|
for (index = 0; index < record->items; ++index) {
|
|
unsigned tag;
|
|
unsigned type;
|
|
unsigned size;
|
|
unsigned i;
|
|
const uint8_t *data;
|
|
result = rf_item(record, index, &tag, &type, &data, &size);
|
|
if (result != RF_OK) {
|
|
return result;
|
|
}
|
|
temporary.items += 1;
|
|
temporary.payload_bytes += size;
|
|
temporary.tag_fold = (temporary.tag_fold ^ tag) * UINT32_C(16777619);
|
|
temporary.tag_fold = (temporary.tag_fold ^ type) * UINT32_C(16777619);
|
|
if (type <= 3) {
|
|
temporary.numeric_items += 1;
|
|
temporary.numeric_sum += numeric(data, size);
|
|
} else {
|
|
for (i = 0; i < size; ++i) {
|
|
temporary.binary_xor ^= data[i];
|
|
}
|
|
}
|
|
}
|
|
*summary = temporary;
|
|
return RF_OK;
|
|
}
|
|
int rf_find(const rf_record *record, unsigned tag, unsigned occurrence, unsigned *index)
|
|
{
|
|
unsigned at;
|
|
int result;
|
|
if (tag > 255 || index == NULL) {
|
|
return RF_INVALID;
|
|
}
|
|
result = rf_validate(record);
|
|
if (result != RF_OK) {
|
|
return result;
|
|
}
|
|
for (at = 0; at < record->items; ++at) {
|
|
unsigned item_tag;
|
|
unsigned type;
|
|
unsigned size;
|
|
const uint8_t *data;
|
|
result = rf_item(record, at, &item_tag, &type, &data, &size);
|
|
if (result != RF_OK) {
|
|
return result;
|
|
}
|
|
if (item_tag == tag) {
|
|
if (occurrence == 0) {
|
|
*index = at;
|
|
return RF_OK;
|
|
}
|
|
occurrence -= 1;
|
|
}
|
|
}
|
|
return RF_STATE;
|
|
}
|
|
int rf_project(rf_record *destination, const rf_record *source, unsigned first, unsigned count)
|
|
{
|
|
rf_record temporary;
|
|
unsigned index;
|
|
int result;
|
|
if (destination == NULL) {
|
|
return RF_INVALID;
|
|
}
|
|
result = rf_validate(source);
|
|
if (result != RF_OK) {
|
|
return result;
|
|
}
|
|
if (first > source->items || count > source->items - first) {
|
|
return RF_INVALID;
|
|
}
|
|
result = rf_begin(&temporary, &source->config, source->sequence, source->kind);
|
|
if (result != RF_OK) {
|
|
return result;
|
|
}
|
|
for (index = first; index < first + count; ++index) {
|
|
unsigned tag;
|
|
unsigned type;
|
|
unsigned size;
|
|
const uint8_t *data;
|
|
result = rf_item(source, index, &tag, &type, &data, &size);
|
|
if (result != RF_OK) {
|
|
return result;
|
|
}
|
|
if (type == 1) {
|
|
result = rf_u8(&temporary, tag, numeric(data, size));
|
|
} else if (type == 2) {
|
|
result = rf_u16(&temporary, tag, numeric(data, size));
|
|
} else if (type == 3) {
|
|
result = rf_u32(&temporary, tag, numeric(data, size));
|
|
} else if (type == 4) {
|
|
result = rf_bytes(&temporary, tag, data, size);
|
|
} else {
|
|
result = rf_text(&temporary, tag, data, size);
|
|
}
|
|
if (result != RF_OK) {
|
|
return result;
|
|
}
|
|
}
|
|
result = rf_seal(&temporary);
|
|
if (result != RF_OK) {
|
|
return result;
|
|
}
|
|
*destination = temporary;
|
|
return RF_OK;
|
|
}
|
|
int rf_sum_tag(const rf_record *record, unsigned tag, uint64_t *sum, unsigned *matches)
|
|
{
|
|
uint64_t total = 0;
|
|
unsigned found = 0;
|
|
unsigned index;
|
|
int result;
|
|
if (tag > 255 || sum == NULL || matches == NULL) {
|
|
return RF_INVALID;
|
|
}
|
|
result = rf_validate(record);
|
|
if (result != RF_OK) {
|
|
return result;
|
|
}
|
|
for (index = 0; index < record->items; ++index) {
|
|
unsigned item_tag;
|
|
unsigned type;
|
|
unsigned size;
|
|
const uint8_t *data;
|
|
result = rf_item(record, index, &item_tag, &type, &data, &size);
|
|
if (result != RF_OK) {
|
|
return result;
|
|
}
|
|
if (item_tag == tag && type <= 3) {
|
|
total += numeric(data, size);
|
|
found += 1;
|
|
}
|
|
}
|
|
*sum = total;
|
|
*matches = found;
|
|
return RF_OK;
|
|
}
|