Examples for using vector containers.
Examples for using vector containers.
#include <stdio.h>
#include <stdlib.h>
#define ITEM int
#define NAME basic_vec
DC_SCOPED(basic_vec) vec = basic_vec_new(stdalloc_get_ref());
for (int i = 0; i < 10; i++) {
basic_vec_push(&vec, i);
}
basic_vec_pop(&vec);
}
#define ITEM int
#define NAME dynamic_vec
DC_SCOPED(dynamic_vec) vec = dynamic_vec_new(stdalloc_get_ref());
for (int i = 0; i < 10; i++) {
dynamic_vec_push(&vec, i);
}
}
#define ITEM int
#define CAPACITY 3
#define NAME static_vec
DC_SCOPED(static_vec) vec = static_vec_new();
static_vec_push(&vec, 1);
static_vec_push(&vec, 2);
static_vec_push(&vec, 3);
int* result = static_vec_try_push(&vec, 4);
printf("\n");
}
#define ITEM char*
#define ITEM_DELETE(ptr_to_str) free(*ptr_to_str)
#define NAME char_vec
#define KEY char*
#define KEY_DELETE(ptr_to_str) free(*ptr_to_str)
#define KEY_HASH DC_DEFAULT_HASH
#define VALUE char_vec
#define VALUE_DELETE char_vec_delete
#define VALUE_DEBUG char_vec_debug
#define VALUE_CLONE char_vec_clone
#define NAME str_to_vec_map
DC_SCOPED(str_to_vec_map) map = str_to_vec_map_new(stdalloc_get_ref());
char_vec empty_vec = char_vec_new(stdalloc_get_ref());
char* key = strdup("key1");
str_to_vec_map_insert(&map, key, empty_vec);
char_vec* vec_ptr = str_to_vec_map_write(&map, key);
char_vec_push(vec_ptr, strdup("value1"));
char_vec_push(vec_ptr, strdup("value2"));
char_vec_push(vec_ptr, strdup("value3"));
}
return 0;
}
static void example_basic()
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_new()
#define DC_FOR_CONST(TYPE, INSTANCE, ITER, ITEM)
#define DC_ASSERT(expr,...)
#define DC_SCOPED(type,...)
RAII in C. Call the destructor when the variable goes out of scope.
static void example_map()
static void example_static()
static void example_dynamic()