diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-12-28 17:30:04 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-12-28 17:30:04 -0500 |
| commit | fedc4b0ead8f7874120c6e86aaa971a790faea1f (patch) | |
| tree | 2973f9691b72c97a9cc80fd75c4db8e2e2c59e63 /src/stdlib/tables.c | |
| parent | 469030e9686e81c520c2ecbeab703a07361f51a4 (diff) | |
| parent | cfce376f585e0cd0231e95843617f75bd65b6c07 (diff) | |
Merge branch 'dev' into static-dependencies
Diffstat (limited to 'src/stdlib/tables.c')
| -rw-r--r-- | src/stdlib/tables.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/stdlib/tables.c b/src/stdlib/tables.c index 81cccceb..a89ae85f 100644 --- a/src/stdlib/tables.c +++ b/src/stdlib/tables.c @@ -138,7 +138,8 @@ static void Table$set_bucket(Table_t *t, const void *entry, int32_t index, const bucket->occupied = 1; bucket->index = index; bucket->next_bucket = END_OF_CHAIN; - } else { // Collided with the start of a chain, put the new entry in chain position #2 + } else { // Collided with the start of a chain, put the new entry in chain + // position #2 buckets[t->bucket_info->last_free] = (bucket_t){.occupied = 1, .index = index, .next_bucket = bucket->next_bucket}; bucket->next_bucket = t->bucket_info->last_free; @@ -317,7 +318,9 @@ CONSTFUNC public void *Table$entry(Table_t t, int64_t n) { } public -void Table$clear(Table_t *t) { *t = EMPTY_TABLE; } +void Table$clear(Table_t *t) { + *t = EMPTY_TABLE; +} public Table_t Table$sorted(Table_t t, const TypeInfo_t *type) { @@ -536,7 +539,8 @@ Table_t Table$from_entries(List_t entries, const TypeInfo_t *type) { // "set intersection" in formal terms public Table_t Table$intersection(Table_t a, Table_t b, const TypeInfo_t *type) { - // Return a table such that t[k]==a[k] for all k such that a.has(k), b.has(k), and a[k]==b[k] + // Return a table such that t[k]==a[k] for all k such that a.has(k), b.has(k), + // and a[k]==b[k] Table_t result = EMPTY_TABLE; const size_t offset = value_offset(type); for (Table_t *t = &a; t; t = t->fallback) { @@ -554,8 +558,8 @@ Table_t Table$intersection(Table_t a, Table_t b, const TypeInfo_t *type) { // "set union" in formal terms public Table_t Table$with(Table_t a, Table_t b, const TypeInfo_t *type) { - // return a table such that t[k]==b[k] for all k such that b.has(k), and t[k]==a[k] for all k such that a.has(k) and - // not b.has(k) + // return a table such that t[k]==b[k] for all k such that b.has(k), and + // t[k]==a[k] for all k such that a.has(k) and not b.has(k) Table_t result = EMPTY_TABLE; const size_t offset = value_offset(type); for (Table_t *t = &a; t; t = t->fallback) { @@ -597,7 +601,8 @@ Table_t Table$difference(Table_t a, Table_t b, const TypeInfo_t *type) { // "without" is "set difference" in formal terms public Table_t Table$without(Table_t a, Table_t b, const TypeInfo_t *type) { - // Return a table such that t[k]==a[k] for all k such that not b.has(k) or b[k] != a[k] + // Return a table such that t[k]==a[k] for all k such that not b.has(k) or + // b[k] != a[k] Table_t result = EMPTY_TABLE; const size_t offset = value_offset(type); for (Table_t *t = &a; t; t = t->fallback) { @@ -656,12 +661,18 @@ void *Table$str_reserve(Table_t *t, const char *key, const void *value) { } public -void Table$str_set(Table_t *t, const char *key, const void *value) { Table$set(t, &key, &value, &CStrToVoidStarTable); } +void Table$str_set(Table_t *t, const char *key, const void *value) { + Table$set(t, &key, &value, &CStrToVoidStarTable); +} public -void Table$str_remove(Table_t *t, const char *key) { return Table$remove(t, &key, &CStrToVoidStarTable); } +void Table$str_remove(Table_t *t, const char *key) { + return Table$remove(t, &key, &CStrToVoidStarTable); +} -CONSTFUNC public void *Table$str_entry(Table_t t, int64_t n) { return Table$entry(t, n); } +CONSTFUNC public void *Table$str_entry(Table_t t, int64_t n) { + return Table$entry(t, n); +} PUREFUNC public bool Table$is_none(const void *obj, const TypeInfo_t *info) { (void)info; |
