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

Map





The map module header is lapin/container/map.h.
typedef int (*t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌c‌m‌p)( const void *a, const void *b, void *param );

Description

$ This function pointer type is part of the t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p structure and is useful to compare two keys in order to search or sort items in the map container.

If this pointer is not set, then keys will be compared as size_t.

Parameters

  • void *a:
         The element to compare with b.
  • void *b:
         The element to compare with a.
  • void *param:
         An arbitrary parameter defined as param in t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p.

Return value

Return a positive integer if a is greater tha b. Equal to zero if they are equal. Negative if b is greater than a.



INDEX

typedef void *(*t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌d‌u‌p)( const void *a, void *param );

Description

$ This function pointer type is part of the t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p structure and is useful to duplicate keys. Making this a deep copy or a shallow copy is up to you.

If this pointer is not set, keys will not be duplicated when using functions like b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌g‌e‌t‌_‌d‌a‌t‌a or b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌g‌e‌t‌_‌s‌u‌b‌t‌r‌e‌e and pointers parameters sent to those functions will be used directly, which can be dangerous if not considered.

Parameters


Return value

a's duplicata or NULL on error.



INDEX

typedef void (*t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌d‌e‌l)( void *a, void *param );

Description

$ This function pointer type is part of the t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p structure and is useful to delete keys.

It should be sent only if the t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌d‌u‌p functions was also set.

Parameters




INDEX

typedef struct s_bunny_map
{
     const void * const data;
     const void * const key;
     size_t nbr_children;
     struct s_bunny_map * const up;
     struct s_bunny_map * const right;
     struct s_bunny_map * const left;
     const t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌c‌m‌p cmp;
     const t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌d‌u‌p dup;
     const t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌d‌e‌l del;
     const void * const param;

} t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p;

Description

     This structure is at the same time the map container and a node from it. It should be manipulated with map functions. It is created by b‌u‌n‌n‌y‌_‌n‌e‌w‌_‌m‌a‌p and deleted by b‌u‌n‌n‌y‌_‌d‌e‌l‌e‌t‌e‌_‌m‌a‌p.

Attributes

  • const void * const data:
         A data store inside this current node.
  • const void * const key:
         The key of the current node.
  • size_t nbr_children:
         How many nodes are under this one, directly or indirectly.
  • struct s_bunny_map * const up:
         The parent of the current node. If NULL, it means the current node is a root node.
  • struct s_bunny_map * const right:
         A node that contains greater keys than the current one.
  • struct s_bunny_map * const left:
         A node that contains lower keys than the current one.
  • const t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌c‌m‌p cmp:
         A function pointer to compare keys. If NULL, the default value, keys are compared like size_t.
  • const t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌d‌u‌p dup:
         A function pointer to duplicate keys. If NULL, the default value, keys fields are copied directly from parameters. (Making, possibily, a shallow copy)
  • const t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌d‌e‌l del:
         A function pointer to delete keys. If NULL, the default value, keys are not deleted. This function pointer should be set to a valid function if you set a function to the dup field.
  • const void * const param:
         An arbitrary value that will be sent to cmp, dup and del as last parameter.


INDEX


Description

     Create a t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p container. The returned value must be deleted with b‌u‌n‌n‌y‌_‌d‌e‌l‌e‌t‌e‌_‌m‌a‌p.

Parameters


Return value


Error values and logs

On error, $Vb‌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 the sent map. Returns how many elements there was inside.

Parameters


Return value

This functions returns how many elements there was inside the map.




INDEX


Description

     Clear the content the sent map node. Returns how many elements there was inside.

Parameters


Return value

This functions returns how many elements there was inside the map.




INDEX


Description

     Returns how many elements there is in the map.

Parameters


Return value

This functions returns how many elements there is in the map.




INDEX


Description

     Returns if the map is empty.

Parameters


Return value

This functions returns if the map is empty.




INDEX


Description

     Retrieve a node from the sent map associated with key, create it or not if it does not exist.

Parameters

  • t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p *map:
         The map to browse and eventually edit.
  • void *key:
         The key associated to the node you want to fetch or create.
  • bool create:
         If true and the node associated to key does not exists, create it.

Return value

  • On success, the function returns the address of the found or created node.
  • On failure, it returns NULL.

Error values and logs

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


  • ENOMEM:

    Out of memory.

  • BE_CANNOT_DUPLICATE:

    The set duplication function returned NULL.

  • BE_CANNOT_FIND_ELEMENT:

    The node was not found and create was false.

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



INDEX


Description

     Get the data inside the sent map node, which is of type type.

Parameters


Return value

It returns the data inside the sent map node, of type type.




INDEX


Description

     Get the data inside the sent map at key, which is of type type.

Parameters

  • t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p *map:
         The map node in which there is the data you want.
  • key:
         The key of the element you want to get.
  • type:
         The type of the data you want to get, any type is possible.

Return value

It returns the data inside the sent map at key, of type type.


Additional informations

This macro wraps a call to a real function, which is:

void *_b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌g‌e‌t‌_‌d‌a‌t‌a(t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p *map, void *key);



INDEX


Description

     Set data inside the sent map at key, which is of type type.

Parameters

  • t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p *map:
         The map node in which there is the data you want.
  • key:
         The key of the element you want to set.
  • data:
         The data you want to set.
  • type:
         The type of the data you want to set, any type is possible.

Return value

It returns the data inside the sent map at key, of type type.


Additional informations

This macro wraps a call to a real function, which is:

void *_b‌u‌n‌n‌y‌_‌m‌a‌p‌_‌s‌e‌t‌_‌d‌a‌t‌a( t‌_‌b‌u‌n‌n‌y‌_‌m‌a‌p *map, void *key, void *data );



INDEX


Description

     Call function with every nodes of map as first parameter, one after the other. Send param as second parameter.

Parameters




INDEX


Description

     Call function with every nodes of map as first parameter throught threads from pool, one after the other. Send param as second parameter.

Parameters


Return value

  • On complete success, the function returns true.
  • On failure, it returns false. Failire indicates all datas were not treated by threads, some of them may have been treated by the main thread because of a thread pool memory exhaustion. Elements are always all computed.



INDEX