liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
basic queue library
Collaboration diagram for basic queue library:

Data Structures

struct  a_que
 instance structure for basic queue More...
 

Macros

#define A_QUE_FORE_(T, ctx)
 
#define A_QUE_BACK_(T, ctx)
 
#define A_QUE_FORE(T, ctx)
 
#define A_QUE_BACK(T, ctx)
 
#define A_QUE_AT(T, ctx, idx)
 
#define A_QUE_PUSH_SORT(T, ctx, key, cmp)
 
#define A_QUE_PUSH_FORE(T, ctx)
 
#define A_QUE_PUSH_BACK(T, ctx)
 
#define A_QUE_PULL_FORE(T, ctx)
 
#define A_QUE_PULL_BACK(T, ctx)
 
#define A_QUE_INSERT(T, ctx, idx)
 
#define A_QUE_REMOVE(T, ctx, idx)
 
#define a_que_foreach(T, P, it, ctx)
 iterate over a queue
 
#define a_que_foreach_reverse(T, P, it, ctx)
 iterate over a queue in reverse
 

Typedefs

typedef struct a_que a_que
 instance structure for basic queue
 

Functions

size_t a_que_siz (a_que const *ctx)
 access size of a element for a pointer to queue structure
 
size_t a_que_num (a_que const *ctx)
 access number of element for a pointer to queue structure
 
void * a_que_fore_ (a_que const *ctx)
 access foremost element for a pointer to queue structure
 
void * a_que_back_ (a_que const *ctx)
 access backmost element for a pointer to queue structure
 
void * a_que_fore (a_que const *ctx)
 access foremost element for a pointer to queue structure
 
void * a_que_back (a_que const *ctx)
 access backmost element 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
 
a_quea_que_new (size_t size)
 allocate a pointer to queue structure from memory
 
void a_que_die (a_que *ctx, void(*dtor)(void *))
 deallocate a pointer to queue structure
 
void a_que_ctor (a_que *ctx, size_t size)
 constructor for queue structure
 
void a_que_dtor (a_que *ctx, void(*dtor)(void *))
 destructor for queue structure
 
void a_que_move (a_que *ctx, a_que *obj)
 initialize a pointer to queue structure by moving
 
void * a_que_at (a_que const *ctx, ptrdiff_t idx)
 access specified element for a pointer to queue structure
 
int a_que_drop (a_que *ctx, void(*dtor)(void *))
 drop all the elements 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
 
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_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_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_push_sort (a_que *ctx, void const *key, int(*cmp)(void const *, void const *))
 push an element into the queue and sort it
 
void * a_que_push_fore (a_que *ctx)
 push an element into the queue forward
 
void * a_que_push_back (a_que *ctx)
 push an element into the queue backward
 
void * a_que_pull_fore (a_que *ctx)
 pull an element from the queue forward
 
void * a_que_pull_back (a_que *ctx)
 pull an element from the queue backward
 
void * a_que_insert (a_que *ctx, size_t idx)
 insert an element into the queue
 
void * a_que_remove (a_que *ctx, size_t idx)
 remove an element from the queue
 

Detailed Description

Macro Definition Documentation

◆ A_QUE_AT

#define A_QUE_AT ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_que_at(ctx, idx))
void * a_que_at(a_que const *ctx, ptrdiff_t idx)
access specified element for a pointer to queue structure

◆ A_QUE_BACK

#define A_QUE_BACK ( T,
ctx )
Value:
a_cast_s(T *, a_que_back(ctx))
void * a_que_back(a_que const *ctx)
access backmost element for a pointer to queue structure
Definition que.h:84

◆ A_QUE_BACK_

#define A_QUE_BACK_ ( T,
ctx )
Value:
a_cast_s(T *, a_que_back_(ctx))
void * a_que_back_(a_que const *ctx)
access backmost element for a pointer to queue structure
Definition que.h:60

◆ A_QUE_FORE

#define A_QUE_FORE ( T,
ctx )
Value:
a_cast_s(T *, a_que_fore(ctx))
void * a_que_fore(a_que const *ctx)
access foremost element for a pointer to queue structure
Definition que.h:72

◆ A_QUE_FORE_

#define A_QUE_FORE_ ( T,
ctx )
Value:
a_cast_s(T *, a_que_fore_(ctx))
void * a_que_fore_(a_que const *ctx)
access foremost element for a pointer to queue structure
Definition que.h:48

◆ a_que_foreach

#define a_que_foreach ( T,
P,
it,
ctx )
Value:
for (T P it = a_cast_r(T P, (ctx)->head_.next), \
P it##_ = a_cast_r(T P, a_list_(*, it)->next); \
a_list_(*, it) != &(ctx)->head_ \
? ((void)(it = a_cast_r(T P, a_list_(*, it) + 1)), 1) \
: (0); \
it = it##_, it##_ = a_cast_r(T P, a_list_(*, it)->next))
#define a_list_(_, x)
cast a list pointer from another type pointer
Definition list.h:35

iterate over a queue

a_que_foreach(T, *, it, ctx)
{
assert(a_que_siz(ctx) >= sizeof(*it));
}
#define a_que_foreach(T, P, it, ctx)
iterate over a queue
Definition que.h:309
size_t a_que_siz(a_que const *ctx)
access size of a element for a pointer to queue structure
Definition que.h:34
Parameters
Tthe prefix of the element type
Pthe suffix of the element type
itthe &a_que to use as a loop counter
ctxpoints to an instance of queue structure

◆ a_que_foreach_reverse

#define a_que_foreach_reverse ( T,
P,
it,
ctx )
Value:
for (T P it = a_cast_r(T P, (ctx)->head_.prev), \
P it##_ = a_cast_r(T P, a_list_(*, it)->prev); \
a_list_(*, it) != &(ctx)->head_ \
? ((void)(it = a_cast_r(T P, a_list_(*, it) + 1)), 1) \
: (0); \
it = it##_, it##_ = a_cast_r(T P, a_list_(*, it)->prev))

iterate over a queue in reverse

a_que_foreach_reverse(T, *, it, ctx)
{
assert(a_que_siz(ctx) >= sizeof(*it));
}
#define a_que_foreach_reverse(T, P, it, ctx)
iterate over a queue in reverse
Definition que.h:330
Parameters
Tthe prefix of the element type
Pthe suffix of the element type
itthe &a_que to use as a loop counter
ctxpoints to an instance of queue structure

◆ A_QUE_INSERT

#define A_QUE_INSERT ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_que_insert(ctx, idx))
void * a_que_insert(a_que *ctx, size_t idx)
insert an element into the queue

◆ A_QUE_PULL_BACK

#define A_QUE_PULL_BACK ( T,
ctx )
Value:
a_cast_s(T *, a_que_pull_back(ctx))
void * a_que_pull_back(a_que *ctx)
pull an element from the queue backward

◆ A_QUE_PULL_FORE

#define A_QUE_PULL_FORE ( T,
ctx )
Value:
a_cast_s(T *, a_que_pull_fore(ctx))
void * a_que_pull_fore(a_que *ctx)
pull an element from the queue forward

◆ A_QUE_PUSH_BACK

#define A_QUE_PUSH_BACK ( T,
ctx )
Value:
a_cast_s(T *, a_que_push_back(ctx))
void * a_que_push_back(a_que *ctx)
push an element into the queue backward

◆ A_QUE_PUSH_FORE

#define A_QUE_PUSH_FORE ( T,
ctx )
Value:
a_cast_s(T *, a_que_push_fore(ctx))
void * a_que_push_fore(a_que *ctx)
push an element into the queue forward

◆ A_QUE_PUSH_SORT

#define A_QUE_PUSH_SORT ( T,
ctx,
key,
cmp )
Value:
a_cast_s(T *, a_que_push_sort(ctx, key, cmp))
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_REMOVE

#define A_QUE_REMOVE ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_que_remove(ctx, idx))
void * a_que_remove(a_que *ctx, size_t idx)
remove an element from the queue

Function Documentation

◆ a_que_at()

void * a_que_at ( a_que const * ctx,
ptrdiff_t idx )

access specified element for a pointer to queue structure

Parameters
[in]ctxpoints to an instance of queue structure
[in]idxindex of element, 0 ~ n-1, -n ~ -1
Returns
element pointer
Return values
0out of bounds

◆ a_que_back()

void * a_que_back ( a_que const * ctx)

access backmost element for a pointer to queue structure

Parameters
[in]ctxpoints to an instance of queue structure
Returns
element pointer
Return values
0empty queue

◆ a_que_back_()

void * a_que_back_ ( a_que const * ctx)

access backmost element for a pointer to queue structure

Parameters
[in]ctxpoints to an instance of queue structure
Note
should check if queue is empty
Returns
element pointer

◆ a_que_ctor()

void a_que_ctor ( a_que * ctx,
size_t size )

constructor for queue structure

Parameters
[in]ctxpoints to an instance of queue structure
[in]sizesize of element

◆ a_que_die()

void a_que_die ( a_que * ctx,
void(* dtor )(void *) )

deallocate a pointer to queue structure

Parameters
[in]ctxpoints to an instance of queue structure
[in]dtorelement destructor

◆ a_que_drop()

int a_que_drop ( a_que * ctx,
void(* dtor )(void *) )

drop all the elements for a pointer to queue structure

Parameters
[in]ctxpoints to an instance of queue structure
[in]dtorcurrent element destructor
Returns
the execution state of the function
Return values
0success
1failure

◆ a_que_dtor()

void a_que_dtor ( a_que * ctx,
void(* dtor )(void *) )

destructor for queue structure

Parameters
[in]ctxpoints to an instance of queue structure
[in]dtorelement destructor

◆ a_que_edit()

int a_que_edit ( a_que * ctx,
size_t size,
void(* dtor )(void *) )

edit size of a element for a pointer to queue structure

Parameters
[in]ctxpoints to an instance of queue structure
[in]sizethe size of the new element
[in]dtorprevious element destructor
Returns
the execution state of the function
Return values
0success
1failure

◆ a_que_fore()

void * a_que_fore ( a_que const * ctx)

access foremost element for a pointer to queue structure

Parameters
[in]ctxpoints to an instance of queue structure
Returns
element pointer
Return values
0empty queue

◆ a_que_fore_()

void * a_que_fore_ ( a_que const * ctx)

access foremost element for a pointer to queue structure

Parameters
[in]ctxpoints to an instance of queue structure
Note
should check if queue is empty
Returns
element pointer

◆ a_que_insert()

void * a_que_insert ( a_que * ctx,
size_t idx )

insert an element into the queue

Parameters
[in]ctxpoints to an instance of queue structure
[in]idxindex of element in this queue
  • 0 a_que_push_fore
  • n a_que_push_back
Returns
element pointer
Return values
0failure

◆ a_que_move()

void a_que_move ( a_que * ctx,
a_que * obj )

initialize a pointer to queue structure by moving

Parameters
[in]ctxpoints to an instance of queue structure
[in]objinput source pointing to an instance

◆ a_que_new()

a_que * a_que_new ( size_t size)

allocate a pointer to queue structure from memory

Parameters
[in]sizesize of element

◆ a_que_num()

size_t a_que_num ( a_que const * ctx)

access number of element for a pointer to queue structure

Parameters
[in]ctxpoints to an instance of queue structure

◆ a_que_pull_back()

void * a_que_pull_back ( a_que * ctx)

pull an element from the queue backward

Parameters
[in]ctxpoints to an instance of queue structure
Returns
element pointer
Return values
0failure

◆ a_que_pull_fore()

void * a_que_pull_fore ( a_que * ctx)

pull an element from the queue forward

Parameters
[in]ctxpoints to an instance of queue structure
Returns
element pointer
Return values
0failure

◆ a_que_push_back()

void * a_que_push_back ( a_que * ctx)

push an element into the queue backward

Parameters
[in]ctxpoints to an instance of queue structure
Returns
element pointer
Return values
0failure

◆ a_que_push_fore()

void * a_que_push_fore ( a_que * ctx)

push an element into the queue forward

Parameters
[in]ctxpoints to an instance of queue structure
Returns
element pointer
Return values
0failure

◆ a_que_push_sort()

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

Parameters
[in]ctxpoints to an instance of queue structure
[in]keythe key on the right for insertion sort
[in]cmpa function that compares two elements
  • cmp(lhs,rhs)==0 *lhs is equivalent to *rhs
  • cmp(lhs,rhs)<0 *lhs goes before *rhs
  • cmp(lhs,rhs)>0 *lhs goes after *rhs
Returns
element pointer
Return values
0failure

◆ a_que_remove()

void * a_que_remove ( a_que * ctx,
size_t idx )

remove an element from the queue

Parameters
[in]ctxpoints to an instance of queue structure
[in]idxindex of element in this queue
  • 0 a_que_pull_fore
  • n a_que_pull_back
Returns
element pointer
Return values
0failure

◆ a_que_siz()

size_t a_que_siz ( a_que const * ctx)

access size of a element for a pointer to queue structure

Parameters
[in]ctxpoints to an instance of queue structure

◆ a_que_sort_back()

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

T *obj = A_QUE_PUSH_BACK(T, ctx);
if (obj)
{
CTOR(obj);
INIT(obj);
a_que_sort_back(ctx, cmp);
}
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
Parameters
[in]ctxpoints to an instance of queue structure
[in]cmpa function that compares two elements
  • cmp(lhs,rhs)==0 *lhs is equivalent to *rhs
  • cmp(lhs,rhs)<0 *lhs goes before *rhs
  • cmp(lhs,rhs)>0 *lhs goes after *rhs

◆ a_que_sort_fore()

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

T *obj = A_QUE_PUSH_FORE(T, ctx);
if (obj)
{
CTOR(obj);
INIT(obj);
a_que_sort_fore(ctx, cmp);
}
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
Parameters
[in]ctxpoints to an instance of queue structure
[in]cmpa function that compares two elements
  • cmp(lhs,rhs)==0 *lhs is equivalent to *rhs
  • cmp(lhs,rhs)<0 *lhs goes before *rhs
  • cmp(lhs,rhs)>0 *lhs goes after *rhs

◆ a_que_swap()

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

Parameters
[in]ctxpoints to an instance of queue structure
[in]lhselement index on the left
[in]rhselement index on the right
Returns
the execution state of the function
Return values
0success
1failure

◆ a_que_swap_()

void a_que_swap_ ( void * lhs,
void * rhs )

swap elements lhs and rhs for a pointer to queue structure

Parameters
[in]lhselement pointer on the left
[in]rhselement pointer on the right