libcdsb/examples/set.c

43 lines
822 B
C
Raw Normal View History

2022-08-16 18:11:07 +00:00
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <assert.h>
#include <stdio.h>
2022-08-19 14:19:22 +00:00
#include "../include/set.h"
2022-08-16 18:11:07 +00:00
typedef vtype_set vset_t;
int print_value(const void* value, vtype type, void* data) {
const char *n = data;
vtype_int32 *v = (void*)value;
assert(type == VTYPE_INT32);
printf("%s %d\n", n, *v);
return 0;
}
int main(int argc, char** argv) {
vset_t set;
2022-08-19 14:19:22 +00:00
int a, b;
2022-08-16 18:11:07 +00:00
vset_init(&set, VTYPE_INT32);
for (size_t i = 0; i < 28; ++i) {
vset_push(&set, i);
}
2022-08-19 14:19:22 +00:00
a = 13;
b = 18;
vset_get(&set, a, "Get value:", print_value);
vset_pop(&set, b, "Pop value:", print_value);
2022-08-16 18:11:07 +00:00
vset_foreach(&set, "Foreach loop:", print_value);
vset_free(&set);
}