Skip to content

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)
        // Check initial state
        bool result =
            (VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL && vec.allocator->alignment == 1 &&
             vec.copy_init == NULL && vec.copy_deinit == NULL);
        // Check initial state
        result =
            result && (VecLen(&test_vec) == 0 && VecCapacity(&test_vec) == 0 && VecBegin(&test_vec) == NULL &&
                       test_vec.allocator->alignment == 1 && test_vec.copy_init == NULL && test_vec.copy_deinit == NULL);
        // Check initial state
        bool result =
            (VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL && vec.allocator->alignment == 4 &&
             vec.copy_init == NULL && vec.copy_deinit == NULL);
        // Check initial state
        result =
            result && (VecLen(&test_vec) == 0 && VecCapacity(&test_vec) == 0 && VecBegin(&test_vec) == NULL &&
                       test_vec.allocator->alignment == 16 && test_vec.copy_init == NULL && test_vec.copy_deinit == NULL);
        // Check initial state
        bool result =
            (VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL && vec.allocator->alignment == 1 &&
             vec.copy_init == (GenericCopyInit)TestItemCopyInit && vec.copy_deinit == (GenericCopyDeinit)TestItemDeinit);
        // Check initial state
        bool result =
            (VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL && vec.allocator->alignment == 8 &&
             vec.copy_init == (GenericCopyInit)TestItemCopyInit && vec.copy_deinit == (GenericCopyDeinit)TestItemDeinit);
    
            // Check initial state
            if (VecLen(&vec) != 0 || VecCapacity(&vec) != 10 || VecBegin(&vec) == NULL || vec.allocator->alignment != 1 ||
                vec.copy_init != NULL || vec.copy_deinit != NULL) {
                result = false;
    
        // After the scope, vec should be zeroed out
        if (VecBegin(&vec) != NULL || VecLen(&vec) != 0 || VecCapacity(&vec) != 0) {
            result = false;
        }
    
            // Check initial state
            if (VecLen(&test_vec) != 0 || VecCapacity(&test_vec) != 5 || VecBegin(&test_vec) == NULL ||
                test_vec.allocator->alignment != 1 || test_vec.copy_init != NULL || test_vec.copy_deinit != NULL) {
                result = false;
    
        // After the scope, test_vec should be zeroed out
        if (VecBegin(&test_vec) != NULL || VecLen(&test_vec) != 0 || VecCapacity(&test_vec) != 0) {
            result = false;
        }
        // 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) &&
             clone.allocator->alignment == src.allocator->alignment);
    
        // Original capacity should be at least 100
        bool result = (VecCapacity(&vec) >= 100);
    
        // Try to reduce space
    
        // 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
    
        // Initial capacity should be 0
        bool result = (VecCapacity(&vec) == 0);
    
        // Reserve space for 50 elements
    
        // Capacity should now be at least 50
        result = result && (VecCapacity(&vec) >= 50);
    
        // Length should still be 0
    
        // Capacity should still be at least 50
        result = result && (VecCapacity(&vec) >= 50);
    
        // Length should now be 5
    
        // Capacity should still be at least 50
        result = result && (VecCapacity(&vec) >= 50);
    
        // Clean up
    
        // Remember the capacity
        size original_capacity = VecCapacity(&vec);
    
        // Clear the vector
    
        // Capacity should remain the same
        result = result && (VecCapacity(&vec) == original_capacity);
    
        // Data pointer should still be valid
        ValidateGraph(&graph);
    
        bool        result            = VecCapacity(&graph.slots) >= 8;
        GraphNodeId first_id          = GraphAddNodeR(&graph, 10);
        GraphNodeId second_id         = GraphAddNodeR(&graph, 20);
        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);
        result = result && !GraphContainsNode(&graph, third_id);
        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;
        // Check initial state
        bool result =
            (VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL && vec.allocator->alignment == 1 &&
             vec.copy_init == NULL && vec.copy_deinit == NULL);
        // Check initial state
        result =
            result && (VecLen(&test_vec) == 0 && VecCapacity(&test_vec) == 0 && VecBegin(&test_vec) == NULL &&
                       test_vec.allocator->alignment == 1 && test_vec.copy_init == NULL && test_vec.copy_deinit == NULL);
        // Check initial state
        bool result =
            (VecLen(&vec) == 0 && VecCapacity(&vec) == 0 && VecBegin(&vec) == NULL &&
             vec.copy_init == (GenericCopyInit)ComplexItemCopyInit &&
             vec.copy_deinit == (GenericCopyDeinit)ComplexItemDeinit);
        // Reserve zero capacity
        VecReserve(&vec, 0);
        result = result && (VecCapacity(&vec) == 0);
    
        // Push an element (should auto-resize)
    /// TAGS: Str, Access, Capacity
    ///
    #define StrCapacity(str) VecCapacity(str)
    
    ///
Last updated on