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>
162 lines
3.7 KiB
C
162 lines
3.7 KiB
C
#include "vector.h"
|
|
#include <string.h>
|
|
|
|
static int acceptable(const char *word)
|
|
{
|
|
size_t length;
|
|
if (word == NULL) {
|
|
return 0;
|
|
}
|
|
length = strlen(word);
|
|
return length <= SV_WORD_LIMIT;
|
|
}
|
|
static size_t next_capacity(const struct strvec *v, size_t needed)
|
|
{
|
|
size_t size = v->capacity;
|
|
if (size == 0) {
|
|
size = v->quantum;
|
|
}
|
|
while (size < needed) {
|
|
if (size > SV_LIMIT / 2) {
|
|
size = SV_LIMIT;
|
|
} else {
|
|
size *= 2;
|
|
}
|
|
}
|
|
return size;
|
|
}
|
|
static int reserve(struct strvec *v, size_t needed)
|
|
{
|
|
size_t capacity;
|
|
char **replacement;
|
|
if (needed <= v->capacity) {
|
|
return 0;
|
|
}
|
|
capacity = next_capacity(v, needed);
|
|
replacement = pool_resize(v->pool, v->items,
|
|
capacity * sizeof(*v->items), POOL_ARRAY);
|
|
if (replacement == NULL) {
|
|
return -1;
|
|
}
|
|
v->items = replacement;
|
|
v->capacity = capacity;
|
|
return 0;
|
|
}
|
|
static char *duplicate(struct strvec *v, const char *word)
|
|
{
|
|
size_t bytes = strlen(word) + 1;
|
|
char *copy = pool_allocate(v->pool, bytes, POOL_STRING);
|
|
if (copy != NULL) {
|
|
memcpy(copy, word, bytes);
|
|
}
|
|
return copy;
|
|
}
|
|
void sv_init(struct strvec *v, struct pool *p, size_t quantum)
|
|
{
|
|
v->pool = p;
|
|
v->items = NULL;
|
|
v->count = 0;
|
|
v->capacity = 0;
|
|
v->quantum = quantum;
|
|
}
|
|
int sv_push(struct strvec *v, const char *word)
|
|
{
|
|
char *copy;
|
|
if (!acceptable(word) || v->count == SV_LIMIT) {
|
|
return -2;
|
|
}
|
|
if (reserve(v, v->count + 1) != 0) {
|
|
return -1;
|
|
}
|
|
copy = duplicate(v, word);
|
|
if (copy == NULL) {
|
|
return -1;
|
|
}
|
|
v->items[v->count] = copy;
|
|
v->count++;
|
|
return 0;
|
|
}
|
|
int sv_batch(struct strvec *v, const char *const *words, size_t count)
|
|
{
|
|
size_t checkpoint = v->count;
|
|
size_t cursor;
|
|
if (count > SV_LIMIT - checkpoint || (count && words == NULL)) {
|
|
return -2;
|
|
}
|
|
for (cursor = 0; cursor < count; cursor++) {
|
|
if (!acceptable(words[cursor])) {
|
|
return -2;
|
|
}
|
|
}
|
|
if (count == 0) {
|
|
return 0;
|
|
}
|
|
if (reserve(v, checkpoint + count) != 0) {
|
|
return -1;
|
|
}
|
|
for (cursor = 0; cursor < count; cursor++) {
|
|
char *entry = duplicate(v, words[cursor]);
|
|
if (entry == NULL) {
|
|
while (v->count != checkpoint) {
|
|
v->count--;
|
|
pool_release(v->pool, v->items[v->count]);
|
|
}
|
|
return -1;
|
|
}
|
|
v->items[v->count++] = entry;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int sv_replace(struct strvec *v, size_t index, const char *word)
|
|
{
|
|
char *copy;
|
|
if (index >= v->count || !acceptable(word)) {
|
|
return -2;
|
|
}
|
|
copy = duplicate(v, word);
|
|
if (copy == NULL) {
|
|
return -1;
|
|
}
|
|
pool_release(v->pool, v->items[index]);
|
|
v->items[index] = copy;
|
|
return 0;
|
|
}
|
|
int sv_erase(struct strvec *v, size_t index, size_t count)
|
|
{
|
|
size_t cursor;
|
|
if (index > v->count || count > v->count - index) {
|
|
return -2;
|
|
}
|
|
for (cursor = index; cursor < index + count; cursor++) {
|
|
pool_release(v->pool, v->items[cursor]);
|
|
}
|
|
for (cursor = index + count; cursor < v->count; cursor++) {
|
|
v->items[cursor - count] = v->items[cursor];
|
|
}
|
|
v->count -= count;
|
|
return 0;
|
|
}
|
|
void sv_clear(struct strvec *v)
|
|
{
|
|
size_t index;
|
|
for (index = 0; index < v->count; index++) {
|
|
pool_release(v->pool, v->items[index]);
|
|
}
|
|
v->count = 0;
|
|
}
|
|
void sv_drop(struct strvec *v)
|
|
{
|
|
sv_clear(v);
|
|
pool_release(v->pool, v->items);
|
|
v->items = NULL;
|
|
v->capacity = 0;
|
|
}
|
|
const char *sv_at(const struct strvec *v, size_t index)
|
|
{
|
|
if (index >= v->count) {
|
|
return NULL;
|
|
}
|
|
return v->items[index];
|
|
}
|