5 static void dtor(void *ptr
)
7 a_u32
*u
= a_u32_(*, ptr
);
8 printf("%" PRIu32
" ", *u
);
11 static void test(void)
13 a_que
*ctx
= a_que_new(sizeof(a_u64
));
14 for (a_u64 i
= 0; i
!= 10; ++i
)
16 a_u64
*obj
= a_que_push_back(a_u64
, ctx
);
17 if (obj
) { *obj
= i
; }
20 a_u64
*fore
= a_que_fore_(a_u64
, ctx
);
21 a_u64
*back
= a_que_back_(a_u64
, ctx
);
22 printf("%" PRIu64
" %" PRIu64
" ", *fore
, *back
);
25 a_u64
*fore
= a_que_fore(a_u64
, ctx
);
26 a_u64
*back
= a_que_back(a_u64
, ctx
);
29 printf("%" PRIu64
" %" PRIu64
" ", *fore
, *back
);
33 a_u64
*fore
= a_que_at(a_u64
, ctx
, 0);
34 a_u64
*back
= a_que_at(a_u64
, ctx
, ~0);
37 printf("%" PRIu64
" %" PRIu64
"\n", *fore
, *back
);
40 for (a_u64 i
= 0; i
!= 5; ++i
)
42 (void)(a_que_pull_fore(a_u64
, ctx
));
44 a_que_edit(ctx
, sizeof(a_u32
) + 8, A_NULL
);
45 for (a_u32 i
= 5; i
--;)
47 a_u32
*obj
= a_que_push_fore(a_u32
, ctx
);
48 if (obj
) { *obj
= i
; }
50 for (a_u32 i
= 5; i
!= 10; ++i
)
52 a_u32
*obj
= a_que_push_back(a_u32
, ctx
);
53 if (obj
) { *obj
= i
; }
56 a_u32
*obj
= a_que_insert(a_u32
, ctx
, 0);
57 if (obj
) { *obj
= A_U32_MAX
; }
60 a_u32
*obj
= a_que_insert(a_u32
, ctx
, A_SIZE_MAX
);
61 if (obj
) { *obj
= A_U32_MAX
; }
63 (void)(a_que_remove(a_u32
, ctx
, 0));
64 (void)(a_que_remove(a_u32
, ctx
, A_SIZE_MAX
));
65 a_que_swap(ctx
, 0, A_SIZE_MAX
);
67 a_u32
*lhs
= a_que_fore_(a_u32
, ctx
);
68 a_u32
*rhs
= a_que_back_(a_u32
, ctx
);
69 a_que_swap_(lhs
, rhs
);
71 a_que_foreach(a_u32
, it
, ctx
)
73 TEST_BUG(a_que_siz(ctx
) >= sizeof(*it
));
74 printf("%" PRIu32
" ", *it
);
77 a_que_foreach_reverse(a_u32
, it
, ctx
)
79 TEST_BUG(a_que_siz(ctx
) >= sizeof(*it
));
80 printf("%" PRIu32
" ", *it
);
83 for (a_u32 i
= 0; i
!= 5; ++i
)
85 (void)(a_que_pull_back(a_u32
, ctx
));
87 for (a_u32 i
= 0; i
!= 5; ++i
)
89 (void)(a_que_pull_fore(a_u32
, ctx
));
97 static int cmp(void const *lhs
, void const *rhs
)
99 return *a_int_(const *, lhs
) - *a_int_(const *, rhs
);
102 static int cmpr(void const *lhs
, void const *rhs
)
104 return *a_int_(const *, rhs
) - *a_int_(const *, lhs
);
107 static void test_sort(void)
109 unsigned int t
= a_cast_s(unsigned int, time(A_NULL
));
110 a_que
*ctx
= a_que_new(sizeof(int));
113 a_que_drop(ctx
, A_NULL
);
114 for (int i
= 0; i
!= 10; ++i
)
116 int *obj
= a_que_push_fore(int, ctx
);
119 *obj
= rand() % 10; // NOLINT
121 a_que_sort_fore(ctx
, cmp
);
125 a_que_foreach(int, it
, ctx
)
132 a_que_drop(ctx
, dtor
);
134 for (int i
= 0; i
!= 10; ++i
)
136 int *obj
= a_que_push_back(int, ctx
);
139 *obj
= rand() % 10; // NOLINT
141 a_que_sort_back(ctx
, cmpr
);
145 a_que_foreach(int, it
, ctx
)
151 a_que_die(ctx
, dtor
);
155 int main(int argc
, char *argv
[]) // NOLINT(misc-definitions-in-headers)
159 printf("%s\n", A_FUNC
);