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

Data Structures

struct  a_vec
 instance structure for basic vector More...
 

Macros

#define A_VEC_PTR(T, ctx)
 
#define A_VEC_AT_(T, ctx, idx)
 
#define A_VEC_AT(T, ctx, idx)
 
#define A_VEC_IDX(T, ctx, idx)
 
#define A_VEC_TOP_(T, ctx)
 
#define A_VEC_TOP(T, ctx)
 
#define A_VEC_END_(T, ctx)
 
#define A_VEC_END(T, ctx)
 
#define A_VEC_PUSH_SORT(T, ctx, key, cmp)
 
#define A_VEC_SEARCH(T, ctx, obj, cmp)
 
#define A_VEC_INSERT(T, ctx, idx)
 
#define A_VEC_REMOVE(T, ctx, idx)
 
#define A_VEC_PUSH_FORE(T, ctx)
 
#define A_VEC_PUSH_BACK(T, ctx)
 
#define A_VEC_PULL_FORE(T, ctx)
 
#define A_VEC_PULL_BACK(T, ctx)
 
#define A_VEC_PUSH(T, ctx)
 
#define A_VEC_PULL(T, ctx)
 
#define a_vec_forenum(i, ctx)
 iterate over a vector
 
#define a_vec_forenum_reverse(i, ctx)
 iterate over a vector in reverse
 
#define a_vec_foreach(T, P, it, ctx)
 iterate over a vector
 
#define a_vec_foreach_reverse(T, P, it, ctx)
 iterate over a vector in reverse
 

Typedefs

typedef struct a_vec a_vec
 instance structure for basic vector
 

Functions

void * a_vec_ptr (a_vec const *ctx)
 access address of vector for a pointer to vector structure
 
size_t a_vec_siz (a_vec const *ctx)
 access size of a element for a pointer to vector structure
 
size_t a_vec_num (a_vec const *ctx)
 access number of element for a pointer to vector structure
 
size_t a_vec_mem (a_vec const *ctx)
 access memory of element for a pointer to vector structure
 
void * a_vec_at_ (a_vec const *ctx, size_t idx)
 access specified element for a pointer to vector structure
 
void * a_vec_at (a_vec const *ctx, size_t idx)
 access specified element for a pointer to vector structure
 
void * a_vec_idx (a_vec const *ctx, ptrdiff_t idx)
 access specified element for a pointer to vector structure
 
void * a_vec_top_ (a_vec const *ctx)
 access top element for a pointer to vector structure
 
void * a_vec_top (a_vec const *ctx)
 access top element for a pointer to vector structure
 
void * a_vec_end_ (a_vec const *ctx)
 access end pointer for a pointer to vector structure
 
void * a_vec_end (a_vec const *ctx)
 access end pointer for a pointer to vector structure
 
a_veca_vec_new (size_t size)
 allocate a pointer to vector structure from memory
 
void a_vec_die (a_vec *ctx, void(*dtor)(void *))
 deallocate a pointer to vector structure
 
void a_vec_ctor (a_vec *ctx, size_t size)
 constructor for vector structure
 
void a_vec_dtor (a_vec *ctx, void(*dtor)(void *))
 destructor for vector structure
 
int a_vec_copy (a_vec *ctx, a_vec const *obj, int(*dup)(void *, void const *))
 initialize a pointer to vector structure by copying
 
void a_vec_move (a_vec *ctx, a_vec *obj)
 initialize a pointer to vector structure by moving
 
void a_vec_edit (a_vec *ctx, size_t size, void(*dtor)(void *))
 edit size of a element for a pointer to vector structure
 
int a_vec_make (a_vec *ctx, size_t num, void(*dtor)(void *))
 modify element number for a pointer to string structure
 
void a_vec_drop (a_vec *ctx, void(*dtor)(void *))
 drop all the elements for a pointer to vector structure
 
void a_vec_swap (a_vec const *ctx, size_t lhs, size_t rhs)
 swap elements lhs and rhs for a pointer to vector structure
 
void a_vec_sort (a_vec const *ctx, int(*cmp)(void const *, void const *))
 sort all elements for a pointer to vector structure
 
void a_vec_sort_fore (a_vec const *ctx, int(*cmp)(void const *, void const *))
 insert sort foremost element for a pointer to vector structure
 
void a_vec_sort_back (a_vec const *ctx, int(*cmp)(void const *, void const *))
 insert sort backmost element for a pointer to vector structure
 
void * a_vec_push_sort (a_vec *ctx, void const *key, int(*cmp)(void const *, void const *))
 push an element into the vector and sort it
 
void * a_vec_search (a_vec const *ctx, void const *obj, int(*cmp)(void const *, void const *))
 search the given element in this vector
 
void * a_vec_insert (a_vec *ctx, size_t idx)
 insert an element into the vector
 
void * a_vec_remove (a_vec *ctx, size_t idx)
 remove an element from the vector
 
void * a_vec_push_fore (a_vec *ctx)
 push an element into the vector forward
 
void * a_vec_push_back (a_vec *ctx)
 push an element into the vector backward
 
void * a_vec_pull_fore (a_vec *ctx)
 pull an element from the vector forward
 
void * a_vec_pull_back (a_vec *ctx)
 pull an element from the vector backward
 
void * a_vec_push (a_vec *ctx)
 push an element into the vector
 
void * a_vec_pull (a_vec *ctx)
 pull an element from the vector
 

Detailed Description

Macro Definition Documentation

◆ A_VEC_AT

#define A_VEC_AT ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_vec_at(ctx, idx))
void * a_vec_at(a_vec const *ctx, size_t idx)
access specified element for a pointer to vector structure
Definition vec.h:73

◆ A_VEC_AT_

#define A_VEC_AT_ ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_vec_at_(ctx, idx))
void * a_vec_at_(a_vec const *ctx, size_t idx)
access specified element for a pointer to vector structure
Definition vec.h:60

◆ A_VEC_END

#define A_VEC_END ( T,
ctx )
Value:
a_cast_s(T *, a_vec_end(ctx))
void * a_vec_end(a_vec const *ctx)
access end pointer for a pointer to vector structure
Definition vec.h:134

◆ A_VEC_END_

#define A_VEC_END_ ( T,
ctx )
Value:
a_cast_s(T *, a_vec_end_(ctx))
void * a_vec_end_(a_vec const *ctx)
access end pointer for a pointer to vector structure
Definition vec.h:122

◆ a_vec_foreach

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

iterate over a vector

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

◆ a_vec_foreach_reverse

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

iterate over a vector in reverse

a_vec_foreach_reverse(T, *, it, ctx)
{
assert(a_vec_siz(ctx) == sizeof(*it));
}
#define a_vec_foreach_reverse(T, P, it, ctx)
iterate over a vector in reverse
Definition vec.h:438
Parameters
Tthe prefix of the element type
Pthe suffix of the element type
itthe &a_vec to use as a loop counter
ctxpoints to an instance of vector structure

◆ a_vec_forenum

#define a_vec_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 vector

{
T *it = (T *)a_vec_at(ctx, i);
assert(a_vec_siz(ctx) == sizeof(*it));
}
#define a_vec_forenum(i, ctx)
iterate over a vector
Definition vec.h:394
Parameters
iindex of elements in the vector
ctxpoints to an instance of vector structure

◆ a_vec_forenum_reverse

#define a_vec_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 vector in reverse

{
T *it = (T *)a_vec_at(ctx, i);
assert(a_vec_siz(ctx) == sizeof(*it));
}
#define a_vec_forenum_reverse(i, ctx)
iterate over a vector in reverse
Definition vec.h:408
Parameters
iindex of elements in the vector
ctxpoints to an instance of vector structure

◆ A_VEC_IDX

#define A_VEC_IDX ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_vec_idx(ctx, idx))
void * a_vec_idx(a_vec const *ctx, ptrdiff_t idx)
access specified element for a pointer to vector structure
Definition vec.h:86

◆ A_VEC_INSERT

#define A_VEC_INSERT ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_vec_insert(ctx, idx))
void * a_vec_insert(a_vec *ctx, size_t idx)
insert an element into the vector

◆ A_VEC_PTR

#define A_VEC_PTR ( T,
ctx )
Value:
a_cast_s(T *, a_vec_ptr(ctx))
void * a_vec_ptr(a_vec const *ctx)
access address of vector for a pointer to vector structure
Definition vec.h:32

◆ A_VEC_PULL

#define A_VEC_PULL ( T,
ctx )
Value:
a_cast_s(T *, a_vec_pull(ctx))
void * a_vec_pull(a_vec *ctx)
pull an element from the vector
Definition vec.h:379

◆ A_VEC_PULL_BACK

#define A_VEC_PULL_BACK ( T,
ctx )
Value:
a_cast_s(T *, a_vec_pull_back(ctx))
void * a_vec_pull_back(a_vec *ctx)
pull an element from the vector backward

◆ A_VEC_PULL_FORE

#define A_VEC_PULL_FORE ( T,
ctx )
Value:
a_cast_s(T *, a_vec_pull_fore(ctx))
void * a_vec_pull_fore(a_vec *ctx)
pull an element from the vector forward

◆ A_VEC_PUSH

#define A_VEC_PUSH ( T,
ctx )
Value:
a_cast_s(T *, a_vec_push(ctx))
void * a_vec_push(a_vec *ctx)
push an element into the vector
Definition vec.h:370

◆ A_VEC_PUSH_BACK

#define A_VEC_PUSH_BACK ( T,
ctx )
Value:
a_cast_s(T *, a_vec_push_back(ctx))
void * a_vec_push_back(a_vec *ctx)
push an element into the vector backward

◆ A_VEC_PUSH_FORE

#define A_VEC_PUSH_FORE ( T,
ctx )
Value:
a_cast_s(T *, a_vec_push_fore(ctx))
void * a_vec_push_fore(a_vec *ctx)
push an element into the vector forward

◆ A_VEC_PUSH_SORT

#define A_VEC_PUSH_SORT ( T,
ctx,
key,
cmp )
Value:
a_cast_s(T *, a_vec_push_sort(ctx, key, cmp))
void * a_vec_push_sort(a_vec *ctx, void const *key, int(*cmp)(void const *, void const *))
push an element into the vector and sort it

◆ A_VEC_REMOVE

#define A_VEC_REMOVE ( T,
ctx,
idx )
Value:
a_cast_s(T *, a_vec_remove(ctx, idx))
void * a_vec_remove(a_vec *ctx, size_t idx)
remove an element from the vector

◆ A_VEC_SEARCH

#define A_VEC_SEARCH ( T,
ctx,
obj,
cmp )
Value:
a_cast_s(T *, a_vec_search(ctx, obj, cmp))
void * a_vec_search(a_vec const *ctx, void const *obj, int(*cmp)(void const *, void const *))
search the given element in this vector

◆ A_VEC_TOP

#define A_VEC_TOP ( T,
ctx )
Value:
a_cast_s(T *, a_vec_top(ctx))
void * a_vec_top(a_vec const *ctx)
access top element for a pointer to vector structure
Definition vec.h:111

◆ A_VEC_TOP_

#define A_VEC_TOP_ ( T,
ctx )
Value:
a_cast_s(T *, a_vec_top_(ctx))
void * a_vec_top_(a_vec const *ctx)
access top element for a pointer to vector structure
Definition vec.h:99

Function Documentation

◆ a_vec_at()

void * a_vec_at ( a_vec const * ctx,
size_t idx )

access specified element for a pointer to vector structure

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

◆ a_vec_at_()

void * a_vec_at_ ( a_vec const * ctx,
size_t idx )

access specified element for a pointer to vector structure

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

◆ a_vec_copy()

int a_vec_copy ( a_vec * ctx,
a_vec const * obj,
int(* dup )(void *, void const *) )

initialize a pointer to vector structure by copying

Parameters
[in]ctxpoints to an instance of vector structure
[in]objinput source pointing to an instance
[in]dupa function that copies elements
  • 0 use function a_copy to copy elements
Returns
the execution state of the function
Return values
0success
1failure

◆ a_vec_ctor()

void a_vec_ctor ( a_vec * ctx,
size_t size )

constructor for vector structure

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

◆ a_vec_die()

void a_vec_die ( a_vec * ctx,
void(* dtor )(void *) )

deallocate a pointer to vector structure

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

◆ a_vec_drop()

void a_vec_drop ( a_vec * ctx,
void(* dtor )(void *) )

drop all the elements for a pointer to vector structure

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

◆ a_vec_dtor()

void a_vec_dtor ( a_vec * ctx,
void(* dtor )(void *) )

destructor for vector structure

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

◆ a_vec_edit()

void a_vec_edit ( a_vec * ctx,
size_t size,
void(* dtor )(void *) )

edit size of a element for a pointer to vector structure

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

◆ a_vec_end()

void * a_vec_end ( a_vec const * ctx)

access end pointer for a pointer to vector structure

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

◆ a_vec_end_()

void * a_vec_end_ ( a_vec const * ctx)

access end pointer for a pointer to vector structure

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

◆ a_vec_idx()

void * a_vec_idx ( a_vec const * ctx,
ptrdiff_t idx )

access specified element for a pointer to vector structure

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

◆ a_vec_insert()

void * a_vec_insert ( a_vec * ctx,
size_t idx )

insert an element into the vector

Parameters
[in]ctxpoints to an instance of vector structure
[in]idxindex of element in this vector
  • 0 a_vec_push_fore
  • n a_vec_push_back
Returns
element pointer
Return values
0failure

◆ a_vec_make()

int a_vec_make ( a_vec * ctx,
size_t num,
void(* dtor )(void *) )

modify element number for a pointer to string structure

Parameters
[in]ctxpoints to an instance of string structure
[in]numnumber of all elements in the vector
[in]dtorprevious element destructor
Returns
the execution state of the function
Return values
0success
1failure

◆ a_vec_mem()

size_t a_vec_mem ( a_vec const * ctx)

access memory of element for a pointer to vector structure

Parameters
[in]ctxpoints to an instance of vector structure

◆ a_vec_move()

void a_vec_move ( a_vec * ctx,
a_vec * obj )

initialize a pointer to vector structure by moving

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

◆ a_vec_new()

a_vec * a_vec_new ( size_t size)

allocate a pointer to vector structure from memory

Parameters
[in]sizesize of element

◆ a_vec_num()

size_t a_vec_num ( a_vec const * ctx)

access number of element for a pointer to vector structure

Parameters
[in]ctxpoints to an instance of vector structure

◆ a_vec_ptr()

void * a_vec_ptr ( a_vec const * ctx)

access address of vector for a pointer to vector structure

Parameters
[in]ctxpoints to an instance of vector structure

◆ a_vec_pull()

void * a_vec_pull ( a_vec * ctx)

pull an element from the vector

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

◆ a_vec_pull_back()

void * a_vec_pull_back ( a_vec * ctx)

pull an element from the vector backward

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

◆ a_vec_pull_fore()

void * a_vec_pull_fore ( a_vec * ctx)

pull an element from the vector forward

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

◆ a_vec_push()

void * a_vec_push ( a_vec * ctx)

push an element into the vector

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

◆ a_vec_push_back()

void * a_vec_push_back ( a_vec * ctx)

push an element into the vector backward

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

◆ a_vec_push_fore()

void * a_vec_push_fore ( a_vec * ctx)

push an element into the vector forward

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

◆ a_vec_push_sort()

void * a_vec_push_sort ( a_vec * ctx,
void const * key,
int(* cmp )(void const *, void const *) )

push an element into the vector and sort it

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

void * a_vec_remove ( a_vec * ctx,
size_t idx )

remove an element from the vector

Parameters
[in]ctxpoints to an instance of vector structure
[in]idxindex of element in this vector
  • 0 a_vec_pull_fore
  • n a_vec_pull_back
Returns
element pointer
Return values
0failure

◆ a_vec_search()

void * a_vec_search ( a_vec const * ctx,
void const * obj,
int(* cmp )(void const *, void const *) )

search the given element in this vector

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

size_t a_vec_siz ( a_vec const * ctx)

access size of a element for a pointer to vector structure

Parameters
[in]ctxpoints to an instance of vector structure

◆ a_vec_sort()

void a_vec_sort ( a_vec const * ctx,
int(* cmp )(void const *, void const *) )

sort all elements for a pointer to vector structure

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

void a_vec_sort_back ( a_vec const * ctx,
int(* cmp )(void const *, void const *) )

insert sort backmost element for a pointer to vector structure

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

void a_vec_sort_fore ( a_vec const * ctx,
int(* cmp )(void const *, void const *) )

insert sort foremost element for a pointer to vector structure

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

void a_vec_swap ( a_vec const * ctx,
size_t lhs,
size_t rhs )

swap elements lhs and rhs for a pointer to vector structure

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

◆ a_vec_top()

void * a_vec_top ( a_vec const * ctx)

access top element for a pointer to vector structure

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

◆ a_vec_top_()

void * a_vec_top_ ( a_vec const * ctx)

access top element for a pointer to vector structure

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