VecCapacity
Description
Capacity in elements: the most the vector can hold before the next reallocation. Always >= VecLen(v).
Parameters
| Name | Direction | Description |
|---|---|---|
v |
in | Vector to query. |
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Access.h:37:
/// TAGS: Str, Access, Capacity
///
#define StrCapacity(str) VecCapacity(str)
///
- In
Graph.c:507:
ValidateGraph(graph);
old_capacity = VecCapacity(&graph->slots);
success = reserve_vec(GENERIC_VEC(&graph->free_indices), sizeof(u32), n) &&- In
Graph.c:515:
}
if (VecCapacity(&graph->slots) != old_capacity) {
graph_bump_mutation_epoch(graph);
}- In
Pdb.c:329:
bool ok = false;
VecInitStack(u8, buf, 28) {
if (!stream_read(self, 1, 0, VecBegin(&buf), VecCapacity(&buf)))
break;
BufIter bi = BufIterFromMemory(VecBegin(&buf), VecCapacity(&buf));- In
Pdb.c:331:
if (!stream_read(self, 1, 0, VecBegin(&buf), VecCapacity(&buf)))
break;
BufIter bi = BufIterFromMemory(VecBegin(&buf), VecCapacity(&buf));
if (!BufReadFmt(&bi, FMT_PDB_INFO_LE, self->info.version, self->info.signature, self->info.age)) {
LOG_ERROR("PDB: info stream prefix truncated");- In
Pdb.c:372:
u16 global_idx = 0, build_num = 0, public_idx = 0, pdb_dll_ver = 0, pdb_dll_rbld = 0, flags = 0, machine = 0;
VecInitStack(u8, hdr, DBI_HEADER_SIZE) {
if (!stream_read(self, DBI_STREAM_INDEX, 0, VecBegin(&hdr), VecCapacity(&hdr)))
break;- In
Pdb.c:375:
break;
BufIter bi = BufIterFromMemory(VecBegin(&hdr), VecCapacity(&hdr));
if (!BufReadFmt(
&bi,- In
Init.c:26:
ValidateGraph(&graph);
bool result = VecCapacity(&graph.slots) >= 8;
GraphNodeId first_id = GraphAddNodeR(&graph, 10);
GraphNodeId second_id = GraphAddNodeR(&graph, 20);- In
Init.c:31:
GraphNodeId third_id = GraphAddNodeR(&graph, 30);
u64 slot_count = VecLen(&graph.slots);
size slot_capacity = VecCapacity(&graph.slots);
u32 first_generation = GraphNodeIdGeneration(first_id);
u32 second_generation = GraphNodeIdGeneration(second_id);- In
Init.c:55:
// surface does not expose.
result = result && VecLen(&graph.slots) == slot_count && VecLen(&graph.free_indices) == slot_count;
result = result && VecCapacity(&graph.slots) == slot_capacity && VecCapacity(&graph.free_indices) >= slot_count;
result = result && graph.pending_delete_count == 0 && VecLen(&graph.pending_edge_removals) == 0;- In
Init.c:202:
bool result = GraphReserve(&graph, 64);
result = result && (VecCapacity(&graph.slots) >= 64);
GraphDeinit(&graph);- In
Insert.c:127:
(void)GraphAddNodeR(&graph, 1);
size old_capacity = VecCapacity(&graph.slots);
u64 old_epoch = GraphMutationEpoch(&graph);- In
Insert.c:133:
bool result = grew;
result = result && (VecCapacity(&graph.slots) > old_capacity);
result = result && (GraphMutationEpoch(&graph) > old_epoch);- In
Complex.c:187:
// Check initial state
bool result =
(VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL &&
VecCopyInit(&vec) == (GenericCopyInit)ComplexItemCopyInit &&
VecCopyDeinit(&vec) == (GenericCopyDeinit)ComplexItemDeinit);- In
Complex.c:651:
// Reserve zero capacity
VecReserve(&vec, 0);
result = result && (VecCapacity(&vec) == 0);
// Push an element (should auto-resize)
- In
Memory.c:100:
// Original capacity should be at least 100
bool result = (VecCapacity(&vec) >= 100);
// Try to reduce space
- In
Memory.c:106:
// Capacity should now be closer to the actual length
result = result && (VecCapacity(&vec) < 100) && (VecCapacity(&vec) >= VecLen(&vec));
// Check that the data is still intact
- In
Memory.c:179:
// Initial capacity should be 0
bool result = (VecCapacity(&vec) == 0);
// Reserve space for 50 elements
- In
Memory.c:185:
// Capacity should now be at least 50
result = result && (VecCapacity(&vec) >= 50);
// Length should still be 0
- In
Memory.c:197:
// Capacity should still be at least 50
result = result && (VecCapacity(&vec) >= 50);
// Length should now be 5
- In
Memory.c:206:
// Capacity should still be at least 50
result = result && (VecCapacity(&vec) >= 50);
// Clean up
- In
Memory.c:235:
// Remember the capacity
size original_capacity = VecCapacity(&vec);
// Clear the vector
- In
Memory.c:244:
// Capacity should remain the same
result = result && (VecCapacity(&vec) == original_capacity);
// Data pointer should still be valid
- In
Memory.c:275:
bool ok = VecResize(&vec, 100);
bool result = ok && (VecLen(&vec) == 100) && (VecCapacity(&vec) >= 100);
VecDeinit(&vec);- In
Memory.c:321:
// Whichever way the constant forces the branch, a real grow must leave
// capacity large enough to hold the new length.
bool result = (VecCapacity(&vec) >= 64);
VecDeinit(&vec);- In
Memory.c:358:
VecResize(&vec, 10);
bool result = (VecLen(&vec) == 10) && (VecCapacity(&vec) == 16);
VecDeinit(&vec);- In
Memory.c:612:
// Real: capacity 0.
bool result = (VecCapacity(&vec) == 0);
VecDeinit(&vec);- In
Memory.c:658:
// Real: capacity == length == 5.
bool result = (VecCapacity(&vec) == 5);
VecDeinit(&vec);- In
Init.c:65:
// Check initial state
bool result =
(VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL && VecAllocator(&vec)->alignment == 1 &&
VecCopyInit(&vec) == NULL && VecCopyDeinit(&vec) == NULL);- In
Init.c:76:
// Check initial state
result = result && (VecLen(&test_vec) == 0 && VecCapacity(&test_vec) == 0 && VecBegin(&test_vec) == NULL &&
VecAllocator(&test_vec)->alignment == 1 && VecCopyInit(&test_vec) == NULL &&
VecCopyDeinit(&test_vec) == NULL);- In
Init.c:99:
// Check initial state
bool result =
(VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL && VecAllocator(&vec)->alignment == 4 &&
VecCopyInit(&vec) == NULL && VecCopyDeinit(&vec) == NULL);- In
Init.c:110:
// Check initial state
result = result && (VecLen(&test_vec) == 0 && VecCapacity(&test_vec) == 0 && VecBegin(&test_vec) == NULL &&
VecAllocator(&test_vec)->alignment == 16 && VecCopyInit(&test_vec) == NULL &&
VecCopyDeinit(&test_vec) == NULL);- In
Init.c:132:
// Check initial state
bool result =
(VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL && VecAllocator(&vec)->alignment == 1 &&
VecCopyInit(&vec) == (GenericCopyInit)TestItemCopyInit &&
VecCopyDeinit(&vec) == (GenericCopyDeinit)TestItemDeinit);- In
Init.c:154:
// Check initial state
bool result =
(VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL && VecAllocator(&vec)->alignment == 8 &&
VecCopyInit(&vec) == (GenericCopyInit)TestItemCopyInit &&
VecCopyDeinit(&vec) == (GenericCopyDeinit)TestItemDeinit);- In
Init.c:231:
VecInitStack(int, vec, 10) {
// Stack-init: NULL allocator distinguishes from heap-init.
if (VecLen(&vec) != 0 || VecCapacity(&vec) != 10 || VecBegin(&vec) == NULL || VecAllocator(&vec) != NULL) {
result = false;
}- In
Init.c:246:
// Test with struct type
VecInitStack(TestItem, test_vec, 5) {
if (VecLen(&test_vec) != 0 || VecCapacity(&test_vec) != 5 || VecBegin(&test_vec) == NULL ||
VecAllocator(&test_vec) != NULL) {
result = false;- In
Init.c:313:
// Check that the clone has the same data but different memory
bool result =
(VecLen(&clone) == VecLen(&src) && VecCapacity(&clone) >= VecLen(&src) && VecBegin(&clone) != VecBegin(&src) &&
VecAllocator(&clone)->alignment == VecAllocator(&src)->alignment);- In
Insert.c:746:
// run, so capacity must have expanded past the old value of 8. The mutant
// skips the grow and leaves capacity == 8.
bool result = ok && (VecLen(&vec) == 16) && (VecCapacity(&vec) >= 16);
for (int i = 0; i < 8; i++) {
result = result && (VecAt(&vec, (size)i) == i);- In
Insert.c:793:
// Real code reserves past the old capacity (10 -> 16). The `>` mutant skips
// the grow and leaves capacity at 10.
bool result = ok && (VecLen(&vec) == 10) && (VecCapacity(&vec) > 10);
for (int i = 0; i < 5; i++) {
result = result && (VecAt(&vec, (size)i) == i);- In
Insert.c:816:
// Holding 8 elements requires growth from capacity 0; the mutant's
// inverted predicate skips it.
bool result = ok && (VecLen(&vec) == 8) && (VecCapacity(&vec) >= 8);
for (size i = 0; i < 8; i++) {
result = result && (VecAt(&vec, i) == add[i]);- In
Insert.c:841:
// replacement makes the call return false. Either way the real growth
// contract (true return, all 10 elements, capacity >= 10) breaks.
bool result = ok && (VecLen(&vec) == 10) && (VecCapacity(&vec) >= 10);
for (size i = 0; i < 10; i++) {
result = result && (VecAt(&vec, i) == add[i]);- In
Type.c:31:
// Check initial state
bool result =
(VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL && VecAllocator(&vec)->alignment == 1 &&
VecCopyInit(&vec) == NULL && VecCopyDeinit(&vec) == NULL);- In
Type.c:42:
// Check initial state
result = result && (VecLen(&test_vec) == 0 && VecCapacity(&test_vec) == 0 && VecBegin(&test_vec) == NULL &&
VecAllocator(&test_vec)->alignment == 1 && VecCopyInit(&test_vec) == NULL &&
VecCopyDeinit(&test_vec) == NULL);
Last updated on