forked from troydhanson/uthash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest43.c
130 lines (128 loc) · 4.04 KB
/
test43.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <stdio.h>
#include "utarray.h"
typedef struct {
int a;
int b;
} intpair_t;
int main()
{
UT_array *pairs, *pairs_cpy;
intpair_t it, *ip;
UT_icd pairicd = { sizeof(intpair_t),NULL,NULL,NULL};
size_t zero=0;
utarray_new(pairs, &pairicd);
printf("length is %u\n", utarray_len(pairs));
it.a = 1;
it.b=2;
utarray_push_back(pairs, &it);
printf("push\n");
printf("length is %u\n", utarray_len(pairs));
ip = (intpair_t*)utarray_back(pairs);
printf("back is %d %d\n", ip->a, ip->b);
utarray_pop_back(pairs);
printf("pop\n");
printf("length is %u\n", utarray_len(pairs));
it.a = 1;
it.b=2;
utarray_push_back(pairs, &it);
printf("push\n");
it.a = 3;
it.b=4;
utarray_push_back(pairs, &it);
printf("push\n");
printf("length is %u\n", utarray_len(pairs));
ip=NULL;
while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
printf("%d %d\n", ip->a, ip->b);
}
utarray_erase(pairs,0,1);
printf("erase [0]\n");
printf("length is %u\n", utarray_len(pairs));
while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
printf("%d %d\n", ip->a, ip->b);
}
it.a = 1;
it.b=2;
utarray_push_back(pairs, &it);
printf("push\n");
while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
printf("%d %d\n", ip->a, ip->b);
}
utarray_clear(pairs);
printf("clear\n");
printf("length is %u\n", utarray_len(pairs));
utarray_extend_back(pairs);
printf("extend\n");
ip = (intpair_t*)utarray_back(pairs);
printf("length is %u\n", utarray_len(pairs));
printf("ip points to [0] ? %s\n", (ip==(intpair_t*)utarray_front(pairs)) ? "yes" : "no");
it.a = 1;
it.b=2;
utarray_push_back(pairs, &it);
printf("push\n");
ip=NULL;
while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
printf("%d %d\n", ip->a, ip->b);
}
utarray_erase(pairs,1,1);
printf("erase [1]\n");
printf("length is %u\n", utarray_len(pairs));
while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
printf("%d %d\n", ip->a, ip->b);
}
it.a = 3;
it.b=4;
utarray_push_back(pairs, &it);
printf("push\n");
for(ip=(intpair_t*)utarray_front(pairs); ip!=NULL; ip=(intpair_t*)utarray_next(pairs,ip)) {
printf("%d %d\n", ip->a,ip->b);
}
ip = (intpair_t*)utarray_back(pairs);
printf("back is %d %d\n", ip->a, ip->b);
utarray_new(pairs_cpy, &pairicd);
utarray_concat(pairs_cpy, pairs);
printf("copy\n");
printf("cpy length is %u\n", utarray_len(pairs_cpy));
ip=NULL;
while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) {
printf("cpy %d %d\n", ip->a, ip->b);
}
it.a=5;
it.b=6;
utarray_insert(pairs_cpy, &it, 0);
printf("insert cpy[0]\n");
printf("cpy length is %u\n", utarray_len(pairs_cpy));
while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) {
printf("cpy %d %d\n", ip->a, ip->b);
}
utarray_erase(pairs_cpy,0,2);
printf("erase cpy [0] [1]\n");
printf("cpy length is %u\n", utarray_len(pairs_cpy));
while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) {
printf("cpy %d %d\n", ip->a, ip->b);
}
utarray_inserta(pairs_cpy, pairs, 1);
printf("inserta at cpy[1]\n");
printf("cpy length is %u\n", utarray_len(pairs_cpy));
while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) {
printf("cpy %d %d\n", ip->a, ip->b);
}
utarray_free(pairs_cpy);
printf("free cpy\n");
printf("length is %u\n", utarray_len(pairs));
utarray_resize(pairs, 30);
printf("resize to 30\n");
printf("length is %u\n", utarray_len(pairs));
while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
printf("%d %d\n", ip->a, ip->b);
}
utarray_resize(pairs, 1);
printf("resize to 1\n");
printf("length is %u\n", utarray_len(pairs));
utarray_resize(pairs, zero);
printf("resize to 0\n");
printf("length is %u\n", utarray_len(pairs));
utarray_free(pairs);
printf("free\n");
return 0;
}