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
basic buffer library
Collaboration diagram for basic buffer library:

Data Structures

struct  a_buf
 instance structure for basic buffer More...
 

Macros

#define A_BUF_DEF   a_size num_, mem_, siz_
 
#define a_buf_(_, x)
 cast a buffer pointer from another type pointer
 
#define A_BUF_PTR(T, ctx)
 
#define A_BUF_AT_(T, ctx, idx)
 
#define A_BUF_AT(T, ctx, idx)
 
#define A_BUF_OF(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(I, i, ctx)
 
#define a_buf_forenum_reverse(i, ctx)
 iterate over a buffer in reverse
 
#define A_BUF_FORENUM_REVERSE(I, i, ctx)
 
#define a_buf_foreach(T, S, it, ctx)
 iterate over a buffer
 
#define A_BUF_FOREACH(T, it, at, ctx)
 
#define a_buf_foreach_reverse(T, S, it, ctx)
 iterate over a buffer in reverse
 
#define A_BUF_FOREACH_REVERSE(T, it, at, ctx)
 

Typedefs

typedef struct a_buf a_buf
 instance structure for basic buffer
 

Functions

a_size a_buf_num (void const *ctx)
 access number of element for a pointer to buffer structure
 
a_size a_buf_mem (void const *ctx)
 access memory of element for a pointer to buffer structure
 
a_size a_buf_siz (void const *ctx)
 access size of a element for a pointer to buffer structure
 
void * a_buf_ptr (void const *ctx)
 access address of buffer for a pointer to buffer structure
 
void * a_buf_at_ (void const *ctx, a_size idx)
 access specified element for a pointer to buffer structure
 
void * a_buf_at (void const *ctx, a_size idx)
 access specified element for a pointer to buffer structure
 
void * a_buf_of (void const *ctx, a_diff idx)
 access specified element for a pointer to buffer structure
 
void * a_buf_top_ (void const *ctx)
 access top element for a pointer to buffer structure
 
void * a_buf_top (void const *ctx)
 access top element for a pointer to buffer structure
 
void * a_buf_end (void const *ctx)
 access end pointer for a pointer to buffer structure
 
a_bufa_buf_new (a_size siz, a_size num)
 allocate a pointer to buffer structure from memory
 
void a_buf_die (a_buf *ctx, void(*dtor)(void *))
 deallocate a pointer to buffer structure
 
void a_buf_ctor (void *ctx, a_size siz, a_size num)
 constructor for buffer structure
 
void a_buf_dtor (void *ctx, void(*dtor)(void *))
 destructor for buffer structure
 
a_bufa_buf_setm (a_buf *ctx, a_size mem)
 set memory of element for a pointer to buffer structure
 
void a_buf_setn (void *ctx, a_size num, void(*dtor)(void *))
 set number of element for a pointer to buffer structure
 
void a_buf_setz (void *ctx, a_size siz, void(*dtor)(void *))
 set size of a element for a pointer to buffer structure
 
void a_buf_sort (void const *ctx, int(*cmp)(void const *, void const *))
 sort all elements for a pointer to buffer structure
 
void a_buf_sort_fore (void const *ctx, int(*cmp)(void const *, void const *))
 insert sort foremost element for a pointer to buffer structure
 
void a_buf_sort_back (void const *ctx, int(*cmp)(void const *, void const *))
 insert sort backmost element for a pointer to buffer structure
 
void * a_buf_push_sort (void *ctx, void const *key, int(*cmp)(void const *, void const *))
 push an element into the buffer and sort it
 
void * a_buf_search (void const *ctx, void const *obj, int(*cmp)(void const *, void const *))
 search the given element in this buffer
 
void * a_buf_insert (void *ctx, a_size idx)
 insert an element into the buffer
 
void * a_buf_remove (void *ctx, a_size idx)
 remove an element from the buffer
 
void * a_buf_push_fore (void *ctx)
 push an element into the buffer forward
 
void * a_buf_push_back (void *ctx)
 push an element into the buffer backward
 
void * a_buf_pull_fore (void *ctx)
 pull an element from the buffer forward
 
void * a_buf_pull_back (void *ctx)
 pull an element from the buffer backward
 
int a_buf_store (void *ctx, a_size idx, void *ptr, a_size num, int(*copy)(void *, void const *))
 store elements into the buffer
 
int a_buf_erase (void *ctx, a_size idx, a_size num, void(*dtor)(void *))
 erase elements from the buffer
 
void * a_buf_push (void *ctx)
 push an element into the buffer
 
void * a_buf_pull (void *ctx)
 pull an element from the buffer
 

Detailed Description

Macro Definition Documentation

◆ a_buf_

#define a_buf_ ( _,
x )
Value:
a_cast_s(a_buf _, a_cast_s(void _, x))
instance structure for basic buffer
Definition buf.h:22

cast a buffer pointer from another type pointer

Parameters
[in]_additional attributes of specified type
[in]xpoints to basic buffer
Returns
a pointer to basic buffer

◆ A_BUF_AT

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

◆ A_BUF_AT_

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

◆ A_BUF_END

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

◆ A_BUF_FOREACH

#define A_BUF_FOREACH ( T,
it,
at,
ctx )
Value:
A_FOREACH(T, it, at, a_buf_ptr(ctx), a_buf_num(ctx))
a_size a_buf_num(void const *ctx)
access number of element for a pointer to buffer structure
Definition buf.h:38
void * a_buf_ptr(void const *ctx)
access address of buffer for a pointer to buffer structure
Definition buf.h:56

◆ a_buf_foreach

#define a_buf_foreach ( T,
S,
it,
ctx )
Value:
a_foreach(T, S, it, a_buf_ptr(ctx), a_buf_num(ctx))
#define a_foreach(T, S, it, ptr, num)
iterate over an array
Definition a.h:1157

iterate over a buffer

a_buf_foreach(T, *, it, ctx)
{
assert(a_buf_siz(ctx) == sizeof(*it));
}
a_size a_buf_siz(void const *ctx)
access size of a element for a pointer to buffer structure
Definition buf.h:50
#define a_buf_foreach(T, S, it, ctx)
iterate over a buffer
Definition buf.h:421
Parameters
Tthe prefix of the element type
Sthe 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,
it,
at,
ctx )
Value:
A_FOREACH_REVERSE(T, it, at, a_buf_ptr(ctx), a_buf_num(ctx))

◆ a_buf_foreach_reverse

#define a_buf_foreach_reverse ( T,
S,
it,
ctx )
Value:
a_foreach_reverse(T, S, it, a_buf_ptr(ctx), a_buf_num(ctx))
#define a_foreach_reverse(T, S, it, ptr, num)
iterate over an array in reverse
Definition a.h:1175

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, S, it, ctx)
iterate over a buffer in reverse
Definition buf.h:437
Parameters
Tthe prefix of the element type
Sthe 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,
i,
ctx )
Value:
A_FORENUM(I, i, a_buf_num(ctx))

◆ a_buf_forenum

#define a_buf_forenum ( i,
ctx )
Value:
#define a_forenum(I, i, n)
iterate from 0 to n and not include n
Definition a.h:1137
size_t a_size
unsigned integer type returned by the sizeof operator
Definition a.h:823

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:390
Parameters
iindex of elements in the buffer
ctxpoints to an instance of buffer structure

◆ A_BUF_FORENUM_REVERSE

#define A_BUF_FORENUM_REVERSE ( I,
i,
ctx )
Value:
A_FORENUM_REVERSE(I, i, a_buf_num(ctx))

◆ a_buf_forenum_reverse

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

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:405
Parameters
iindex of elements in the buffer
ctxpoints to an instance of buffer structure

◆ A_BUF_INSERT

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

◆ A_BUF_OF

#define A_BUF_OF ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_buf_of(ctx, idx))
void * a_buf_of(void const *ctx, a_diff idx)
access specified element for a pointer to buffer structure
Definition buf.h:95

◆ A_BUF_PTR

#define A_BUF_PTR ( T,
ctx )
Value:
a_cast_s(T *, a_buf_ptr(ctx))

◆ A_BUF_PULL

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

◆ 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(void *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(void *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(void *ctx)
push an element into the buffer
Definition buf.h:366

◆ 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(void *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(void *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(void *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(void *ctx, a_size 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(void 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(void const *ctx)
access top element for a pointer to buffer structure
Definition buf.h:120

◆ A_BUF_TOP_

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

Function Documentation

◆ a_buf_at()

void * a_buf_at ( void const * ctx,
a_size 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_ ( void const * ctx,
a_size 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 ( void * ctx,
a_size siz,
a_size num )

constructor for buffer structure

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

◆ a_buf_die()

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

deallocate a pointer to buffer structure

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

◆ a_buf_dtor()

void a_buf_dtor ( void * 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 ( void 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_erase()

int a_buf_erase ( void * ctx,
a_size idx,
a_size num,
void(* dtor )(void *) )

erase elements from the buffer

Parameters
[in]ctxpoints to an instance of buffer structure
[in]idxindex of element in this buffer
[in]numnumber of elements to erase
[in]dtora function that erases elements
  • 0 not erase these elements
Returns
error code value
Return values
0success

◆ a_buf_insert()

void * a_buf_insert ( void * ctx,
a_size 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()

a_size a_buf_mem ( void const * ctx)

access memory of element for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure

◆ a_buf_new()

a_buf * a_buf_new ( a_size siz,
a_size num )

allocate a pointer to buffer structure from memory

Parameters
[in]sizsize of a element
[in]numnumber of element

◆ a_buf_num()

a_size a_buf_num ( void const * ctx)

access number of element for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure

◆ a_buf_of()

void * a_buf_of ( void const * ctx,
a_diff 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_ptr()

void * a_buf_ptr ( void 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 ( void * 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 ( void * 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 ( void * 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 ( void * 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 ( void * 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 ( void * 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 ( void * 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 ( void * ctx,
a_size 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 ( void 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_setm()

a_buf * a_buf_setm ( a_buf * ctx,
a_size mem )

set memory of element for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of string structure
[in]memnew memory of current element
Returns
error code value
Return values
0success

◆ a_buf_setn()

void a_buf_setn ( void * ctx,
a_size num,
void(* dtor )(void *) )

set number of element for a pointer to buffer structure

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

◆ a_buf_setz()

void a_buf_setz ( void * ctx,
a_size siz,
void(* dtor )(void *) )

set size of a element for a pointer to buffer structure

Parameters
[in]ctxpoints to an instance of buffer structure
[in]sizthe size of the new element
[in]dtorprevious element destructor

◆ a_buf_siz()

a_size a_buf_siz ( void 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 ( void 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 ( void 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(void 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 ( void 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(void 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_store()

int a_buf_store ( void * ctx,
a_size idx,
void * ptr,
a_size num,
int(* copy )(void *, void const *) )

store elements into the buffer

Parameters
[in]ctxpoints to an instance of buffer structure
[in]idxindex of element in this buffer
[in]ptrpoints to array elements
[in]numnumber of array elements
[in]copya function that copies elements
  • 0 use function a_copy to copy elements
Returns
error code value
Return values
0success

◆ a_buf_top()

void * a_buf_top ( void 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_ ( void 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