libcdsb/examples/set.c

43 lines
827 B
C
Raw Normal View History

2022-08-16 21:11:07 +03: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 17:19:22 +03:00
#include "../include/set.h"
2022-08-16 21:11:07 +03:00
typedef vtype_set vset_t;
2023-03-23 18:18:51 +03:00
int print_value(vtype_variable value, void* data) {
2022-08-16 21:11:07 +03:00
const char *n = data;
2023-03-23 18:18:51 +03:00
vtype_int32 *v = (void*)value.pointer;
2022-08-16 21:11:07 +03:00
2023-03-23 18:18:51 +03:00
assert(value.type == VTYPE_INT32);
2022-08-16 21:11:07 +03:00
printf("%s %d\n", n, *v);
return 0;
}
int main(int argc, char** argv) {
vset_t set;
2022-08-19 17:19:22 +03:00
int a, b;
2022-08-16 21:11:07 +03:00
vset_init(&set, VTYPE_INT32);
for (size_t i = 0; i < 28; ++i) {
vset_push(&set, i);
}
2022-08-19 17:19:22 +03:00
a = 13;
b = 18;
vset_get(&set, a, "Get value:", print_value);
vset_pop(&set, b, "Pop value:", print_value);
2022-08-16 21:11:07 +03:00
vset_foreach(&set, "Foreach loop:", print_value);
vset_free(&set);
}