liba 0.1.15
An algorithm library based on C/C++
 
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
Loading...
Searching...
No Matches
que.h
Go to the documentation of this file.
1
5
6#ifndef LIBA_QUE_H
7#define LIBA_QUE_H
8
9#include "list.h"
10
16
29
34A_INTERN a_size a_que_siz(a_que const *ctx) { return ctx->siz_; }
35
40A_INTERN a_size a_que_num(a_que const *ctx) { return ctx->num_; }
41
48A_INTERN void *a_que_fore_(a_que const *ctx)
49{
50 return a_cast_s(void *, ctx->head_.next + 1);
51}
52#define A_QUE_FORE_(T, ctx) a_cast_s(T *, a_que_fore_(ctx))
53
60A_INTERN void *a_que_back_(a_que const *ctx)
61{
62 return a_cast_s(void *, ctx->head_.prev + 1);
63}
64#define A_QUE_BACK_(T, ctx) a_cast_s(T *, a_que_back_(ctx))
65
72A_INTERN void *a_que_fore(a_que const *ctx)
73{
74 return ctx->head_.next != &ctx->head_ ? a_que_fore_(ctx) : A_NULL;
75}
76#define A_QUE_FORE(T, ctx) a_cast_s(T *, a_que_fore(ctx))
77
84A_INTERN void *a_que_back(a_que const *ctx)
85{
86 return ctx->head_.prev != &ctx->head_ ? a_que_back_(ctx) : A_NULL;
87}
88#define A_QUE_BACK(T, ctx) a_cast_s(T *, a_que_back(ctx))
89
95A_INTERN void a_que_swap_(void *lhs, void *rhs)
96{
97 a_list_swap_node(a_cast_s(a_list *, lhs) - 1, a_cast_s(a_list *, rhs) - 1);
98}
99
100#if defined(__cplusplus)
101extern "C" {
102#endif /* __cplusplus */
103
108A_EXTERN a_que *a_que_new(a_size size);
109
115A_EXTERN void a_que_die(a_que *ctx, void (*dtor)(void *));
116
122A_EXTERN void a_que_ctor(a_que *ctx, a_size size);
123
129A_EXTERN void a_que_dtor(a_que *ctx, void (*dtor)(void *));
130
136A_EXTERN void a_que_swap(a_que *lhs, a_que *rhs);
137
145A_EXTERN int a_que_drop(a_que *ctx, void (*dtor)(void *));
146
155A_EXTERN int a_que_setz(a_que *ctx, a_size siz, void (*dtor)(void *));
156
164A_EXTERN void *a_que_at(a_que const *ctx, a_diff idx);
165#define A_QUE_AT(T, ctx, idx) a_cast_s(T *, a_que_at(ctx, idx))
166
184A_EXTERN void a_que_sort_fore(a_que const *ctx, int (*cmp)(void const *, void const *));
185
203A_EXTERN void a_que_sort_back(a_que const *ctx, int (*cmp)(void const *, void const *));
204
216A_EXTERN void *a_que_push_sort(a_que *ctx, void const *key, int (*cmp)(void const *, void const *));
217#define A_QUE_PUSH_SORT(T, ctx, key, cmp) a_cast_s(T *, a_que_push_sort(ctx, key, cmp))
218
225A_EXTERN void *a_que_push_fore(a_que *ctx);
226#define A_QUE_PUSH_FORE(T, ctx) a_cast_s(T *, a_que_push_fore(ctx))
227
234A_EXTERN void *a_que_push_back(a_que *ctx);
235#define A_QUE_PUSH_BACK(T, ctx) a_cast_s(T *, a_que_push_back(ctx))
236
243A_EXTERN void *a_que_pull_fore(a_que *ctx);
244#define A_QUE_PULL_FORE(T, ctx) a_cast_s(T *, a_que_pull_fore(ctx))
245
252A_EXTERN void *a_que_pull_back(a_que *ctx);
253#define A_QUE_PULL_BACK(T, ctx) a_cast_s(T *, a_que_pull_back(ctx))
254
264A_EXTERN void *a_que_insert(a_que *ctx, a_size idx);
265#define A_QUE_INSERT(T, ctx, idx) a_cast_s(T *, a_que_insert(ctx, idx))
266
276A_EXTERN void *a_que_remove(a_que *ctx, a_size idx);
277#define A_QUE_REMOVE(T, ctx, idx) a_cast_s(T *, a_que_remove(ctx, idx))
278
279#if defined(__cplusplus)
280} /* extern "C" */
281#endif /* __cplusplus */
282
296#define a_que_foreach(T, S, it, ctx) \
297 for (T S it = a_cast_r(T S, (ctx)->head_.next), \
298 S it##_ = a_cast_r(T S, a_list_(*, it)->next); \
299 a_list_(*, it) != &(ctx)->head_ \
300 ? ((void)(it = a_cast_r(T S, a_list_(*, it) + 1)), 1) \
301 : (0); \
302 it = it##_, it##_ = a_cast_r(T S, a_list_(*, it)->next))
303#define A_QUE_FOREACH(T, it, at, ctx) \
304 for ((void)(it = a_cast_r(T, (ctx)->head_.next)), \
305 at = a_cast_r(T, a_list_(*, it)->next); \
306 a_list_(*, it) != &(ctx)->head_ \
307 ? ((void)(it = a_cast_r(T, a_list_(*, it) + 1)), 1) \
308 : (0); \
309 it = at, at = a_cast_r(T, a_list_(*, it)->next))
310
324#define a_que_foreach_reverse(T, S, it, ctx) \
325 for (T S it = a_cast_r(T S, (ctx)->head_.prev), \
326 S it##_ = a_cast_r(T S, a_list_(*, it)->prev); \
327 a_list_(*, it) != &(ctx)->head_ \
328 ? ((void)(it = a_cast_r(T S, a_list_(*, it) + 1)), 1) \
329 : (0); \
330 it = it##_, it##_ = a_cast_r(T S, a_list_(*, it)->prev))
331#define A_QUE_FOREACH_REVERSE(T, it, at, ctx) \
332 for ((void)(it = a_cast_r(T, (ctx)->head_.prev)), \
333 at = a_cast_r(T, a_list_(*, it)->prev); \
334 a_list_(*, it) != &(ctx)->head_ \
335 ? ((void)(it = a_cast_r(T, a_list_(*, it) + 1)), 1) \
336 : (0); \
337 it = at, at = a_cast_r(T, a_list_(*, it)->prev))
338
340
341#endif /* a/que.h */
void a_list_swap_node(a_list *lhs, a_list *rhs)
swap the node lhs and the node rhs
Definition list.h:490
void a_que_sort_fore(a_que const *ctx, int(*cmp)(void const *, void const *))
insert sort foremost element for a pointer to queue structure
void * a_que_at(a_que const *ctx, a_diff idx)
access specified element for a pointer to queue structure
void * a_que_push_sort(a_que *ctx, void const *key, int(*cmp)(void const *, void const *))
push an element into the queue and sort it
a_que * a_que_new(a_size size)
allocate a pointer to queue structure from memory
void * a_que_pull_fore(a_que *ctx)
pull an element from the queue forward
void * a_que_push_back(a_que *ctx)
push an element into the queue backward
int a_que_setz(a_que *ctx, a_size siz, void(*dtor)(void *))
set size of a element for a pointer to queue structure
void * a_que_back_(a_que const *ctx)
access backmost element for a pointer to queue structure
Definition que.h:60
a_size a_que_num(a_que const *ctx)
access number of element for a pointer to queue structure
Definition que.h:40
void * a_que_back(a_que const *ctx)
access backmost element for a pointer to queue structure
Definition que.h:84
void a_que_dtor(a_que *ctx, void(*dtor)(void *))
destructor for queue structure
void a_que_die(a_que *ctx, void(*dtor)(void *))
deallocate a pointer to queue structure
void * a_que_fore(a_que const *ctx)
access foremost element for a pointer to queue structure
Definition que.h:72
void a_que_sort_back(a_que const *ctx, int(*cmp)(void const *, void const *))
insert sort backmost element for a pointer to queue structure
void * a_que_insert(a_que *ctx, a_size idx)
insert an element into the queue
void a_que_swap(a_que *lhs, a_que *rhs)
initialize a pointer to queue structure by moving
void * a_que_push_fore(a_que *ctx)
push an element into the queue forward
void * a_que_pull_back(a_que *ctx)
pull an element from the queue backward
void * a_que_fore_(a_que const *ctx)
access foremost element for a pointer to queue structure
Definition que.h:48
a_size a_que_siz(a_que const *ctx)
access size of a element for a pointer to queue structure
Definition que.h:34
void * a_que_remove(a_que *ctx, a_size idx)
remove an element from the queue
void a_que_ctor(a_que *ctx, a_size size)
constructor for queue structure
int a_que_drop(a_que *ctx, void(*dtor)(void *))
drop all the elements for a pointer to queue structure
void a_que_swap_(void *lhs, void *rhs)
swap elements lhs and rhs for a pointer to queue structure
Definition que.h:95
ptrdiff_t a_diff
signed integer type returned when subtracting two pointers
Definition a.h:780
size_t a_size
unsigned integer type returned by the sizeof operator
Definition a.h:823
circular doubly linked list implementation
instance structure for circular doubly linked list
Definition list.h:25
instance structure for basic queue
Definition que.h:21
a_size cur_
Definition que.h:26
a_size siz_
Definition que.h:24
a_list ** ptr_
Definition que.h:23
a_size num_
Definition que.h:25
a_size mem_
Definition que.h:27
a_list head_
Definition que.h:22