Skip to content

glegendr/libvec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libvec

Documentation

check here for more informations

C vector librairy

the structure

you can see the structure here

typedef struct	s_vec
{
  void      *private_content;           // vector's content
  int       private_elem_nb;            // current number of element
  int       private_elem_size;          // size of element
  int       private_elem_cap;           // number of element capacity
}               t_vec;

vectors functions

Copy raw at the end of the vector.

Params:

  • vec: the current vector.
  • raw: the raw to add at the end of vector.
  • nb: the numbers of elems content in the raw.

Return value:

void.

void			v_append_raw(t_vec *vec, void *raw, int nb);

Copy a vector into a new vector.

Params:

  • vec: the current vector.

Return value:

the copy of the current vector (t_vec)

t_vec			v_copy(t_vec *vec);

Free the vector.

Param:

  • vec: the vector to delete.

Return value:

void.

void			v_del(t_vec *vec);

Free the vector and all vector in.

Param:

  • vec: the vector to delete.

Return value:

void.

void			v_del_all(t_vec *vec);

Del the last Param. Param:

  • vec: the vector to delete.

Return value:

void.

void			v_del_last(t_vec *vec);

Get the pointer of element pointed by index.

Params:

  • vec: the current vector.
  • index: the index.

Return value:

the pointer of the element pointed by index (void *)

void			*v_get(t_vec *vec, int index);

Give the size of type.

Param:

  • vec: the current vector.

Return value:

the size of the current vector (int)

int				v_get_size(t_vec *vec);

Create a new vector.

Param:

  • elem_size: the size of each element of the vector.

Return value:

the new vector (t_vec)

t_vec			v_new(int elem_size);

Create a new vector but don't malloc it.

Param:

  • elem_size: the size of each element of the vector.

Return value:

the new vector (t_vec)

t_vec			v_new_null(int elem_size);

return the last part of the vector and del it from the vector.

Params:

  • vec: the current vector.

Return value:

the pointer of the element deleted from the vector (void *)

void			*v_pop(t_vec *vec);

Print a vector.

Params:

  • vec: the current vector.

Return value:

void.

void			v_print(t_vec *vec);

Copy a new element at the end of the vector.

Params:

  • vec: the current vector.
  • elem: the element to add at the end of vector.

Return value:

void.

void			v_push(t_vec *vec, void *elem);

Copy a new element at the end of the vector. -this one is an int-

Params:

  • vec: the current vector.
  • elem: the element to add at the end of vector.

Return value:

void.

void			v_push_int(t_vec *vec, int elem);

Copy a new element at the start of the vector.

Params:

  • vec: the current vector.
  • elem: the element to add at the end of vector.

Return value:

void.

void			v_push_first(t_vec *vec, void *elem);

Give the raw.

Param:

  • vec: the current vector.

Return value:

the current data (void *)

void			*v_raw(t_vec *vec);

Reset the current vector.

Param:

  • vec: the vector to reset.

Return value:

void.

void			v_reset(t_vec *vec);

Rotate the vector by 1 right.

Params:

  • vec: the current vector.

Return value:

void.

void			v_reverse_rotate(t_vec *vec);

Rotate the vector by 1 left.

Params:

  • vec: the current vector.

Return value:

void.

void			v_rotate(t_vec *vec);

Return the element number in the vector.

Param:

  • vec: the current vector.

Return value:

the current size (int)

int				v_size(t_vec *vec);

Sort the current all vector in the current vector by size.

Param:

  • vec: the current vector.

Return value:

void.

void			v_sort_size(t_vec *vec);

Split a vector into two vector at the index.

Pararms:

  • vec: the current vector.
  • index: the index where you have to cut.

Return value:

a new vector filled by the first part of the given vector (t_vec)

t_vec			v_split(t_vec *vec, int index);

Split the vector's data into two data at the index.

Pararms:

  • vec: the current vector.
  • index: the index where you have to cut.

Return value:

a new data filled by the first part of the given vector (void *)

void			*v_split_raw(t_vec *vec, int index);

Swap 2 params of a vector.

Params:

  • vec: the current vector.
  • first: the first elem to Swap.
  • second: the second elem to Swap.

Return value:

void.

void			v_swap(t_vec *vec, size_t first, size_t second);

Utils functions

Function Used in
v_memcpy v_realloc v_append_raw v_copy v_push v_push_int v_push_first v_reverse_rotate v_rotate v_split v_swap
v_realloc v_append_raw v_push v_push_int v_push_first
v_putchar v_putnbr v_print
v_putnbr v_print

Copy a memory into an other one.

Params:

  • dst: the destination (non malloced).
  • src: the memory to Copy.
  • n: size of the memory src.

Return value:

an other pointer of the destination (void *)

void			*v_memcpy(void *dst, const void *src, size_t n);

Copy a memory and malloc to the new size.

Params:

  • dst: the memory to Copy.
  • mem_size: the size of memory dst.
  • new_size: the size you want for your new memory.

Return value:

an other pointer of the destination (void *)

void			*v_realloc(void *dst, int mem_size, int new_size);

Print a character.

Params:

  • c: the current character.

Return value:

void.

void			v_putchar(char c);

Print a number.

Params:

  • nb: the current number.

Return value:

void.

void			v_putnbr(int nb);

Releases

No releases published

Packages

No packages published