VecAt
Description
Element at idx accessed by value. Use this rather than indexing data directly so element alignment is respected.
Parameters
| Name | Direction | Description |
|---|---|---|
v |
in | Vector to query. |
idx |
in | Index in [0, length). |
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Graph.c:200:
for (idx = 0; idx < VecLen(neighbors); idx++) {
if (VecAt(neighbors, idx) == node_id) {
return true;
}- In
Graph.c:212:
for (idx = 0; idx < VecLen(neighbors); idx++) {
if (VecAt(neighbors, idx) == node_id) {
return idx;
}- In
Graph.c:264:
while (idx < VecLen(neighbors)) {
GraphNodeId neighbor_id = VecAt(neighbors, idx);
const GenericGraphSlot *slot;- In
Graph.c:378:
for (neighbor_i = 0; neighbor_i < VecLen(&slot->out_neighbors); neighbor_i++) {
GraphNodeId neighbor_id = VecAt(&slot->out_neighbors, neighbor_i);
const GenericGraphSlot *target_slot;- In
Graph.c:389:
for (neighbor_i = 0; neighbor_i < VecLen(&slot->in_neighbors); neighbor_i++) {
GraphNodeId predecessor_id = VecAt(&slot->in_neighbors, neighbor_i);
const GenericGraphSlot *source_slot;- In
Graph.c:418:
for (free_index_i = 0; free_index_i < VecLen(&graph->free_indices); free_index_i++) {
u32 index = VecAt(&graph->free_indices, free_index_i);
if ((u64)index >= VecLen(&graph->slots)) {
LOG_FATAL("Graph free slot index out of bounds");- In
Graph.c:698:
}
return VecAt(neighbors, neighbor_idx);
}- In
Graph.c:712:
}
return VecAt(neighbors, predecessor_idx);
}- In
Graph.c:1027:
while (iter->neighbor_index < VecLen(neighbors)) {
GraphNodeId neighbor_id = VecAt(neighbors, iter->neighbor_index);
iter->neighbor_index += 1;- In
Graph.c:1074:
while (iter->predecessor_index < VecLen(neighbors)) {
GraphNodeId predecessor_id = VecAt(neighbors, iter->predecessor_index);
iter->predecessor_index += 1;- In
Dns.c:631:
bool have_one = ok && VecLen(&addrs) > 0;
if (have_one) {
*out = VecAt(&addrs, 0);
}
VecDeinit(&addrs);- In
Dwarf.c:315:
u64 dir_off = 0;
if (st->file >= 1 && st->file - 1 < VecLen(&cs->file_offsets)) {
file_off = VecAt(&cs->file_offsets, st->file - 1);
u64 dir_idx = VecAt(&cs->file_dir_idx, st->file - 1);
if (dir_idx >= 1 && dir_idx - 1 < VecLen(&cs->dir_offsets)) {- In
Dwarf.c:316:
if (st->file >= 1 && st->file - 1 < VecLen(&cs->file_offsets)) {
file_off = VecAt(&cs->file_offsets, st->file - 1);
u64 dir_idx = VecAt(&cs->file_dir_idx, st->file - 1);
if (dir_idx >= 1 && dir_idx - 1 < VecLen(&cs->dir_offsets)) {
dir_off = VecAt(&cs->dir_offsets, dir_idx - 1);- In
Dwarf.c:318:
u64 dir_idx = VecAt(&cs->file_dir_idx, st->file - 1);
if (dir_idx >= 1 && dir_idx - 1 < VecLen(&cs->dir_offsets)) {
dir_off = VecAt(&cs->dir_offsets, dir_idx - 1);
}
}- In
Dwarf.c:641:
if (ok) {
for (u64 i = 0; i < VecLen(&out->entries); ++i) {
u64 fo = VecAt(&pending_file_offsets, i);
u64 dofs = VecAt(&pending_dir_offsets, i);
VecPtrAt(&out->entries, i)->file = fo ? (Zstr)(StrBegin(&out->string_pool) + fo) : NULL;- In
Dwarf.c:642:
for (u64 i = 0; i < VecLen(&out->entries); ++i) {
u64 fo = VecAt(&pending_file_offsets, i);
u64 dofs = VecAt(&pending_dir_offsets, i);
VecPtrAt(&out->entries, i)->file = fo ? (Zstr)(StrBegin(&out->string_pool) + fo) : NULL;
VecPtrAt(&out->entries, i)->dir = dofs ? (Zstr)(StrBegin(&out->string_pool) + dofs) : NULL;- In
Pdb.c:434:
if (!stream_read(self, DBI_STREAM_INDEX, sec_hdr_off, VecBegin(&sh), 2))
break;
r.section_hdr_stream = (u16)VecAt(&sh, 0) | (u16)VecAt(&sh, 1) << 8;
r.ok = true;
}- In
VecCharPtr.c:126:
if (VecLen(vec) > 0 && *offset + 4 <= data_size) {
size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
char *str = VecAt(vec, index);
(void)str; // Use the result to avoid warnings
}- In
VecCharPtr.c:179:
char *str = generate_cstring(data, offset, data_size, 16);
if (str) {
VecAt(vec, i) = (char *)ZstrDup(str, (Allocator *)alloc);
cleanup_cstring(str);
}- In
VecStr.c:148:
if (VecLen(vec) > 0 && *offset + 4 <= data_size) {
size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
Str str = VecAt(vec, index);
(void)str; // Use the result to avoid warnings
}- In
VecStr.c:195:
for (size_t i = old_size; i < new_size; i++) {
Str str = generate_str_from_input(data, offset, data_size, 16, alloc);
VecAt(vec, i) = str;
}
}- In
VecInt.c:94:
uint16_t idx = extract_u16(data, offset, data_size);
if (idx < VecLen(vec)) {
volatile i32 value = VecAt(vec, idx);
(void)value; // Prevent optimization
} });
if (obj.x_value == 1 && VecLen(&obj.filled_items) == 2 && VecAt(&obj.filled_items, 0) == 1 &&
VecAt(&obj.filled_items, 1) == 2) {
WriteFmt(
if (obj.x_value == 1 && VecLen(&obj.filled_items) == 2 && VecAt(&obj.filled_items, 0) == 1 &&
VecAt(&obj.filled_items, 1) == 2) {
WriteFmt(
"[DEBUG] Mixed empty and filled test passed - x: {}, items: {}\n", );
if (VecLen(&obj.filled_items) > 0) {
WriteFmt("[DEBUG] First item: {}\n", VecAt(&obj.filled_items, 0));
}
success = false; // Write dynamic key for source function ID
Str source_key = StrInit(&alloc);
u64 source_id = VecLen(&response.data) > 0 ? VecAt(&response.data, 0).source_function_id : 0;
StrAppendFmt(&source_key, "{}", source_id); JW_OBJ_KV(json, StrBegin(&source_key), {
if (VecLen(&response.data) > 0) {
AnnSymbol *s = &VecAt(&response.data, 0);
Str target_key = StrInit(&alloc);
StrAppendFmt(&target_key, "{}", s->target_function_id);
if (VecLen(&symbols) >= 2) {
AnnSymbol *sym1 = &VecAt(&symbols, 0);
AnnSymbol *sym2 = &VecAt(&symbols, 1); if (VecLen(&symbols) >= 2) {
AnnSymbol *sym1 = &VecAt(&symbols, 0);
AnnSymbol *sym2 = &VecAt(&symbols, 1);
if (!(sym1->source_function_id == 12345 || sym1->source_function_id == 54321)) {
if (VecLen(&response.data) > 0) {
AnnSymbol *sym = &VecAt(&response.data, 0);
// Debug individual symbol checks
if (VecLen(&response.data) > 0) {
AnnSymbol *sym = &VecAt(&response.data, 0);
if (sym->source_function_id != 12345) {
if (VecLen(&response.data) > 0) {
AnnSymbol *sym = &VecAt(&response.data, 0);
if (sym->source_function_id != 12345) {
if (VecLen(&languages) >= 3) {
Str *lang1 = &VecAt(&languages, 0);
Str *lang2 = &VecAt(&languages, 1);
Str *lang3 = &VecAt(&languages, 2); if (VecLen(&languages) >= 3) {
Str *lang1 = &VecAt(&languages, 0);
Str *lang2 = &VecAt(&languages, 1);
Str *lang3 = &VecAt(&languages, 2); Str *lang1 = &VecAt(&languages, 0);
Str *lang2 = &VecAt(&languages, 1);
Str *lang3 = &VecAt(&languages, 2);
if (StrCmp(lang1, "C", 1) != 0) {
if (VecLen(&product.tags) >= 3) {
Str *tag1 = &VecAt(&product.tags, 0);
Str *tag2 = &VecAt(&product.tags, 1);
Str *tag3 = &VecAt(&product.tags, 2); if (VecLen(&product.tags) >= 3) {
Str *tag1 = &VecAt(&product.tags, 0);
Str *tag2 = &VecAt(&product.tags, 1);
Str *tag3 = &VecAt(&product.tags, 2); Str *tag1 = &VecAt(&product.tags, 0);
Str *tag2 = &VecAt(&product.tags, 1);
Str *tag3 = &VecAt(&product.tags, 2);
if (StrCmp(tag1, "electronics", 11) != 0) {- In
RoundTrip.c:81:
for (size i = 0; i < VecLen(&a->features); i++) {
if (StrCmp((Str *)&VecAt(&a->features, i), (Str *)&VecAt(&b->features, i)) != 0) {
return false;
}- In
RoundTrip.c:419:
if (numbers_match) {
for (size i = 0; i < VecLen(&original_numbers); i++) {
if (VecAt(&original_numbers, i) != VecAt(&parsed_numbers, i)) {
numbers_match = false;
break;- In
RoundTrip.c:630:
if (numbers_match) {
for (size i = 0; i < VecLen(&original.numbers); i++) {
if (VecAt(&original.numbers, i) != VecAt(&parsed.numbers, i)) {
numbers_match = false;
break;- In
RoundTrip.c:640:
if (flags_match) {
for (size i = 0; i < VecLen(&original.flags); i++) {
if (VecAt(&original.flags, i) != VecAt(&parsed.flags, i)) {
flags_match = false;
break; }
ok = ok && (VecLen(&v) == 1024) && (VecAt(&v, 0) == 0) && (VecAt(&v, 1023) == 1023);
VecDeinit(&v);
PageAllocatorDeinit(&alloc);- In
Vec.Ops.c:48:
// Check that the elements were swapped
bool result = (VecAt(&vec, 0) == 50 && VecAt(&vec, 4) == 10);
// Swap two elements in the middle
- In
Vec.Ops.c:54:
// Check that the elements were swapped
result = result && (VecAt(&vec, 1) == 40 && VecAt(&vec, 3) == 20);
// Check that the middle element is unchanged
- In
Vec.Ops.c:57:
// Check that the middle element is unchanged
result = result && (VecAt(&vec, 2) == 30);
// Clean up
- In
Vec.Ops.c:85:
bool result = true;
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[4 - i]);
}- In
Vec.Ops.c:93:
// Check that the elements are back in the original order
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[i]);
}- In
Vec.Ops.c:108:
// Check that the elements are reversed
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == even_values[3 - i]);
}- In
Vec.Ops.c:138:
int sorted_asc[] = {10, 20, 30, 40, 50};
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == sorted_asc[i]);
}- In
Vec.Ops.c:147:
int sorted_desc[] = {50, 40, 30, 20, 10};
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == sorted_desc[i]);
}- In
Vec.Foreach.c:60:
// Check that the values in the vector are unchanged (foreach uses value, not reference)
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[i]);
} bool result = true;
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[i] * 2);
} bool result = true;
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == i);
} VecForeachReverseIdx(&vec, item, idx) {
result = result && (item == values[idx]);
result = result && (VecAt(&vec, idx) == item);
} bool result = true;
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected[i]);
} bool result = true;
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected[i]);
} result = result && VecLen(&matches) == 5;
if (result) {
result = result && VecAt(&matches, 0) == 0;
result = result && VecAt(&matches, 1) == 2;
result = result && VecAt(&matches, 2) == 4; if (result) {
result = result && VecAt(&matches, 0) == 0;
result = result && VecAt(&matches, 1) == 2;
result = result && VecAt(&matches, 2) == 4;
result = result && VecAt(&matches, 3) == 6; result = result && VecAt(&matches, 0) == 0;
result = result && VecAt(&matches, 1) == 2;
result = result && VecAt(&matches, 2) == 4;
result = result && VecAt(&matches, 3) == 6;
result = result && VecAt(&matches, 4) == 8; result = result && VecAt(&matches, 1) == 2;
result = result && VecAt(&matches, 2) == 4;
result = result && VecAt(&matches, 3) == 6;
result = result && VecAt(&matches, 4) == 8;
} result = result && VecAt(&matches, 2) == 4;
result = result && VecAt(&matches, 3) == 6;
result = result && VecAt(&matches, 4) == 8;
} }
ok = ok && VecLen(&v) == 4096 && VecAt(&v, 0) == 0 && VecAt(&v, 4095) == 4095;
VecDeinit(&v);
ArenaAllocatorDeinit(&arena);- In
Vec.Init.c:228:
VecPushBackR(&vec, 30);
if (VecLen(&vec) != 3 || VecAt(&vec, 0) != 10 || VecAt(&vec, 1) != 20 || VecAt(&vec, 2) != 30) {
result = false;
}- In
Vec.Init.c:245:
VecPushBackR(&test_vec, item);
if (VecLen(&test_vec) != 1 || VecAt(&test_vec, 0).id != 1 || VecAt(&test_vec, 0).value != 3.14f) {
result = false;
}- In
Vec.Init.c:263:
AlignedItem item = {.a = 7, .b = 2.71828};
VecPushBackR(&av, item);
if (VecLen(&av) != 1 || VecAt(&av, 0).a != 7 || VecAt(&av, 0).b != 2.71828) {
result = false;
}- In
Vec.Init.c:308:
if (result) {
for (size i = 0; i < VecLen(&src); i++) {
if (VecAt(&clone, i) != VecAt(&src, i)) {
result = false;
break;- In
Vec.Memory.c:45:
// Check that the data is still intact
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[i]);
}- In
Vec.Memory.c:82:
// First 3 elements should be unchanged
for (size i = 0; i < 3; i++) {
result = result && (VecAt(&vec, i) == values[i]);
}- In
Vec.Memory.c:93:
// First 3 elements should still be the same
for (size i = 0; i < 3; i++) {
result = result && (VecAt(&vec, i) == values[i]);
}- In
Vec.Remove.c:59:
// Check remaining elements
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[i]);
}- In
Vec.Remove.c:107:
// Check remaining elements
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[i + 1]);
}- In
Vec.Remove.c:152:
int expected1[] = {10, 20, 40, 50};
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected1[i]);
}- In
Vec.Remove.c:164:
int expected2[] = {20, 40, 50};
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected2[i]);
}- In
Vec.Remove.c:201:
int expected[] = {10, 50, 30, 40};
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected[i]);
}- In
Vec.Remove.c:237:
int expected[] = {10, 20, 60, 70};
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected[i]);
}- In
Vec.Remove.c:266:
WriteFmt("Before fast range delete: ");
for (u64 i = 0; i < VecLen(&vec); i++) {
WriteFmt("{} ", VecAt(&vec, i));
}
WriteFmt("\n");- In
Vec.Remove.c:277:
int end_values[3];
for (int i = 0; i < count; i++) {
end_values[i] = VecAt(&vec, VecLen(&vec) - count + i);
}- In
Vec.Remove.c:285:
WriteFmt("After fast range delete: ");
for (u64 i = 0; i < VecLen(&vec); i++) {
WriteFmt("{} ", VecAt(&vec, i));
}
WriteFmt("\n");- In
Vec.Remove.c:294:
// Check that the last 3 elements moved to the deleted positions
for (int i = 0; i < count; i++) {
result = result && (VecAt(&vec, start_index + i) == end_values[i]);
}- In
Vec.Remove.c:300:
bool values_found[10] = {false};
for (u64 i = 0; i < VecLen(&vec); i++) {
int val = VecAt(&vec, i);
int index = val / 10;
if (index >= 0 && index < 10) {- In
Vec.Remove.c:348:
// Check remaining elements
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[i]);
}- In
Vec.Remove.c:359:
// Check remaining elements
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[i]);
}- In
Vec.Remove.c:395:
int expected[] = {10, 20, 40, 50};
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected[i]);
}- In
Vec.Remove.c:430:
int expected[] = {10, 20, 40, 50};
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected[i]);
}- In
Vec.Remove.c:459:
WriteFmt("Before L-value fast delete: ");
for (u64 i = 0; i < VecLen(&vec); i++) {
WriteFmt("{} ", VecAt(&vec, i));
}
WriteFmt("\n");- In
Vec.Remove.c:465:
// Test L-value fast delete operation
int fast_index = 2; // Delete 30
int valueToBeDeleted = VecAt(&vec, fast_index);
int lastValue = VecAt(&vec, VecLen(&vec) - 1); // Should move to deleted position
VecDeleteFast(&vec, fast_index);- In
Vec.Remove.c:466:
int fast_index = 2; // Delete 30
int valueToBeDeleted = VecAt(&vec, fast_index);
int lastValue = VecAt(&vec, VecLen(&vec) - 1); // Should move to deleted position
VecDeleteFast(&vec, fast_index);- In
Vec.Remove.c:472:
WriteFmt("After L-value fast delete: ");
for (u64 i = 0; i < VecLen(&vec); i++) {
WriteFmt("{} ", VecAt(&vec, i));
}
WriteFmt("\n");- In
Vec.Remove.c:482:
bool containsValue = false;
for (u64 i = 0; i < VecLen(&vec); i++) {
if (VecAt(&vec, i) == valueToBeDeleted) {
containsValue = true;
break;- In
Vec.Remove.c:490:
// Check that the value at the deleted position is now the last value
result = result && (VecAt(&vec, fast_index) == lastValue);
WriteFmtLn(
"Value at deleted position ({}) is now {} (expected {})\n",- In
Vec.Remove.c:494:
"Value at deleted position ({}) is now {} (expected {})\n",
fast_index,
VecAt(&vec, fast_index),
lastValue
);- In
Vec.Remove.c:503:
bool found = false;
for (u64 j = 0; j < VecLen(&vec); j++) {
if (VecAt(&vec, j) == expected_values[i]) {
found = true;
break;- In
Vec.Remove.c:540:
WriteFmt("Before R-value fast delete: ");
for (u64 i = 0; i < VecLen(&vec); i++) {
WriteFmt("{} ", VecAt(&vec, i));
}
WriteFmt("\n");- In
Vec.Remove.c:545:
// Remember the value to be deleted and the last value
int valueToBeDeleted = VecAt(&vec, 2); // 30
int lastValue = VecAt(&vec, VecLen(&vec) - 1); // Should move to deleted position
- In
Vec.Remove.c:546:
// Remember the value to be deleted and the last value
int valueToBeDeleted = VecAt(&vec, 2); // 30
int lastValue = VecAt(&vec, VecLen(&vec) - 1); // Should move to deleted position
// Test R-value fast delete operation
- In
Vec.Remove.c:554:
WriteFmt("After R-value fast delete: ");
for (u64 i = 0; i < VecLen(&vec); i++) {
WriteFmt("{} ", VecAt(&vec, i));
}
WriteFmt("\n");- In
Vec.Remove.c:564:
bool containsValue = false;
for (u64 i = 0; i < VecLen(&vec); i++) {
if (VecAt(&vec, i) == valueToBeDeleted) {
containsValue = true;
break;- In
Vec.Remove.c:572:
// Check that the value at the deleted position is now the last value
result = result && (VecAt(&vec, 2) == lastValue);
WriteFmtLn("Value at deleted position (2) is now {} (expected {})\n", VecAt(&vec, 2), lastValue);- In
Vec.Remove.c:573:
// Check that the value at the deleted position is now the last value
result = result && (VecAt(&vec, 2) == lastValue);
WriteFmtLn("Value at deleted position (2) is now {} (expected {})\n", VecAt(&vec, 2), lastValue);
// Verify all expected values (except the deleted one and the moved one) are still present
- In
Vec.Remove.c:580:
bool found = false;
for (u64 j = 0; j < VecLen(&vec); j++) {
if (VecAt(&vec, j) == expected_values[i]) {
found = true;
break;- In
Vec.Remove.c:625:
int expected[] = {10, 20, 60, 70};
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected[i]);
}- In
Vec.Remove.c:660:
int expected[] = {10, 20, 60, 70};
for (u64 i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected[i]);
}- In
Vec.Remove.c:689:
WriteFmt("Before L-value fast range delete: ");
for (u64 i = 0; i < VecLen(&vec); i++) {
WriteFmt("{} ", VecAt(&vec, i));
}
WriteFmt("\n");- In
Vec.Remove.c:704:
WriteFmt("After L-value fast range delete: ");
for (u64 i = 0; i < VecLen(&vec); i++) {
WriteFmt("{} ", VecAt(&vec, i));
}
WriteFmt("\n");- In
Vec.Remove.c:715:
bool found = false;
for (u64 j = 0; j < VecLen(&vec); j++) {
if (VecAt(&vec, j) == valuesToDelete[i]) {
found = true;
break;- In
Vec.Remove.c:731:
bool found = false;
for (u64 j = 0; j < VecLen(&vec); j++) {
if (VecAt(&vec, j) == remainingValues[i]) {
found = true;
break;- In
Vec.Remove.c:768:
WriteFmt("Before R-value fast range delete: ");
for (u64 i = 0; i < VecLen(&vec); i++) {
WriteFmt("{} ", VecAt(&vec, i));
}
WriteFmt("\n");- In
Vec.Remove.c:781:
WriteFmt("After R-value fast range delete: ");
for (u64 i = 0; i < VecLen(&vec); i++) {
WriteFmt("{} ", VecAt(&vec, i));
}
WriteFmt("\n");- In
Vec.Remove.c:792:
bool found = false;
for (u64 j = 0; j < VecLen(&vec); j++) {
if (VecAt(&vec, j) == valuesToDelete[i]) {
found = true;
break;- In
Vec.Remove.c:808:
bool found = false;
for (u64 j = 0; j < VecLen(&vec); j++) {
if (VecAt(&vec, j) == remainingValues[i]) {
found = true;
break;- In
Str.Type.c:64:
// Check the content of the strings
if (result) {
Str *str1 = &VecAt(&sv, 0);
Str *str2 = &VecAt(&sv, 1);- In
Str.Type.c:65:
if (result) {
Str *str1 = &VecAt(&sv, 0);
Str *str2 = &VecAt(&sv, 1);
result = result && (ZstrCompare(StrBegin(str1), "Hello") == 0);
// Check that the item was copied correctly
result = result && ComplexItemsEqual(&VecAt(&vec, 0), &item);
// Modify the original item and verify the vector's copy is independent
// The vector's copy should still have the original values
result = result && (ZstrCompare(VecAt(&vec, 0).name, "Test Item") == 0);
result = result && (VecAt(&vec, 0).values[0] == 1); // The vector's copy should still have the original values
result = result && (ZstrCompare(VecAt(&vec, 0).name, "Test Item") == 0);
result = result && (VecAt(&vec, 0).values[0] == 1);
// Clean up
// Check items order: item2, item1, item3
result = result && (ZstrCompare(VecAt(&vec, 0).name, "Item 2") == 0);
result = result && (ZstrCompare(VecAt(&vec, 1).name, "Item 1") == 0);
result = result && (ZstrCompare(VecAt(&vec, 2).name, "Item 3") == 0); // Check items order: item2, item1, item3
result = result && (ZstrCompare(VecAt(&vec, 0).name, "Item 2") == 0);
result = result && (ZstrCompare(VecAt(&vec, 1).name, "Item 1") == 0);
result = result && (ZstrCompare(VecAt(&vec, 2).name, "Item 3") == 0); result = result && (ZstrCompare(VecAt(&vec, 0).name, "Item 2") == 0);
result = result && (ZstrCompare(VecAt(&vec, 1).name, "Item 1") == 0);
result = result && (ZstrCompare(VecAt(&vec, 2).name, "Item 3") == 0);
// Check values
// Check values
result = result && (VecAt(&vec, 0).values[0] == 40);
result = result && (VecAt(&vec, 1).values[0] == 10);
result = result && (VecAt(&vec, 2).values[0] == 70); // Check values
result = result && (VecAt(&vec, 0).values[0] == 40);
result = result && (VecAt(&vec, 1).values[0] == 10);
result = result && (VecAt(&vec, 2).values[0] == 70); result = result && (VecAt(&vec, 0).values[0] == 40);
result = result && (VecAt(&vec, 1).values[0] == 10);
result = result && (VecAt(&vec, 2).values[0] == 70);
// Clean up
// Check items order: item2, item3, item1
result = result && (ZstrCompare(VecAt(&vec, 0).name, "Item 2") == 0);
result = result && (ZstrCompare(VecAt(&vec, 1).name, "Item 3") == 0);
result = result && (ZstrCompare(VecAt(&vec, 2).name, "Item 1") == 0); // Check items order: item2, item3, item1
result = result && (ZstrCompare(VecAt(&vec, 0).name, "Item 2") == 0);
result = result && (ZstrCompare(VecAt(&vec, 1).name, "Item 3") == 0);
result = result && (ZstrCompare(VecAt(&vec, 2).name, "Item 1") == 0); result = result && (ZstrCompare(VecAt(&vec, 0).name, "Item 2") == 0);
result = result && (ZstrCompare(VecAt(&vec, 1).name, "Item 3") == 0);
result = result && (ZstrCompare(VecAt(&vec, 2).name, "Item 1") == 0);
// Clean up
// Check items in vec1: item1, item2, item3
result = result && (ZstrCompare(VecAt(&vec1, 0).name, "Item 1") == 0);
result = result && (ZstrCompare(VecAt(&vec1, 1).name, "Item 2") == 0);
result = result && (ZstrCompare(VecAt(&vec1, 2).name, "Item 3") == 0); // Check items in vec1: item1, item2, item3
result = result && (ZstrCompare(VecAt(&vec1, 0).name, "Item 1") == 0);
result = result && (ZstrCompare(VecAt(&vec1, 1).name, "Item 2") == 0);
result = result && (ZstrCompare(VecAt(&vec1, 2).name, "Item 3") == 0); result = result && (ZstrCompare(VecAt(&vec1, 0).name, "Item 1") == 0);
result = result && (ZstrCompare(VecAt(&vec1, 1).name, "Item 2") == 0);
result = result && (ZstrCompare(VecAt(&vec1, 2).name, "Item 3") == 0);
// Now test VecMergeL which transfers ownership
// Check items in vec3: item4, item5
result = result && (ZstrCompare(VecAt(&vec3, 0).name, "Item 4") == 0);
result = result && (ZstrCompare(VecAt(&vec3, 1).name, "Item 5") == 0); // Check items in vec3: item4, item5
result = result && (ZstrCompare(VecAt(&vec3, 0).name, "Item 4") == 0);
result = result && (ZstrCompare(VecAt(&vec3, 1).name, "Item 5") == 0);
// Clean up
// Check items order: val2, val3, val1
result = result && (VecAt(&vec, 0) == 20);
result = result && (VecAt(&vec, 1) == 30);
result = result && (VecAt(&vec, 2) == 10); // Check items order: val2, val3, val1
result = result && (VecAt(&vec, 0) == 20);
result = result && (VecAt(&vec, 1) == 30);
result = result && (VecAt(&vec, 2) == 10); result = result && (VecAt(&vec, 0) == 20);
result = result && (VecAt(&vec, 1) == 30);
result = result && (VecAt(&vec, 2) == 10);
// Test array operations
// Check items: val2, val3, val1, arr[0], arr[1], arr[2]
result = result && (VecAt(&vec, 3) == 40);
result = result && (VecAt(&vec, 4) == 50);
result = result && (VecAt(&vec, 5) == 60); // Check items: val2, val3, val1, arr[0], arr[1], arr[2]
result = result && (VecAt(&vec, 3) == 40);
result = result && (VecAt(&vec, 4) == 50);
result = result && (VecAt(&vec, 5) == 60); result = result && (VecAt(&vec, 3) == 40);
result = result && (VecAt(&vec, 4) == 50);
result = result && (VecAt(&vec, 5) == 60);
// Clean up
// Check that the element was inserted
result = result && (VecAt(&vec, 2) == 99);
// Use regular insert range instead of fast insert range
// Check that the array was inserted
result = result && (VecAt(&vec, 1) == 100);
result = result && (VecAt(&vec, 2) == 200);
result = result && (VecAt(&vec, 3) == 300); // Check that the array was inserted
result = result && (VecAt(&vec, 1) == 100);
result = result && (VecAt(&vec, 2) == 200);
result = result && (VecAt(&vec, 3) == 300); result = result && (VecAt(&vec, 1) == 100);
result = result && (VecAt(&vec, 2) == 200);
result = result && (VecAt(&vec, 3) == 300);
// Clean up
result = result && (VecLen(&vec2) == 6);
result = result && (VecAt(&vec2, 2) == 42);
// Now try the range insert with a small array
// Check that the array was inserted
result = result && (VecAt(&vec2, 1) == 111);
result = result && (VecAt(&vec2, 2) == 222); // Check that the array was inserted
result = result && (VecAt(&vec2, 1) == 111);
result = result && (VecAt(&vec2, 2) == 222);
// Clean up
// Check that the element was deleted and elements shifted
result = result && (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 40); // 30 was deleted, so now 40 is at index 2
// Check that the element was deleted and elements shifted
result = result && (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 40); // 30 was deleted, so now 40 is at index 2
result = result && (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 40); // 30 was deleted, so now 40 is at index 2
// Test VecDeleteRange (regular delete range)
// Check that elements were deleted and remaining elements shifted
result = result && (VecAt(&vec, 0) == 40);
result = result && (VecAt(&vec, 1) == 50); // Check that elements were deleted and remaining elements shifted
result = result && (VecAt(&vec, 0) == 40);
result = result && (VecAt(&vec, 1) == 50);
// Clean up this vector
// Check that the element was deleted and replaced with the last element (90)
result = result && (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 90); // 30 was replaced with 90
// Check that the element was deleted and replaced with the last element (90)
result = result && (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 90); // 30 was replaced with 90
result = result && (VecAt(&vec, 7) == 80); // Last element is now 80
result = result && (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 90); // 30 was replaced with 90
result = result && (VecAt(&vec, 7) == 80); // Last element is now 80
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 90); // 30 was replaced with 90
result = result && (VecAt(&vec, 7) == 80); // Last element is now 80
// Test VecDeleteRangeFast (fast delete range)
// Check that the element was deleted
result = result && (VecAt(&vec, 3) == 50); // 40 was deleted, so now 50 is at index 3
// Clean up
// Test pushing to empty vector
VecPushBackR(&vec, 10);
bool result = (VecLen(&vec) == 1 && VecAt(&vec, 0) == 10);
// Test pushing with zero count
// Test inserting at end index
VecInsertR(&vec, 20, VecLen(&vec));
result = result && (VecLen(&vec) == 2 && VecAt(&vec, 1) == 20);
// Test with large number of elements
bool all_correct = true;
for (int i = 0; i < large_count; i++) {
if (VecAt(&vec, i) != i) {
all_correct = false;
break; // Push an element (should auto-resize)
VecPushBackR(&vec, 42);
result = result && (VecLen(&vec) == 1 && VecAt(&vec, 0) == 42);
// Clean up
- In
Vec.Access.c:26:
// Test VecAt function
bool test_vec_at(void) {
WriteFmt("Testing VecAt\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Vec.Access.c:42:
// Check values using VecAt
bool result = (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 30);- In
Vec.Access.c:43:
// Check values using VecAt
bool result = (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 30);
result = result && (VecAt(&vec, 3) == 40);- In
Vec.Access.c:44:
bool result = (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 30);
result = result && (VecAt(&vec, 3) == 40);
result = result && (VecAt(&vec, 4) == 50);- In
Vec.Access.c:45:
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 30);
result = result && (VecAt(&vec, 3) == 40);
result = result && (VecAt(&vec, 4) == 50);- In
Vec.Access.c:46:
result = result && (VecAt(&vec, 2) == 30);
result = result && (VecAt(&vec, 3) == 40);
result = result && (VecAt(&vec, 4) == 50);
// Modify a value using VecAt
- In
Vec.Access.c:49:
// Modify a value using VecAt
VecAt(&vec, 2) = 35;
result = result && (VecAt(&vec, 2) == 35);- In
Vec.Access.c:50:
// Modify a value using VecAt
VecAt(&vec, 2) = 35;
result = result && (VecAt(&vec, 2) == 35);
// Clean up
- In
Vec.Access.c:89:
// Verify changes
result = result && (VecAt(&vec, 0) == 15);
result = result && (VecAt(&vec, 2) == 35);- In
Vec.Access.c:90:
// Verify changes
result = result && (VecAt(&vec, 0) == 15);
result = result && (VecAt(&vec, 2) == 35);
// Clean up
- In
Vec.Access.c:123:
// Verify changes
result = result && (VecAt(&vec, 0) == 15);
result = result && (VecAt(&vec, 2) == 35);- In
Vec.Access.c:124:
// Verify changes
result = result && (VecAt(&vec, 0) == 15);
result = result && (VecAt(&vec, 2) == 35);
// Clean up
- In
Vec.Insert.c:44:
// Check elements in order
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[i]);
}- In
Vec.Insert.c:72:
// Check elements in reverse order (since we pushed to front)
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[4 - i]);
}- In
Vec.Insert.c:93:
// Check first element
bool result = (VecLen(&vec) == 1 && VecAt(&vec, 0) == 10);
// Insert at the end
- In
Vec.Insert.c:99:
// Check elements
result = result && (VecLen(&vec) == 2 && VecAt(&vec, 0) == 10 && VecAt(&vec, 1) == 30);
// Insert in the middle
- In
Vec.Insert.c:106:
// Check all elements
result = result && (VecLen(&vec) == 3);
result = result && (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 30);- In
Vec.Insert.c:107:
result = result && (VecLen(&vec) == 3);
result = result && (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 30);- In
Vec.Insert.c:108:
result = result && (VecAt(&vec, 0) == 10);
result = result && (VecAt(&vec, 1) == 20);
result = result && (VecAt(&vec, 2) == 30);
// Clean up
- In
Vec.Insert.c:133:
// Check elements in order
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[i]);
}- In
Vec.Insert.c:145:
// Check all elements
for (size i = 0; i < 5; i++) {
result = result && (VecAt(&vec, i) == values[i]);
}
for (size i = 0; i < 3; i++) {- In
Vec.Insert.c:148:
}
for (size i = 0; i < 3; i++) {
result = result && (VecAt(&vec, i + 5) == more_values[i]);
}- In
Vec.Insert.c:174:
// Check elements in order
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == values[i]);
}- In
Vec.Insert.c:186:
// Check all elements
for (size i = 0; i < 3; i++) {
result = result && (VecAt(&vec, i) == more_values[i]);
}
for (size i = 0; i < 5; i++) {- In
Vec.Insert.c:189:
}
for (size i = 0; i < 5; i++) {
result = result && (VecAt(&vec, i + 3) == values[i]);
}- In
Vec.Insert.c:222:
// Check all elements
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected[i]);
}- In
Vec.Insert.c:259:
// Check all elements
for (size i = 0; i < VecLen(&vec); i++) {
result = result && (VecAt(&vec, i) == expected[i]);
}- In
Vec.Insert.c:300:
// Check all elements in vec1
for (size i = 0; i < VecLen(&vec1); i++) {
result = result && (VecAt(&vec1, i) == expected[i]);
}- In
Vec.Insert.c:346:
VecAllocator(&dst)->effort == ALLOCATOR_EFFORT_RETRY_FALLBACK &&
VecAllocator(&dst)->retry_limit == 11 && allocator_matches && VecLen(&src) == 3 &&
VecAt(&src, 0) == 10 && VecAt(&src, 1) == 20 && VecAt(&src, 2) == 30 && VecLen(&dst) == 3 &&
VecAt(&dst, 0) == 10 && VecAt(&dst, 1) == 20 && VecAt(&dst, 2) == 30;- In
Vec.Insert.c:347:
VecAllocator(&dst)->retry_limit == 11 && allocator_matches && VecLen(&src) == 3 &&
VecAt(&src, 0) == 10 && VecAt(&src, 1) == 20 && VecAt(&src, 2) == 30 && VecLen(&dst) == 3 &&
VecAt(&dst, 0) == 10 && VecAt(&dst, 1) == 20 && VecAt(&dst, 2) == 30;
VecDeinit(&src);- In
Vec.Insert.c:367:
// Check that the element was added
bool result = (VecLen(&vec) == 1 && VecAt(&vec, 0) == 42);
// Test L-value insert operations
- In
Vec.Insert.c:374:
// Check that the element was added
result = result && (VecLen(&vec) == 2 && VecAt(&vec, 1) == 100);
// Test R-value insert at index
- In
Vec.Insert.c:381:
// Check that the element was inserted
result = result && (VecLen(&vec) == 3);
result = result && (VecAt(&vec, 0) == 42);
result = result && (VecAt(&vec, 1) == 50);
result = result && (VecAt(&vec, 2) == 100);- In
Vec.Insert.c:382:
result = result && (VecLen(&vec) == 3);
result = result && (VecAt(&vec, 0) == 42);
result = result && (VecAt(&vec, 1) == 50);
result = result && (VecAt(&vec, 2) == 100);- In
Vec.Insert.c:383:
result = result && (VecAt(&vec, 0) == 42);
result = result && (VecAt(&vec, 1) == 50);
result = result && (VecAt(&vec, 2) == 100);
// Test L-value insert at index
- In
Vec.Insert.c:391:
// Check that the element was inserted
result = result && (VecLen(&vec) == 4);
result = result && (VecAt(&vec, 0) == 42);
result = result && (VecAt(&vec, 1) == 50);
result = result && (VecAt(&vec, 2) == 75);- In
Vec.Insert.c:392:
result = result && (VecLen(&vec) == 4);
result = result && (VecAt(&vec, 0) == 42);
result = result && (VecAt(&vec, 1) == 50);
result = result && (VecAt(&vec, 2) == 75);
result = result && (VecAt(&vec, 3) == 100);- In
Vec.Insert.c:393:
result = result && (VecAt(&vec, 0) == 42);
result = result && (VecAt(&vec, 1) == 50);
result = result && (VecAt(&vec, 2) == 75);
result = result && (VecAt(&vec, 3) == 100);- In
Vec.Insert.c:394:
result = result && (VecAt(&vec, 1) == 50);
result = result && (VecAt(&vec, 2) == 75);
result = result && (VecAt(&vec, 3) == 100);
// Test R-value fast insert
- In
Vec.Insert.c:401:
// Check that the element was inserted
result = result && (VecLen(&vec) == 5);
result = result && (VecAt(&vec, 1) == 60);
// Test L-value fast insert
- In
Vec.Insert.c:409:
// Check that the element was inserted
result = result && (VecLen(&vec) == 6);
result = result && (VecAt(&vec, 3) == 80);
// Test array operations with L-values and R-values
- In
Vec.Insert.c:419:
// Check that the elements were added
result = result && (VecLen(&vec) == 9);
result = result && (VecAt(&vec, 6) == 200);
result = result && (VecAt(&vec, 7) == 300);
result = result && (VecAt(&vec, 8) == 400);- In
Vec.Insert.c:420:
result = result && (VecLen(&vec) == 9);
result = result && (VecAt(&vec, 6) == 200);
result = result && (VecAt(&vec, 7) == 300);
result = result && (VecAt(&vec, 8) == 400);- In
Vec.Insert.c:421:
result = result && (VecAt(&vec, 6) == 200);
result = result && (VecAt(&vec, 7) == 300);
result = result && (VecAt(&vec, 8) == 400);
// L-value array operations
- In
Vec.Insert.c:428:
// Check that the elements were added
result = result && (VecLen(&vec) == 12);
result = result && (VecAt(&vec, 0) == 200);
result = result && (VecAt(&vec, 1) == 300);
result = result && (VecAt(&vec, 2) == 400);- In
Vec.Insert.c:429:
result = result && (VecLen(&vec) == 12);
result = result && (VecAt(&vec, 0) == 200);
result = result && (VecAt(&vec, 1) == 300);
result = result && (VecAt(&vec, 2) == 400);- In
Vec.Insert.c:430:
result = result && (VecAt(&vec, 0) == 200);
result = result && (VecAt(&vec, 1) == 300);
result = result && (VecAt(&vec, 2) == 400);
// Clean up
- In
Vec.Insert.c:540:
for (size i = 0; i < idx; i++) {
result = result && (VecAt(&vec, i) == originals[i]);
}- In
Vec.Insert.c:544:
for (size i = 0; i < new_count; i++) {
result = result && (VecAt(&vec, idx + i) == new_items[i]);
}- In
Vec.Insert.c:555:
bool found = false;
for (size j = tail_start; j < tail_end; j++) {
if (VecAt(&vec, j) == originals[i]) {
found = true;
break;- In
Access.h:63:
/// TAGS: Vec, Access, First
///
#define VecFirst(v) VecAt(v, 0)
///
- In
Access.h:73:
/// TAGS: Vec, Access, Last
///
#define VecLast(v) VecAt(v, (v)->length - 1)
///
- In
Foreach.h:33:
if ((ValidateVec(UNPL(pv)), 1) && UNPL(pv)->length > 0) \
for (u64 idx = 0, UNPL(d) = 1; UNPL(d); UNPL(d)--) \
for (VEC_DATATYPE(UNPL(pv)) var = {0}; idx < UNPL(pv)->length && (var = VecAt(UNPL(pv), idx), 1); idx++)
///
- In
Foreach.h:59:
for (u64 idx = UNPL(pv)->length; idx-- > 0 && idx < UNPL(pv)->length;) \
for (u8 UNPL(run_once) = 1; UNPL(run_once); UNPL(run_once) = 0) \
for (VEC_DATATYPE(UNPL(pv)) var = VecAt(UNPL(pv), idx); UNPL(run_once); UNPL(run_once) = 0)
///
- In
Foreach.h:181:
UNPL(s) <= idx && idx < UNPL(e) && idx < UNPL(pv)->length && UNPL(s) <= UNPL(e); \
++idx, UNPL(d) = 1) \
for (VEC_DATATYPE(UNPL(pv)) var = VecAt(UNPL(pv), idx); UNPL(d); UNPL(d) = 0)
///
- In
Access.h:108:
/// TAGS: Str, Access, Index
///
#define StrCharAt(str, idx) VecAt(str, idx)
///
Last updated on