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.

LibLapin's logo

LibLapin

Vector





The Vector module brings the t‌_‌b‌u‌n‌n‌y‌_‌v‌e‌c‌t‌o‌r 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.

typedef struct s_bunny_vector
{
     t‌_‌b‌u‌n‌n‌y‌_‌c‌o‌n‌s‌t‌r‌u‌c‌t‌o‌r ctor;
     t‌_‌b‌u‌n‌n‌y‌_‌d‌e‌s‌t‌r‌u‌c‌t‌o‌r dtor;
     const size_t nmemb;
     const size_t elemsize;
     void * const array;

} t‌_‌b‌u‌n‌n‌y‌_‌v‌e‌c‌t‌o‌r;

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 b‌u‌n‌n‌y‌_‌n‌e‌w‌_‌v‌e‌c‌t‌o‌r.

Attributes



INDEX


Description

     Create a Vector instance of nmemb element of specified type.

The returned vector must be freed with b‌u‌n‌n‌y‌_‌d‌e‌l‌e‌t‌e‌_‌v‌e‌c‌t‌o‌r.

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, b‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.


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 b‌u‌n‌n‌y‌_‌d‌e‌l‌e‌t‌e‌_‌v‌e‌c‌t‌o‌r.

Parameters

  • size_t nmemb:
         The amount of elements inside the vector.
  • type:
         The type of elements inside the vector.
  • t‌_‌b‌u‌n‌n‌y‌_‌c‌o‌n‌s‌t‌r‌u‌c‌t‌o‌r 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‌_‌b‌u‌n‌n‌y‌_‌d‌e‌s‌t‌r‌u‌c‌t‌o‌r 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, b‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.


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.

Parameters


Logs

Logs written by this function are tagged with the "container" label.




INDEX


Description

     Return the amount of elements inside the container.

Parameters


Return value

  • This function returns the amount of elements inside the container.


INDEX


Description

     Return true if there is no element in the container.

Parameters


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.

Parameters


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‌_‌b‌u‌n‌n‌y‌_‌v‌e‌c‌t‌o‌r *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


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 b‌u‌n‌n‌y‌_‌v‌e‌c‌t‌o‌r‌_‌c‌r‌o‌p after resizing it.

Parameters


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, b‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.


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.

Parameters


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, b‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.


Logs written by this function are tagged with the "container" label.




INDEX

typedef int (*t‌_‌b‌u‌n‌n‌y‌_‌c‌o‌m‌p‌a‌r‌a‌t‌o‌r)( const void *a, const void *b, void *param );

Description

     This function pointer is used by the function b‌u‌n‌n‌y‌_‌v‌e‌c‌t‌o‌r‌_‌s‌o‌r‌t to compare two elements and sort them.

Parameters


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.

Parameters



INDEX


Description

     Create a list containing the elements of the sent vector. All elements are duplicated with b‌u‌n‌n‌y‌_‌m‌e‌m‌d‌u‌p so you can delete the vector freely.

The returned list must be freed with b‌u‌n‌n‌y‌_‌d‌e‌l‌e‌t‌e‌_‌l‌i‌s‌t.

Parameters


Return value

  • On success, the function returns a list instance.
  • On failure, it returns NULL.

Error values and logs

On error, b‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.


Logs written by this function are tagged with the "container" label.



INDEX


Description

     This function pointer is used by b‌u‌n‌n‌y‌_‌v‌e‌c‌t‌o‌r‌_‌f‌o‌r‌e‌a‌c‌h and b‌u‌n‌n‌y‌_‌v‌e‌c‌t‌o‌r‌_‌f‌a‌s‌t‌_‌f‌o‌r‌e‌a‌c‌h as they are called by them with elements from a vector as parameter.




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.

Parameters


Error values and logs

On error, b‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.


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 b‌u‌n‌n‌y‌_‌n‌e‌w‌_‌t‌h‌r‌e‌a‌d‌p‌o‌o‌l.

Parameters


Error values and logs

On error, b‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.


Logs written by this function are tagged with the "container" label.




INDEX