liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
que.h
Go to the documentation of this file.
1
6#ifndef LIBA_QUE_H
7#define LIBA_QUE_H
8
9#include "list.h"
10
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_move(a_que *ctx, a_que *obj);
137
145A_EXTERN void *a_que_at(a_que const *ctx, a_diff idx);
146#define A_QUE_AT(T, ctx, idx) a_cast_s(T *, a_que_at(ctx, idx))
147
156A_EXTERN int a_que_drop(a_que *ctx, void (*dtor)(void *));
157
167A_EXTERN int a_que_edit(a_que *ctx, a_size size, void (*dtor)(void *));
168
178A_EXTERN int a_que_swap(a_que const *ctx, a_size lhs, a_size rhs);
179
197A_EXTERN void a_que_sort_fore(a_que const *ctx, int (*cmp)(void const *, void const *));
198
216A_EXTERN void a_que_sort_back(a_que const *ctx, int (*cmp)(void const *, void const *));
217
229A_EXTERN void *a_que_push_sort(a_que *ctx, void const *key, int (*cmp)(void const *, void const *));
230#define A_QUE_PUSH_SORT(T, ctx, key, cmp) a_cast_s(T *, a_que_push_sort(ctx, key, cmp))
231
238A_EXTERN void *a_que_push_fore(a_que *ctx);
239#define A_QUE_PUSH_FORE(T, ctx) a_cast_s(T *, a_que_push_fore(ctx))
240
247A_EXTERN void *a_que_push_back(a_que *ctx);
248#define A_QUE_PUSH_BACK(T, ctx) a_cast_s(T *, a_que_push_back(ctx))
249
256A_EXTERN void *a_que_pull_fore(a_que *ctx);
257#define A_QUE_PULL_FORE(T, ctx) a_cast_s(T *, a_que_pull_fore(ctx))
258
265A_EXTERN void *a_que_pull_back(a_que *ctx);
266#define A_QUE_PULL_BACK(T, ctx) a_cast_s(T *, a_que_pull_back(ctx))
267
277A_EXTERN void *a_que_insert(a_que *ctx, a_size idx);
278#define A_QUE_INSERT(T, ctx, idx) a_cast_s(T *, a_que_insert(ctx, idx))
279
289A_EXTERN void *a_que_remove(a_que *ctx, a_size idx);
290#define A_QUE_REMOVE(T, ctx, idx) a_cast_s(T *, a_que_remove(ctx, idx))
291
292#if defined(__cplusplus)
293} /* extern "C" */
294#endif /* __cplusplus */
295
309#define a_que_foreach(T, P, it, ctx) \
310 for (T P it = a_cast_r(T P, (ctx)->head_.next), \
311 P it##_ = a_cast_r(T P, a_list_(*, it)->next); \
312 a_list_(*, it) != &(ctx)->head_ \
313 ? ((void)(it = a_cast_r(T P, a_list_(*, it) + 1)), 1) \
314 : (0); \
315 it = it##_, it##_ = a_cast_r(T P, a_list_(*, it)->next))
316
330#define a_que_foreach_reverse(T, P, it, ctx) \
331 for (T P it = a_cast_r(T P, (ctx)->head_.prev), \
332 P it##_ = a_cast_r(T P, a_list_(*, it)->prev); \
333 a_list_(*, it) != &(ctx)->head_ \
334 ? ((void)(it = a_cast_r(T P, a_list_(*, it) + 1)), 1) \
335 : (0); \
336 it = it##_, it##_ = a_cast_r(T P, a_list_(*, it)->prev))
337
340#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:482
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_push_sort(a_que *ctx, void const *key, int(*cmp)(void const *, void const *))
push an element into the queue and sort it
int a_que_swap(a_que const *ctx, size_t lhs, size_t rhs)
swap elements lhs and rhs for a pointer to queue structure
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
void * a_que_back_(a_que const *ctx)
access backmost element for a pointer to queue structure
Definition que.h:60
void a_que_move(a_que *ctx, a_que *obj)
initialize a pointer to queue structure by moving
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
struct a_que a_que
instance structure for basic queue
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
int a_que_edit(a_que *ctx, size_t size, void(*dtor)(void *))
edit size of a element for a pointer to queue structure
void * a_que_remove(a_que *ctx, size_t idx)
remove an element from the queue
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
void * a_que_at(a_que const *ctx, ptrdiff_t idx)
access specified element for a pointer to queue structure
size_t a_que_siz(a_que const *ctx)
access size of a element for a pointer to queue structure
Definition que.h:34
size_t a_que_num(a_que const *ctx)
access number of element for a pointer to queue structure
Definition que.h:40
void a_que_ctor(a_que *ctx, size_t 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
a_que * a_que_new(size_t size)
allocate a pointer to queue structure from memory
void * a_que_insert(a_que *ctx, size_t idx)
insert an element into the queue
void a_que_swap_(void *lhs, void *rhs)
swap elements lhs and rhs for a pointer to queue structure
Definition que.h:95
#define a_size
Definition a.h:610
#define a_diff
Definition a.h:598
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
size_t cur_
Definition que.h:26
a_list ** ptr_
Definition que.h:23
size_t siz_
Definition que.h:24
a_list head_
Definition que.h:22
size_t num_
Definition que.h:25
size_t mem_
Definition que.h:27