VecPushBack

Table of Contents

VecPushBack

Description

Push item into vector back. Default behaviour is same as VecPushBackL

Parameters

NameDirectionDescription
vin,outVector to push item into
lvalinl-value to be pushed back

Success

return

Failure

Does not return

Usage example (Cross-references)

    
    direntry.name = StrInitFromZstr(findFileData.cFileName); // Copy file name
    VecPushBack(&dc, direntry);
    } while (FindNextFile(hFind, &findFileData) != 0);
    }
    direntry.name = StrInitFromCstr(entry->d_name, NAMELEN(entry));
    VecPushBack(&dc, direntry);
    }
    }
    if (next) {
    StrIter si = {.data = (char*)prev, .length = next - prev, .pos = 0, .alignment = 1};
    VecPushBack(&sv, si);
    prev = next + keylen; // skip past delimiter
    } else {
    } else {
    StrIter si = {.data = (char*)prev, .length = end - prev, .pos = 0, .alignment = 1};
    VecPushBack(&sv, si);
    break;
    }
    if (next) {
    Str tmp = StrInitFromCstr(prev, next - prev);
    VecPushBack(&sv, tmp); // exclude delimiter
    prev = next + keylen;  // skip past delimiter
    } else {
    if (ZstrCompareN(prev, key, end - prev)) {
    Str tmp = StrInitFromCstr(prev, end - prev);
    VecPushBack(&sv, tmp); // remaining part
    }
    break;
    }
    
    VecPushBack(&entries, e);
    });
    });
    Str s = StrInit();                                                                                 \
    JR_STR(json, s);                                                                                   \
    VecPushBack(&p.test_directories, s);                                                               \
    });                                                                                                    \
    JR_ARR_KV(json, "source_directories", {                                                                \
    Str s = StrInit();                                                                                 \
    JR_STR(json, s);                                                                                   \
    VecPushBack(&p.source_directories, s);                                                             \
    });                                                                                                    \
    });                                                                                                        \
    
    // store the directory name, ownersip transferred
    VecPushBack(&dir_paths, path);
    } else if (dir_entry.type == SYS_DIR_ENTRY_TYPE_REGULAR_FILE) {
    // create complete relative file path
    
    // store discovered file name, ownersip transferred
    VecPushBack(&file_paths, path);
    }
    // any other file type is not documented
    Str lang3 = StrInitFromZstr("Rust");
    
    VecPushBack(&languages, lang1);
    VecPushBack(&languages, lang2);
    VecPushBack(&languages, lang3);
    
    VecPushBack(&languages, lang1);
    VecPushBack(&languages, lang2);
    VecPushBack(&languages, lang3);
    VecPushBack(&languages, lang1);
    VecPushBack(&languages, lang2);
    VecPushBack(&languages, lang3);
    
    JW_OBJ(json, { JW_ARR_KV(json, "languages", languages, lang, { JW_STR(json, lang); }); });
    Str tag3 = StrInitFromZstr("portable");
    
    VecPushBack(&product.tags, tag1);
    VecPushBack(&product.tags, tag2);
    VecPushBack(&product.tags, tag3);
    
    VecPushBack(&product.tags, tag1);
    VecPushBack(&product.tags, tag2);
    VecPushBack(&product.tags, tag3);
    VecPushBack(&product.tags, tag1);
    VecPushBack(&product.tags, tag2);
    VecPushBack(&product.tags, tag3);
    
    JW_OBJ(json, {
    Str lang = StrInit();
    JR_STR(si, lang);
    VecPushBack(&languages, lang);
    });
    });
    Str tag = StrInit();
    JR_STR(si, tag);
    VecPushBack(&product.tags, tag);
    });
    });
    Vec(i32) filled_arr = VecInit();
    i32 val1 = 1, val2 = 2;
    VecPushBack(&filled_arr, val1);
    VecPushBack(&filled_arr, val2);
    i32 val1 = 1, val2 = 2;
    VecPushBack(&filled_arr, val1);
    VecPushBack(&filled_arr, val2);
    
    i32 x_value = 1;
    i32 value = 0;
    JR_INT(si1, value);
    VecPushBack(&items, value);
    });
    });
    Str value = StrInit();
    JR_STR(si2, value);
    VecPushBack(&data, value);
    });
    });
    i32 item = 0;
    JR_INT(si, item);
    VecPushBack(&obj.filled_items, item);
    });
    });
    sym.binary_id             = 888;
    sym.debug                 = true;
    VecPushBack(&response.data, sym);
    
    JW_OBJ(json, {
    FunctionInfo func1 = {12345, StrInitFromZstr("test_func"), 1024, 4096};
    FunctionInfo func2 = {54321, StrInitFromZstr("helper_func"), 512, 8192};
    VecPushBack(&functions, func1);
    VecPushBack(&functions, func2);
    FunctionInfo func2 = {54321, StrInitFromZstr("helper_func"), 512, 8192};
    VecPushBack(&functions, func1);
    VecPushBack(&functions, func2);
    
    JW_OBJ(json, {
    Str tag2 = StrInitFromZstr("x86");
    
    VecPushBack(&result.tags, tag1);
    VecPushBack(&result.tags, tag2);
    
    VecPushBack(&result.tags, tag1);
    VecPushBack(&result.tags, tag2);
    
    result.created_at = StrInitFromZstr("2024-04-01");
    sym1.target_function_id    = 222;
    sym1.distance              = 0.9;
    VecPushBack(&symbols, sym1);
    
    AnnSymbol sym2             = {0};
    sym2.target_function_id    = 444;
    sym2.distance              = 0.8;
    VecPushBack(&symbols, sym2);
    
    JW_OBJ(json, {
    Vec(u32) numbers = VecInit();
    u32 num1 = 1, num2 = 2, num3 = 3;
    VecPushBack(&numbers, num1);
    VecPushBack(&numbers, num2);
    VecPushBack(&numbers, num3);
    u32 num1 = 1, num2 = 2, num3 = 3;
    VecPushBack(&numbers, num1);
    VecPushBack(&numbers, num2);
    VecPushBack(&numbers, num3);
    VecPushBack(&numbers, num1);
    VecPushBack(&numbers, num2);
    VecPushBack(&numbers, num3);
    
    Vec(Str) strings = VecInitWithDeepCopy(NULL, StrDeinit);
    Str str3 = StrInitFromZstr("c");
    
    VecPushBack(&strings, str1);
    VecPushBack(&strings, str2);
    VecPushBack(&strings, str3);
    
    VecPushBack(&strings, str1);
    VecPushBack(&strings, str2);
    VecPushBack(&strings, str3);
    VecPushBack(&strings, str1);
    VecPushBack(&strings, str2);
    VecPushBack(&strings, str3);
    
    Vec(bool) booleans = VecInit();
    Vec(bool) booleans = VecInit();
    bool bool1 = true, bool2 = false, bool3 = true;
    VecPushBack(&booleans, bool1);
    VecPushBack(&booleans, bool2);
    VecPushBack(&booleans, bool3);
    bool bool1 = true, bool2 = false, bool3 = true;
    VecPushBack(&booleans, bool1);
    VecPushBack(&booleans, bool2);
    VecPushBack(&booleans, bool3);
    VecPushBack(&booleans, bool1);
    VecPushBack(&booleans, bool2);
    VecPushBack(&booleans, bool3);
    
    JW_OBJ(json, {
    i32 nums[5] = {1, 2, 3, -5, 0};
    for (size i = 0; i < 5; i++) {
    VecPushBack(&original_numbers, nums[i]);
    }
    Str str4 = StrInitFromZstr("last");
    
    VecPushBack(&original_strings, str1);
    VecPushBack(&original_strings, str2);
    VecPushBack(&original_strings, str3);
    
    VecPushBack(&original_strings, str1);
    VecPushBack(&original_strings, str2);
    VecPushBack(&original_strings, str3);
    VecPushBack(&original_strings, str4);
    VecPushBack(&original_strings, str1);
    VecPushBack(&original_strings, str2);
    VecPushBack(&original_strings, str3);
    VecPushBack(&original_strings, str4);
    VecPushBack(&original_strings, str2);
    VecPushBack(&original_strings, str3);
    VecPushBack(&original_strings, str4);
    
    // Write to JSON
    i32 num = 0;
    JR_INT(si, num);
    VecPushBack(&parsed_numbers, num);
    });
    JR_ARR_KV(si, "strings", {
    Str str = StrInit();
    JR_STR(si, str);
    VecPushBack(&parsed_strings, str);
    });
    });
    Str feature2 = StrInitFromZstr("logging");
    
    VecPushBack(&original.config.features, feature1);
    VecPushBack(&original.config.features, feature2);
    
    VecPushBack(&original.config.features, feature1);
    VecPushBack(&original.config.features, feature2);
    
    original.numbers = VecInitT(original.numbers);
    i32 vals[3]      = {10, 20, -5};
    for (size i = 0; i < 3; i++) {
    VecPushBack(&original.numbers, vals[i]);
    }
    bool bools[3]  = {true, false, true};
    for (size i = 0; i < 3; i++) {
    VecPushBack(&original.flags, bools[i]);
    }
    Str feature = StrInit();
    JR_STR(si, feature);
    VecPushBack(&parsed.config.features, feature);
    });
    });
    i32 num = 0;
    JR_INT(si, num);
    VecPushBack(&parsed.numbers, num);
    });
    JR_ARR_KV(si, "flags", {
    bool flag = false;
    JR_BOOL(si, flag);
    VecPushBack(&parsed.flags, flag);
    });
    });
    i32 num = 0;
    JR_INT(si, num);
    VecPushBack(&parsed_numbers, num);
    });
    JR_ARR_KV(si, "empty_strings", {
    Str str = StrInit();
    JR_STR(si, str);
    VecPushBack(&parsed_strings, str);
    });
    JR_OBJ_KV(si, "empty_object", { found_empty_object = true; });
    });
    
    VecPushBack(&symbols, sym);
    });
    });
    });
    
    VecPushBack(&response.data, sym);
    });
    });
    );
    
    VecPushBack(&response.data, sym);
    printf("[DEBUG] Added symbol to vector, length now: %zu\n", response.data.length);
    });
    );
    
    VecPushBack(&response.data, sym);
    printf("[DEBUG] Added symbol to vector, length now: %zu\n", response.data.length);
    });
    Str s2 = StrInitFromZstr("World");
    
    VecPushBack(&sv, s1);
    VecPushBack(&sv, s2);
    
    VecPushBack(&sv, s1);
    VecPushBack(&sv, s2);
    
    // Check that it behaves like a Vec of Str objects
    // Test VecPushBack function
    bool test_vec_push_back(void) {
    printf("Testing VecPushBack\n");
    
    // Create a vector of integers
    for (int i = 0; i < 5; i++) {
    int val = values[i];
    VecPushBack(&vec, val);
    }
    for (int i = 0; i < 5; i++) {
    int val = values[i];
    VecPushBack(&vec, val);
    }
    for (int i = 0; i < 5; i++) {
    int val = values[i];
    VecPushBack(&vec, val);
    }
    for (int i = 0; i < 5; i++) {
    int val = values[i];
    VecPushBack(&vec, val);
    }
    for (int i = 0; i < 7; i++) {
    int val = values[i];
    VecPushBack(&vec, val);
    }
    for (int i = 0; i < 10; i++) {
    int val = i * 10;
    VecPushBack(&vec, val);
    }
    for (int i = 0; i < 5; i++) {
    int val = values[i];
    VecPushBack(&vec, val);
    }
    int values[] = {10, 20, 30, 40, 50};
    for (int i = 0; i < 5; i++) {
    VecPushBack(&vec, values[i]);
    }
    int values[] = {10, 20, 30, 40, 50};
    for (int i = 0; i < 5; i++) {
    VecPushBack(&vec, values[i]);
    }
    int values[] = {10, 20, 30, 40, 50};
    for (int i = 0; i < 5; i++) {
    VecPushBack(&vec, values[i]);
    }
    int values[] = {10, 20, 30, 40, 50};
    for (int i = 0; i < 5; i++) {
    VecPushBack(&vec, values[i]);
    }
    int values[] = {10, 20, 30, 40, 50, 60, 70};
    for (int i = 0; i < 7; i++) {
    VecPushBack(&vec, values[i]);
    }
    int values[] = {10, 20, 30, 40, 50, 60, 70};
    for (int i = 0; i < 7; i++) {
    VecPushBack(&vec, values[i]);
    }
    int values[] = {10, 20, 30, 40, 50, 60, 70};
    for (int i = 0; i < 7; i++) {
    VecPushBack(&vec, values[i]);
    }
    int values[] = {10, 20, 30, 40, 50, 60, 70};
    for (int i = 0; i < 7; i++) {
    VecPushBack(&vec, values[i]);
    }

Share :