6 static void dtor(void *ptr
)
8 a_u32
*obj
= a_u32_(*, ptr
);
9 printf("%" PRIu32
" ", *obj
);
12 static void back(void)
16 a_buf_ctor(&ctx
, buf
, sizeof(a_u32
), 10);
18 for (a_u32 i
= 0; i
!= 20; ++i
)
20 a_u32
*obj
= a_buf_push_back(a_u32
, &ctx
);
21 if (obj
) { *obj
= i
; }
24 a_buf_foreach(a_u32
, it
, &ctx
)
26 printf("%" PRIu32
" ", *it
);
30 for (a_u32 i
= 0; i
!= 20; ++i
)
32 a_u32
*obj
= a_buf_pull_back(a_u32
, &ctx
);
33 if (obj
) { printf("%" PRIu32
" ", *obj
); }
37 a_buf_dtor(&ctx
, dtor
);
40 static void fore(void)
44 a_buf_ctor(&ctx
, buf
, sizeof(a_u32
), 10);
46 for (a_u32 i
= 0; i
!= 20; ++i
)
48 a_u32
*obj
= a_buf_push_fore(a_u32
, &ctx
);
49 if (obj
) { *obj
= i
; }
52 a_buf_foreach_reverse(a_u32
, it
, &ctx
)
54 printf("%" PRIu32
" ", *it
);
58 for (a_u32 i
= 0; i
!= 20; ++i
)
60 a_u32
*obj
= a_buf_pull_fore(a_u32
, &ctx
);
61 if (obj
) { printf("%" PRIu32
" ", *obj
); }
65 a_buf_dtor(&ctx
, dtor
);
71 static int cmp(void const *lhs
, void const *rhs
)
73 return *a_int_(const *, lhs
) - *a_int_(const *, rhs
);
76 static int cmpr(void const *lhs
, void const *rhs
)
78 return *a_int_(const *, rhs
) - *a_int_(const *, lhs
);
81 static int rand10(void)
83 return a_cast_s(int, rand() / a_cast_s(double, RAND_MAX
) * 10); // NOLINT
86 static void test_sort(void)
90 unsigned int t
= a_cast_s(unsigned int, time(A_NULL
));
91 a_buf_ctor(&ctx
, buf
, sizeof(int), 10);
94 a_buf_drop(&ctx
, A_NULL
);
95 for (int i
= 0; i
!= 10; ++i
)
97 int *obj
= a_buf_push_fore(int, &ctx
);
102 a_buf_sort_fore(&ctx
, cmp
);
106 a_buf_foreach(int, it
, &ctx
)
113 a_buf_drop(&ctx
, A_NULL
);
114 for (int i
= 0; i
!= 10; ++i
)
116 int *obj
= a_buf_push_back(int, &ctx
);
121 a_buf_sort_back(&ctx
, cmp
);
125 a_buf_foreach(int, it
, &ctx
)
132 a_buf_foreach(int, it
, &ctx
)
138 a_buf_sort(&ctx
, cmp
);
139 a_buf_foreach(int, it
, &ctx
)
146 a_buf_foreach(int, it
, &ctx
)
152 a_buf_sort(&ctx
, cmpr
);
153 a_buf_foreach(int, it
, &ctx
)
160 a_str
*ok
= a_str_new();
161 a_str
*no
= a_str_new();
162 a_str_puts(ok
, "finding ");
163 a_str_puts(no
, "missing ");
164 for (int i
= 0; i
!= 10; ++i
)
166 int *obj
= a_buf_search(int, &ctx
, &i
, cmp
);
169 a_str_putf(ok
, "%i ", *obj
);
173 a_str_putf(no
, "%i ", i
);
176 printf("%s\n%s\n", a_str_ptr(ok
), a_str_ptr(no
));
181 a_buf_dtor(&ctx
, A_NULL
);
184 int main(int argc
, char *argv
[]) // NOLINT(misc-definitions-in-headers)
188 printf("%s\n", A_FUNC
);