5 static void dtor(void *ptr
)
7 a_u32
*obj
= a_u32_(*, ptr
);
8 printf("%" PRIu32
" ", *obj
);
11 static int u32dup(void *dst
, void const *src
)
13 *a_u32_(*, dst
) = *a_u32_(const *, src
);
14 printf("%" PRIu32
" ", *a_u32_(const *, src
));
18 static void test(void)
20 a_vec
*ctx
= a_vec_new(sizeof(a_u64
));
22 for (a_u64 i
= 0; i
!= 10; ++i
)
24 a_u64
*obj
= A_VEC_PUSH(a_u64
, ctx
);
25 if (obj
) { *obj
= i
; }
27 a_vec_edit(ctx
, sizeof(a_u32
), A_NULL
);
28 for (a_u32 i
= 0; i
!= 20; ++i
)
30 a_u32
*obj
= A_VEC_PUSH(a_u32
, ctx
);
31 if (obj
) { *obj
= i
; }
33 for (a_u32 i
= 0; i
!= 10; ++i
)
39 a_u8
*end
= A_VEC_END(a_u8
, ctx
);
40 a_u8
*top
= A_VEC_TOP(a_u8
, ctx
);
41 TEST_BUG(a_vec_siz(ctx
) == a_size_c(end
- top
));
44 a_vec_swap(ctx
, 0, 0);
45 a_vec_swap(ctx
, 0, ~0U);
46 a_vec_swap(ctx
, ~0U, 0);
47 a_vec_swap(ctx
, 4, 6);
48 a_vec_swap(ctx
, 6, 4);
52 a_u32
*it
= A_VEC_AT(a_u32
, ctx
, i
);
53 TEST_BUG(a_vec_siz(ctx
) == sizeof(*it
));
54 if (it
) { printf("%" PRIu32
" ", *it
); }
57 a_vec_forenum_reverse(i
, ctx
)
59 a_u32
*it
= A_VEC_AT(a_u32
, ctx
, i
);
60 TEST_BUG(a_vec_siz(ctx
) == sizeof(*it
));
61 if (it
) { printf("%" PRIu32
" ", *it
); }
65 a_vec_foreach(a_u32
, it
, ctx
)
67 TEST_BUG(a_vec_siz(ctx
) == sizeof(*it
));
68 TEST_BUG(sizeof(a_u32
) == sizeof(*it
));
69 printf("%" PRIu32
" ", *it
);
72 a_vec_foreach_reverse(a_u32
, it
, ctx
)
74 TEST_BUG(a_vec_siz(ctx
) == sizeof(*it
));
75 TEST_BUG(sizeof(a_u32
) == sizeof(*it
));
76 printf("%" PRIu32
" ", *it
);
82 a_vec_copy(&obj
, ctx
, u32dup
);
84 a_vec_dtor(ctx
, A_NULL
);
85 a_vec_move(ctx
, &obj
);
92 ctx
= a_vec_new(sizeof(a_u32
));
93 for (a_u32 i
= 5; i
!= 10; ++i
)
95 a_u32
*obj
= A_VEC_INSERT(a_u32
, ctx
, i
);
96 if (obj
) { *obj
= i
; }
98 for (a_u32 i
= 0; i
!= 5; ++i
)
100 a_u32
*obj
= A_VEC_INSERT(a_u32
, ctx
, i
);
101 if (obj
) { *obj
= i
; }
103 a_vec_foreach(a_u32
, it
, ctx
)
105 printf("%" PRIu32
" ", *it
);
108 for (a_u32 i
= 0; i
!= 5; ++i
)
110 a_u32
*obj
= A_VEC_REMOVE(a_u32
, ctx
, i
);
111 if (obj
) { printf("%" PRIu32
" ", *obj
); }
113 for (a_u32 i
= 0; i
!= 5; ++i
)
115 a_u32
*obj
= A_VEC_REMOVE(a_u32
, ctx
, 0);
116 if (obj
) { printf("%" PRIu32
" ", *obj
); }
119 a_vec_die(ctx
, A_NULL
);
122 ctx
= a_vec_new(sizeof(a_u32
));
123 for (a_u32 i
= 5; i
!= 10; ++i
)
125 a_u32
*obj
= A_VEC_PUSH_BACK(a_u32
, ctx
);
126 if (obj
) { *obj
= i
; }
128 for (a_u32 i
= 5; i
!= 10; ++i
)
130 a_u32
*obj
= A_VEC_PULL_BACK(a_u32
, ctx
);
131 if (obj
) { printf("%" PRIu32
" ", *obj
); }
133 for (a_u32 i
= 0; i
!= 5; ++i
)
135 a_u32
*obj
= A_VEC_PUSH_FORE(a_u32
, ctx
);
136 if (obj
) { *obj
= i
; }
138 for (a_u32 i
= 0; i
!= 5; ++i
)
140 a_u32
*obj
= A_VEC_PULL_FORE(a_u32
, ctx
);
141 if (obj
) { printf("%" PRIu32
" ", *obj
); }
144 a_vec_die(ctx
, A_NULL
);
151 static int cmp(void const *lhs
, void const *rhs
)
153 return *a_int_(const *, lhs
) - *a_int_(const *, rhs
);
156 static int cmpr(void const *lhs
, void const *rhs
)
158 return *a_int_(const *, rhs
) - *a_int_(const *, lhs
);
161 static void test_sort(void)
163 unsigned int t
= a_cast_s(unsigned int, time(A_NULL
));
164 a_vec
*ctx
= a_vec_new(sizeof(int));
166 a_vec_make(ctx
, 10, A_NULL
);
169 a_vec_foreach(int, it
, ctx
)
171 *it
= rand() % 10; // NOLINT
175 a_vec_sort(ctx
, cmpr
);
176 a_vec_foreach(int, it
, ctx
)
183 a_vec_foreach(int, it
, ctx
)
185 *it
= rand() % 10; // NOLINT
189 a_vec_sort(ctx
, cmp
);
190 a_vec_foreach(int, it
, ctx
)
197 a_vec_drop(ctx
, A_NULL
);
198 for (int i
= 0; i
!= 10; ++i
)
200 int *obj
= A_VEC_PUSH_FORE(int, ctx
);
203 *obj
= rand() % 10; // NOLINT
205 a_vec_sort_fore(ctx
, cmp
);
209 a_vec_foreach(int, it
, ctx
)
216 a_vec_drop(ctx
, A_NULL
);
217 for (int i
= 0; i
!= 10; ++i
)
219 int *obj
= A_VEC_PUSH_BACK(int, ctx
);
222 *obj
= rand() % 10; // NOLINT
224 a_vec_sort_back(ctx
, cmp
);
228 a_vec_foreach(int, it
, ctx
)
235 a_str
*ok
= a_str_new();
236 a_str
*no
= a_str_new();
237 a_str_puts(ok
, "finding ");
238 a_str_puts(no
, "missing ");
239 for (int i
= 0; i
!= 10; ++i
)
241 int *obj
= A_VEC_SEARCH(int, ctx
, &i
, cmp
);
244 a_str_putf(ok
, "%i ", *obj
);
248 a_str_putf(no
, "%i ", i
);
251 printf("%s\n%s\n", a_str_ptr(ok
), a_str_ptr(no
));
256 a_vec_die(ctx
, A_NULL
);
259 int main(int argc
, char *argv
[]) // NOLINT(misc-definitions-in-headers)
263 printf("%s\n", A_FUNC
);