-
Notifications
You must be signed in to change notification settings - Fork 0
/
wmem_iarray_test.c
78 lines (58 loc) · 1.49 KB
/
wmem_iarray_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "config.h"
#include "wmem_iarray.h"
#include <glib.h>
#include <assert.h>
#include <stdio.h>
struct entry {
range_admin_t range;
unsigned value;
};
gboolean equal(gconstpointer _a, gconstpointer _b) {
const struct entry *a = (const struct entry*)_a,
*b = (const struct entry*)_b;
return a->value == b->value;
}
int main(void) {
epl_wmem_iarray_t *iarr;
int i;
struct entry *pentry;
struct entry entry = {
{ 0, 0 },
0
};
iarr = epl_wmem_iarray_new(NULL, sizeof (struct entry), equal);
assert(iarr);
entry.value = 1;
epl_wmem_iarray_insert(iarr, 0, &entry.range);
entry.value = 1;
epl_wmem_iarray_insert(iarr, 0, &entry.range);
entry.value = 1;
epl_wmem_iarray_insert(iarr, 1, &entry.range);
entry.value = 2;
epl_wmem_iarray_insert(iarr, 10, &entry.range);
entry.value = 2;
epl_wmem_iarray_insert(iarr, 11, &entry.range);
epl_wmem_print_iarr(iarr);
epl_wmem_iarray_sort(iarr);
puts("------");
epl_wmem_print_iarr(iarr);
puts("------");
for (i = 0; i < 20; i++) {
pentry = (struct entry*)epl_wmem_iarray_find(iarr, i);
printf("%02d: ", i);
if (pentry) {
printf("[value=%2u, low =%2u, high=%2u]\n",
pentry->value, pentry->range.low, pentry->range.high
);
} else {
puts("doesn't exist");
}
}
return 0;
}
guint wmem_register_callback (wmem_allocator_t *allocator _U_, wmem_user_cb_t callback _U_, void *user_data _U_) {
return 0;
}
void *wmem_alloc(wmem_allocator_t *allocator _U_, const size_t size) {
return g_malloc(size);
}