VecInitWithDeepCopy

Table of Contents

VecInitWithDeepCopy

Description

Initialize vector. Default alignment is 1 It is mandatory to initialize vectors before use. Not doing so is undefined behaviour.

Parameters

NameDirectionDescription
ciinCopy init method.
cdinCopy deinit method.

Usage example (from documentation)

  Vec(HttpRequest) requests = VecInitWithDeepCopy(RequestClone, RequestDeinit);

Usage example (Cross-references)

    ValidateStr(s);
    
    Strs sv     = VecInitWithDeepCopy(NULL, StrDeinit);
    size keylen = ZstrLen(key);
    Scope(&file_paths, VecDeinit, {
    // temporary vector to store all directory paths to explore files in
    Strs dir_paths = VecInitWithDeepCopy(NULL, StrDeinit);
    Scope(&dir_paths, VecDeinit, {
    VecMerge(&dir_paths, &project.source_directories);
    Str  json    = StrInit();
    
    ApiResponse response = {true, StrInitFromZstr("Success"), VecInitWithDeepCopy(NULL, AnnSymbolDeinit)};
    
    // Add sample data
    Str  json    = StrInit();
    
    Vec(FunctionInfo) functions = VecInitWithDeepCopy(NULL, FunctionInfoDeinit);
    
    FunctionInfo func1 = {12345, StrInitFromZstr("test_func"), 1024, 4096};
    Str  json    = StrInit();
    
    Vec(AnnSymbol) symbols = VecInitWithDeepCopy(NULL, AnnSymbolDeinit);
    
    AnnSymbol sym1             = {0};
    VecPushBack(&numbers, num3);
    
    Vec(Str) strings = VecInitWithDeepCopy(NULL, StrDeinit);
    
    // Create strings and push them properly
    StrIter si      = StrIterFromStr(json);
    
    Vec(Str) languages = VecInitWithDeepCopy(NULL, StrDeinit);
    
    JR_OBJ(si, {
    
    typedef Vec(AnnSymbol) Symbols;
    Symbols symbols = VecInitWithDeepCopy(NULL, AnnSymbolDeinit);
    
    JR_OBJ(si, {
    StrIter si = StrIterFromStr(json);
    
    ApiResponse response = {false, StrInit(), VecInitWithDeepCopy(NULL, AnnSymbolDeinit)};
    
    JR_OBJ(si, {
    StrIter si = StrIterFromStr(json);
    
    ApiResponse response = {false, StrInit(), VecInitWithDeepCopy(NULL, AnnSymbolDeinit)};
    
    WriteFmt("[DEBUG] About to parse JSON...\n");
    StrIter si = StrIterFromStr(json);
    
    ApiResponse response = {false, StrInit(), VecInitWithDeepCopy(NULL, AnnSymbolDeinit)};
    
    WriteFmt("[DEBUG] About to parse JSON...\n");
    
    Vec(i32) empty_numbers = VecInit();
    Vec(Str) empty_strings = VecInitWithDeepCopy(NULL, StrDeinit);
    
    JW_OBJ(json, {
    Str  json    = StrInit();
    
    Vec(Str) languages = VecInitWithDeepCopy(NULL, StrDeinit);
    
    // Create strings and push them properly
    // Original data
    Vec(i32) original_numbers = VecInit();
    Vec(Str) original_strings = VecInitWithDeepCopy(NULL, StrDeinit);
    
    // Populate arrays
    // Read back from JSON
    Vec(i32) parsed_numbers = VecInit();
    Vec(Str) parsed_strings = VecInitWithDeepCopy(NULL, StrDeinit);
    
    StrIter si = StrIterFromStr(json);
    // Original empty data
    Vec(i32) empty_numbers = VecInit();
    Vec(Str) empty_strings = VecInitWithDeepCopy(NULL, StrDeinit);
    Str empty_str          = StrInit();
    // Read back from JSON
    Vec(i32) parsed_numbers = VecInit();
    Vec(Str) parsed_strings = VecInitWithDeepCopy(NULL, StrDeinit);
    Str  parsed_str         = StrInit();
    bool found_empty_object = false;
    StrIter si2   = StrIterFromStr(json2);
    
    Vec(Str) data = VecInitWithDeepCopy(NULL, StrDeinit);
    
    JR_OBJ(si2, {
    bool test_bitvec_prefix_match_null_source(void) {
    WriteFmt("Testing BitVecPrefixMatch(NULL, patterns, 1) - should fatal\n");
    BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit);
    BitVecPush(VecPtrAt(&vp, 0), true);
    BitVecPrefixMatch(NULL, &vp);
    bool test_bitvec_suffix_match_null_source(void) {
    WriteFmt("Testing BitVecSuffixMatch(NULL, patterns, 1) - should fatal\n");
    BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit);
    BitVecPush(VecPtrAt(&vp, 0), true);
    BitVecSuffixMatch(NULL, &vp);
    
    // Create a Strs object (vector of strings)
    Strs sv = VecInitWithDeepCopy(NULL, StrDeinit);
    
    // Add some strings
    // Test vector initialization with deep copy functions
    bool test_vec_init_with_deep_copy(void) {
    WriteFmt("Testing VecInitWithDeepCopy\n");
    
    // Test with struct type and custom copy/deinit functions
    // Test with struct type and custom copy/deinit functions
    typedef Vec(TestItem) TestVec;
    TestVec vec = VecInitWithDeepCopy(TestItemCopyInit, TestItemDeinit);
    
    // Check initial state
    // Create a vector of ComplexItem with deep copy functions
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec vec = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit);
    
    // Check initial state
    // Create a vector of ComplexItem with deep copy functions
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec vec = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit);
    
    // Create test items
    // Create a vector of ComplexItem with deep copy functions
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec vec = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit);
    
    // Create test items
    // Create two vectors of ComplexItem with deep copy functions
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec vec1 = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit);
    ComplexVec vec2 = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit);
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec vec1 = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit);
    ComplexVec vec2 = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit);
    
    // Create test items
    
    // Now test VecMergeL which transfers ownership
    ComplexVec vec3 = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    ComplexVec vec4 = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    // Now test VecMergeL which transfers ownership
    ComplexVec vec3 = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    ComplexVec vec4 = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    
    // Create more test items
    // Create a temporary vector with no copy_init but with copy_deinit for proper cleanup
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec temp_vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    
    // Insert with L-value semantics (vector takes ownership)
    // Create a vector with no copy_init but with copy_deinit for proper cleanup
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    
    // First, create a dummy item and add it to the vector
    // Create a vector with no copy_init but with copy_deinit for proper cleanup
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    
    // Make sure we have enough capacity to avoid reallocation issues
    // Create a vector with no copy_init but with copy_deinit for proper cleanup
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    
    // Add a dummy item first
    // Create a vector with no copy_init but with copy_deinit for proper cleanup
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec vec1 = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    ComplexVec vec2 = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec vec1 = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    ComplexVec vec2 = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    
    // Create test items for vec2
    // Create a vector with no copy_init but with copy_deinit for proper cleanup
    typedef Vec(ComplexItem) ComplexVec;
    ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit);
    
    // Create an array of complex items
    
    BitVec  source   = BitVecInit();
    BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit);
    bool    result   = true;
    
    BitVec  source   = BitVecInit();
    BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit);
    bool    result   = true;

Share :

Related Posts

VecForeachReverse

VecForeachReverse Description Iterate over each element var of the given vector v in reverse order. This is a convenience macro that iterates backward using an internally managed index. The variable var is declared and defined by this macro.

Read More

VecInitT

VecInitT Description Initialize given vector. Default alignment is 1 It is mandatory to initialize vectors before use. Not doing so is undefined behaviour.

Read More

VecForeachPtrReverse

VecForeachPtrReverse Description Iterate over each element var (as a pointer) of the given vector v in reverse order. This is a convenience macro that iterates backward using an internally managed index and provides a pointer to each element. The variable var is declared and defined by this macro as a pointer to the vector’s data type.

Read More