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

Data Structures

struct  a_buf
 instance structure for basic buffer More...
 

Macros

#define A_BUF_PTR(T, ctx)
 
#define A_BUF_AT_(T, ctx, idx)
 
#define A_BUF_AT(T, ctx, idx)
 
#define A_BUF_IDX(T, ctx, idx)
 
#define A_BUF_TOP_(T, ctx)
 
#define A_BUF_TOP(T, ctx)
 
#define A_BUF_END(T, ctx)
 
#define A_BUF_PUSH_SORT(T, ctx, key, cmp)
 
#define A_BUF_SEARCH(T, ctx, obj, cmp)
 
#define A_BUF_INSERT(T, ctx, idx)
 
#define A_BUF_REMOVE(T, ctx, idx)
 
#define A_BUF_PUSH_FORE(T, ctx)
 
#define A_BUF_PUSH_BACK(T, ctx)
 
#define A_BUF_PULL_FORE(T, ctx)
 
#define A_BUF_PULL_BACK(T, ctx)
 
#define A_BUF_PUSH(T, ctx)
 
#define A_BUF_PULL(T, ctx)
 
#define a_buf_forenum(i, ctx)
 iterate over a buffer
 
#define a_buf_forenum_reverse(i, ctx)
 iterate over a buffer in reverse
 
#define a_buf_foreach(T, P, it, ctx)
 iterate over a buffer
 
#define a_buf_foreach_reverse(T, P, it, ctx)
 iterate over a buffer in reverse
 

Typedefs

typedef struct a_buf a_buf
 instance structure for basic buffer
 

Functions

void * a_buf_ptr (a_buf const *ctx)
 access address of buffer for a pointer to buffer structure
 
size_t a_buf_siz (a_buf const *ctx)
 access size of a element for a pointer to buffer structure
 
size_t a_buf_num (a_buf const *ctx)
 access number of element for a pointer to buffer structure
 
size_t a_buf_mem (a_buf const *ctx)
 access memory of element for a pointer to buffer structure
 
void * a_buf_at_ (a_buf const *ctx, size_t idx)
 access specified element for a pointer to buffer structure
 
void * a_buf_at (a_buf const *ctx, size_t idx)
 access specified element for a pointer to buffer structure
 
void * a_buf_idx (a_buf const *ctx, ptrdiff_t idx)
 access specified element for a pointer to buffer structure
 
void * a_buf_top_ (a_buf const *ctx)
 access top element for a pointer to buffer structure
 
void * a_buf_top (a_buf const *ctx)
 access top element for a pointer to buffer structure
 
void * a_buf_end (a_buf const *ctx)
 access end pointer for a pointer to buffer structure
 
void a_buf_ctor (a_buf *ctx, void *ptr, size_t siz, size_t num)
 constructor for buffer structure
 
void a_buf_dtor (a_buf *ctx, void(*dtor)(void *))
 destructor for buffer structure
 
void a_buf_move (a_buf *ctx, a_buf *obj)
 initialize a pointer to buffer structure by moving
 
void a_buf_drop (a_buf *ctx, void(*dtor)(void *))
 drop all the elements for a pointer to buffer structure
 
void a_buf_swap (a_buf const *ctx, size_t lhs, size_t rhs)
 swap elements lhs and rhs for a pointer to buffer structure
 
void a_buf_sort (a_buf const *ctx, int(*cmp)(void const *, void const *))
 sort all elements for a pointer to buffer structure
 
void a_buf_sort_fore (a_buf const *ctx, int(*cmp)(void const *, void const *))
 insert sort foremost element for a pointer to buffer structure
 
void a_buf_sort_back (a_buf const *ctx, int(*cmp)(void const *, void const *))
 insert sort backmost element for a pointer to buffer structure
 
void * a_buf_push_sort (a_buf *ctx, void const *key, int(*cmp)(void const *, void const *))
 push an element into the buffer and sort it
 
void * a_buf_search (a_buf const *ctx, void const *obj, int(*cmp)(void const *, void const *))
 search the given element in this buffer
 
void * a_buf_insert (a_buf *ctx, size_t idx)
 insert an element into the buffer
 
void * a_buf_remove (a_buf *ctx, size_t idx)
 remove an element from the buffer
 
void * a_buf_push_fore (a_buf *ctx)
 push an element into the buffer forward
 
void * a_buf_push_back (a_buf *ctx)
 push an element into the buffer backward
 
void * a_buf_pull_fore (a_buf *ctx)
 pull an element from the buffer forward
 
void * a_buf_pull_back (a_buf *ctx)
 pull an element from the buffer backward
 
void * a_buf_push (a_buf *ctx)
 push an element into the buffer
 
void * a_buf_pull (a_buf *ctx)
 pull an element from the buffer
 

Detailed Description

Macro Definition Documentation

◆ A_BUF_AT

#define A_BUF_AT ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_buf_at(ctx, idx))
void * a_buf_at(a_buf const *ctx, size_t idx)
access specified element for a pointer to buffer structure
Definition buf.h:73

◆ A_BUF_AT_

#define A_BUF_AT_ ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_buf_at_(ctx, idx))
void * a_buf_at_(a_buf const *ctx, size_t idx)
access specified element for a pointer to buffer structure
Definition buf.h:60

◆ A_BUF_END

#define A_BUF_END ( T,
ctx )
Value:
a_cast_s(T *, a_buf_end(ctx))
void * a_buf_end(a_buf const *ctx)
access end pointer for a pointer to buffer structure
Definition buf.h:122

◆ a_buf_foreach

#define a_buf_foreach ( T,
P,
it,
ctx )
Value:
a_foreach(T, P, it, (ctx)->ptr_, (ctx)->num_)
#define a_foreach(T, P, it, ptr, num)
iterate over an array
Definition a.h:934

iterate over a buffer

a_buf_foreach(T, *, it, ctx)
{
assert(a_buf_siz(ctx) == sizeof(*it));
}
size_t a_buf_siz(a_buf const *ctx)
access size of a element for a pointer to buffer structure
Definition buf.h:39
#define a_buf_foreach(T, P, it, ctx)
iterate over a buffer
Definition buf.h:369
Parameters
Tthe prefix of the element type
Pthe suffix of the element type
itthe &a_buf to use as a loop counter
ctxpoints to an instance of buffer structure

◆ a_buf_foreach_reverse

#define a_buf_foreach_reverse ( T,
P,
it,
ctx )
Value:
a_foreach_reverse(T, P, it, (ctx)->ptr_, (ctx)->num_)
#define a_foreach_reverse(T, P, it, ptr, num)
iterate over an array in reverse
Definition a.h:948

iterate over a buffer in reverse

a_buf_foreach_reverse(T, *, it, ctx)
{
assert(a_buf_siz(ctx) == sizeof(*it));
}
#define a_buf_foreach_reverse(T, P, it, ctx)
iterate over a buffer in reverse
Definition buf.h:384
Parameters
Tthe prefix of the element type
Pthe suffix of the element type
itthe &a_buf to use as a loop counter
ctxpoints to an instance of buffer structure

◆ a_buf_forenum

#define a_buf_forenum ( i,
ctx )
Value:
a_forenum(a_size, i, (ctx)->num_)
#define a_size
Definition a.h:610
#define a_forenum(I, i, n)
iterate from 0 to n and not include n
Definition a.h:916

iterate over a buffer

{
T *it = (T *)a_buf_at(ctx, i);
assert(a_buf_siz(ctx) == sizeof(*it));
}
#define a_buf_forenum(i, ctx)
iterate over a buffer
Definition buf.h:340
Parameters
iindex of elements in the buffer
ctxpoints to an instance of buffer structure

◆ a_buf_forenum_reverse

#define a_buf_forenum_reverse ( i,
ctx )
Value:
a_forenum_reverse(a_size, i, (ctx)->num_)
#define a_forenum_reverse(I, i, n)
iterate from n to 0 and not include n
Definition a.h:924

iterate over a buffer in reverse

{
T *it = (T *)a_buf_at(ctx, i);
assert(a_buf_siz(ctx) == sizeof(*it));
}
#define a_buf_forenum_reverse(i, ctx)
iterate over a buffer in reverse
Definition buf.h:354
Parameters
iindex of elements in the buffer
ctxpoints to an instance of buffer structure

◆ A_BUF_IDX

#define A_BUF_IDX ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_buf_idx(ctx, idx))
void * a_buf_idx(a_buf const *ctx, ptrdiff_t idx)
access specified element for a pointer to buffer structure
Definition buf.h:86

◆ A_BUF_INSERT

#define A_BUF_INSERT ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_buf_insert(ctx, idx))
void * a_buf_insert(a_buf *ctx, size_t idx)
insert an element into the buffer

◆ A_BUF_PTR

#define A_BUF_PTR ( T,
ctx )
Value:
a_cast_s(T *, a_buf_ptr(ctx))
void * a_buf_ptr(a_buf const *ctx)
access address of buffer for a pointer to buffer structure
Definition buf.h:32

◆ A_BUF_PULL

#define A_BUF_PULL ( T,
ctx )
Value:
a_cast_s(T *, a_buf_pull(ctx))
void * a_buf_pull(a_buf *ctx)
pull an element from the buffer
Definition buf.h:325

◆ A_BUF_PULL_BACK

#define A_BUF_PULL_BACK ( T,
ctx )
Value:
a_cast_s(T *, a_buf_pull_back(ctx))
void * a_buf_pull_back(a_buf *ctx)
pull an element from the buffer backward

◆ A_BUF_PULL_FORE

#define A_BUF_PULL_FORE ( T,
ctx )
Value:
a_cast_s(T *, a_buf_pull_fore(ctx))
void * a_buf_pull_fore(a_buf *ctx)
pull an element from the buffer forward

◆ A_BUF_PUSH

#define A_BUF_PUSH ( T,
ctx )
Value:
a_cast_s(T *, a_buf_push(ctx))
void * a_buf_push(a_buf *ctx)
push an element into the buffer
Definition buf.h:316

◆ A_BUF_PUSH_BACK

#define A_BUF_PUSH_BACK ( T,
ctx )
Value:
a_cast_s(T *, a_buf_push_back(ctx))
void * a_buf_push_back(a_buf *ctx)
push an element into the buffer backward

◆ A_BUF_PUSH_FORE

#define A_BUF_PUSH_FORE ( T,
ctx )
Value:
a_cast_s(T *, a_buf_push_fore(ctx))
void * a_buf_push_fore(a_buf *ctx)
push an element into the buffer forward

◆ A_BUF_PUSH_SORT

#define A_BUF_PUSH_SORT ( T,
ctx,
key,
cmp )
Value:
a_cast_s(T *, a_buf_push_sort(ctx, key, cmp))
void * a_buf_push_sort(a_buf *ctx, void const *key, int(*cmp)(void const *, void const *))
push an element into the buffer and sort it

◆ A_BUF_REMOVE

#define A_BUF_REMOVE ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_buf_remove(ctx, idx))
void * a_buf_remove(a_buf *ctx, size_t idx)
remove an element from the buffer

◆ A_BUF_SEARCH

#define A_BUF_SEARCH ( T,
ctx,
obj,
cmp )
Value:
a_cast_s(T *, a_buf_search(ctx, obj, cmp))
void * a_buf_search(a_buf const *ctx, void const *obj, int(*cmp)(void const *, void const *))
search the given element in this buffer

◆ A_BUF_TOP

#define A_BUF_TOP ( T,
ctx )
Value:
a_cast_s(T *, a_buf_top(ctx))
void * a_buf_top(a_buf const *ctx)
access top element for a pointer to buffer structure
Definition buf.h:111

◆ A_BUF_TOP_

#define A_BUF_TOP_ ( T,
ctx )
Value:
a_cast_s(T *, a_buf_top_(ctx))
void * a_buf_top_(a_buf const *ctx)
access top element for a pointer to buffer structure
Definition buf.h:99

Function Documentation

◆ a_buf_at()

void * a_buf_at ( a_buf const * ctx,
size_t idx )

access specified element for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure
[in]idxindex of element less than memory
Returns
specified element pointer
Return values
0out of bounds

◆ a_buf_at_()

void * a_buf_at_ ( a_buf const * ctx,
size_t idx )

access specified element for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure
[in]idxindex of element less than memory
Note
should check for out of bounds
Returns
specified element pointer

◆ a_buf_ctor()

void a_buf_ctor ( a_buf * ctx,
void * ptr,
size_t siz,
size_t num )

constructor for buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure
[in]ptraddress of memory
[in]sizsize of a element
[in]numnumber of element

◆ a_buf_drop()

void a_buf_drop ( a_buf * ctx,
void(* dtor )(void *) )

drop all the elements for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure
[in]dtorcurrent element destructor

◆ a_buf_dtor()

void a_buf_dtor ( a_buf * ctx,
void(* dtor )(void *) )

destructor for buffer structure

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

◆ a_buf_end()

void * a_buf_end ( a_buf const * ctx)

access end pointer for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure
Returns
buffer end pointer

◆ a_buf_idx()

void * a_buf_idx ( a_buf const * ctx,
ptrdiff_t idx )

access specified element for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure
[in]idxindex of element -memory < idx < memory
Returns
specified element pointer
Return values
0out of bounds

◆ a_buf_insert()

void * a_buf_insert ( a_buf * ctx,
size_t idx )

insert an element into the buffer

Parameters
[in]ctxpoints to an instance of buffer structure
[in]idxindex of element in this buffer
  • 0 a_buf_push_fore
  • n a_buf_push_back
Returns
element pointer
Return values
0failure

◆ a_buf_mem()

size_t a_buf_mem ( a_buf const * ctx)

access memory of element for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure

◆ a_buf_move()

void a_buf_move ( a_buf * ctx,
a_buf * obj )

initialize a pointer to buffer structure by moving

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

◆ a_buf_num()

size_t a_buf_num ( a_buf const * ctx)

access number of element for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure

◆ a_buf_ptr()

void * a_buf_ptr ( a_buf const * ctx)

access address of buffer for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure

◆ a_buf_pull()

void * a_buf_pull ( a_buf * ctx)

pull an element from the buffer

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

◆ a_buf_pull_back()

void * a_buf_pull_back ( a_buf * ctx)

pull an element from the buffer backward

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

◆ a_buf_pull_fore()

void * a_buf_pull_fore ( a_buf * ctx)

pull an element from the buffer forward

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

◆ a_buf_push()

void * a_buf_push ( a_buf * ctx)

push an element into the buffer

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

◆ a_buf_push_back()

void * a_buf_push_back ( a_buf * ctx)

push an element into the buffer backward

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

◆ a_buf_push_fore()

void * a_buf_push_fore ( a_buf * ctx)

push an element into the buffer forward

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

◆ a_buf_push_sort()

void * a_buf_push_sort ( a_buf * ctx,
void const * key,
int(* cmp )(void const *, void const *) )

push an element into the buffer and sort it

Parameters
[in]ctxpoints to an instance of buffer 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_buf_remove()

void * a_buf_remove ( a_buf * ctx,
size_t idx )

remove an element from the buffer

Parameters
[in]ctxpoints to an instance of buffer structure
[in]idxindex of element in this buffer
  • 0 a_buf_pull_fore
  • n a_buf_pull_back
Returns
element pointer
Return values
0failure

◆ a_buf_search()

void * a_buf_search ( a_buf const * ctx,
void const * obj,
int(* cmp )(void const *, void const *) )

search the given element in this buffer

Parameters
[in]ctxpoints to an instance of buffer structure
[in]objobject that serves as key for the search
[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
matching element pointer
Return values
0failure

◆ a_buf_siz()

size_t a_buf_siz ( a_buf const * ctx)

access size of a element for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure

◆ a_buf_sort()

void a_buf_sort ( a_buf const * ctx,
int(* cmp )(void const *, void const *) )

sort all elements for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer 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_buf_sort_back()

void a_buf_sort_back ( a_buf const * ctx,
int(* cmp )(void const *, void const *) )

insert sort backmost element for a pointer to buffer structure

T *obj = A_BUF_PUSH_BACK(T, ctx);
if (obj)
{
CTOR(obj);
INIT(obj);
a_buf_sort_back(ctx, cmp);
}
void a_buf_sort_back(a_buf const *ctx, int(*cmp)(void const *, void const *))
insert sort backmost element for a pointer to buffer structure
Parameters
[in]ctxpoints to an instance of buffer 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_buf_sort_fore()

void a_buf_sort_fore ( a_buf const * ctx,
int(* cmp )(void const *, void const *) )

insert sort foremost element for a pointer to buffer structure

T *obj = A_BUF_PUSH_FORE(T, ctx);
if (obj)
{
CTOR(obj);
INIT(obj);
a_buf_sort_fore(ctx, cmp);
}
void a_buf_sort_fore(a_buf const *ctx, int(*cmp)(void const *, void const *))
insert sort foremost element for a pointer to buffer structure
Parameters
[in]ctxpoints to an instance of buffer 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_buf_swap()

void a_buf_swap ( a_buf const * ctx,
size_t lhs,
size_t rhs )

swap elements lhs and rhs for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure
[in]lhselement index on the left
[in]rhselement index on the right

◆ a_buf_top()

void * a_buf_top ( a_buf const * ctx)

access top element for a pointer to buffer structure

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

◆ a_buf_top_()

void * a_buf_top_ ( a_buf const * ctx)

access top element for a pointer to buffer structure

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