Bienvenue sur le site de la LibLapin.
Jetez un coup d'oeil en bas de la page pour choisir votre niveau de documentation en fonction de votre niveau avec la LibLapin.
Pour l'instant, c'est réglé sur 'Manuel complet'. Si c'est votre première fois avec la LibLapin, il vaudrait mieux choisir 'Débutant'.
De même, n'oubliez pas de préciser une version de la bibliothèque.
Vector
The Vector module brings the t_bunny_vector
object which encapsulate a resizable array with constructible and destructible
elements storage.
By being made out of an array, the Vector module is fast when
you need a random access and is slow when you need to extend its size or to
shift elements.
The vector module header is lapin/container/vector.h.
Description
  This structure is the main data of the Vector container.
It allow to set and retrieve a few informations, but is preferably
considered as an abstract type: to use only with its associated functions.
  This type cannot be declared on stack. It must be created by a call
to
bunny_new_vector.
Attributes
-
t_bunny_constructor ctor:
  The ctor attribute contains a function pointer that will be used
when the container needs to build a new object: at the beginning
while building the vector itself or while resizing.
NULL is an acceptable value.
-
t_bunny_destructor dtor:
  The dtor attribute contains a function pointer that will be used
when the container needs to delete an object: at the end while
deleting the vector itself or while resizing.
NULL is an acceptable value.
-
const size_t nmemb:
  This attribute contains the number of elements inside the vector.
-
const size_t elemsize:
  This attribute contains the size in byte of a single element in the
vector.
- void * const array:
  This attribute is the array containing your data. It cannot
be used without precising the type of the stored data.
You can use the bunny_vector_data macro
to set or get a value from the vector.
You can use the bunny_vector_address
macro to get the address of a value in the vector.
INDEX
Parameters
-
size_t nmemb:
  The amount of elements inside the vector.
-
type:
  The type of elements inside the vector.
Return value
-
On success, the function returns a vector instance.
-
On failure, it returns NULL.
Error values and logs
On error, bunny_errno is set to:
Logs written by this function are tagged with the "container" label.
INDEX
Description
  Create a Vector instance of nmemb elements of a specific type
with specific rules for construction and destruction of elements inside.
The returned vector must be freed with
bunny_delete_vector.
Parameters
-
size_t nmemb:
  The amount of elements inside the vector.
-
type:
  The type of elements inside the vector.
-
t_bunny_constructor ctor,
  The function that will be called when the vector needs to create a new
element, when being created or when being resized.
  NULL may be sent so no construction is made, only memory allocation.
-
t_bunny_destructor dtor,
  The function that will be called when the vector needs to delete an
element, when being deleted or when being resized.
  NULL may be sent so no destruction is made, only memory release.
-
void *data:
  A data that will be sent to the construction function while building
the initial element. This parameter is not stored!
  If both ctor and dtor are NULL, this parameter is useless.
Return value
-
On success, the function returns a vector instance.
-
On failure, it returns NULL.
Error values and logs
On error, bunny_errno is set to:
Logs written by this function are tagged with the "container" label.
INDEX
Description
  Delete a vector. Release all data that was reserved.
Call the destructor if any.
Logs
Logs written by this function are tagged with the "container" label.
INDEX
Description
  Return the amount of elements inside the container.
Return value
-
This function returns the amount of elements inside the container.
INDEX
Description
  Return true if there is no element in the container.
Return value
-
This function returns true if there is no element, false if there is one or more.
INDEX
Description
  Return the size in bytes of a single element of the sent vector.
Return value
-
This function returns the size in bytes of a single element in vector.
INDEX
Description
  Return the element at position idx in vector. The sent type must match the
type sent at the vector construction. This macro can be used to read or write.
Parameters
-
t_bunny_vector *vector:
  The vector to extract informations from.
-
size_t idx:
  The index of the element you want to fetch. Must not be greater
than the vector size minus 1.
-
type:
  The type of the element you want to fetch. It must match
the type sent at the vector construction.
Return value
-
This function returns the element at position idx in vector.
INDEX
Description
  Return the address of the element at position idx in vector.
Parameters
-
t_bunny_vector *vector:
  The vector to extract informations from.
-
size_t idx:
  The index of the element you want to the address.
Must not be greater than the vector size minus 1.
Return value
-
This function returns the address of the element at position idx in vector.
INDEX
Description
  Resize the vector to fit a new amount of elements.
If the new size of the vector is smaller than the previous one, there is no
reallocation and the operation is fast. If it is greater, a reallocation
followed by a copy may happen.
If the vector is getting smaller, excessive elements will be sent
to the destructor function that was defined if there was one.
If the vector is getting greater, new elements will be built by being
sent to the construction function that was defined if there was one.
The
add parameter will be sent too to the constructor.
If you want to enforce reallocation when reducing the vector, you better
use
bunny_vector_crop after resizing it.
Parameters
-
t_bunny_vector *vec:
  The vector to resize.
-
size_t newsize:
  The new size of the vector.
-
void *add:
  A parameter to send to the constructor stored inside the
vector if there is one. Il could be NULL.
Return value
-
On success, the function returns the address of the vector.
If the vector was reallocated then it is a new one and the sent
one does not exist anymore.
-
On failure, it returns NULL.
Error values and logs
On error, bunny_errno is set to:
Logs written by this function are tagged with the "container" label.
INDEX
Description
  Force the inside memory chunk handled by the vector to fits its
requested size, reallocating it if neccessary.
Return value
-
On success, the function returns the address of the vector.
If the vector was reallocated then it is a new one and the sent
one does not exist anymore.
-
On failure, it returns NULL.
Error values and logs
On error, bunny_errno is set to:
Logs written by this function are tagged with the "container" label.
INDEX
Parameters
-
const void *a:
  An element from a vector to be compared.
-
const void *b:
  Another element from a vector to be compared.
-
void *param:
  A parameter sent throught bunny_vector_sort.
Return value
Return a negative value if the first parameter is smaller than
the second one.
A zero value if they are equal.
A positive value if the first parameter is greater than the second one.
INDEX
Description
  This function sorts the sent vector in ascending order. The sent function
pointer is used to compare two elements together, allowing you to compare
complex elements.
INDEX
Return value
-
On success, the function returns a list instance.
-
On failure, it returns NULL.
Error values and logs
On error, bunny_errno is set to:
Logs written by this function are tagged with the "container" label.
INDEX
Description
  Call the sent function with, as first parameter,
each elements inside the vector, one after the other,
and with param as second element.
Error values and logs
On error, bunny_errno is set to:
Logs written by this function are tagged with the "container" label.
INDEX
Description
  Call the sent function with, as first parameter,
each elements inside the vector, one after the other,
and with
param as second element.
Elements may be processed in separated threads, depending
of the sent threadpool. The threadpool is created by
bunny_new_threadpool.
Error values and logs
On error, bunny_errno is set to:
Logs written by this function are tagged with the "container" label.
INDEX