AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
vector.h
1 
21 #ifndef _AVRIO_VECTOR_H_
22 #define _AVRIO_VECTOR_H_
23 
24 #include <avrio/defs.h>
25 __BEGIN_C_DECLS
26 /* ========================================================================== */
27 
37 /* macros =================================================================== */
38 
39 /* types ==================================================================== */
40 
44 typedef void * (*vVectorElmtNew) (void);
45 
49 typedef void (*vVectorElmtDestroy) (void *data);
50 
55 typedef int (*iVectorElmtMatch) (const void *key1, const void *key2);
56 
60 typedef const void * (*pvVectorElmtKey) (const void * element);
61 
62 /* structures =============================================================== */
67 typedef struct vVector {
68  void** data;
69  int size;
70  int alloc;
71  int growth;
72  union {
73  uint16_t flag;
74  struct {
75  uint16_t malloc: 1;
76  };
77  };
78  vVectorElmtNew fnew;
79  vVectorElmtDestroy fdestroy;
80  pvVectorElmtKey fkey;
81  iVectorElmtMatch fmatch;
82 } xVector;
83 
84 /* internal public functions ================================================ */
85 
97 int iVectorInit (xVector * vector, int growth, vVectorElmtNew fnew, vVectorElmtDestroy fdestroy);
98 
106 int iVectorInitSearch (xVector *vector, pvVectorElmtKey fkey, iVectorElmtMatch fmatch);
107 
113 int iVectorSize (const xVector * vector);
114 
126 int iVectorResize (xVector * vector, int new_size);
127 
137 void vVectorDestroy (xVector * vector);
138 
147 int iVectorClear (xVector * vector);
148 
160 int iVectorAppend (xVector * vector, void * data);
161 
167 void * pvVectorGet (const xVector * vector, int index);
168 
179 int iVectorRemove (xVector * vector, int index);
180 
196 int iVectorReplace (xVector * vector, int index, void * data);
197 
204 void * pvVectorFindFirst (const xVector * vector, const void * key);
205 
212 int iVectorFindFirstIndex (const xVector * vector, const void * key);
213 
220 /* ========================================================================== */
221 __END_C_DECLS
222 #endif /*_AVRIO_VECTOR_H_ defined */
int iVectorFindFirstIndex(const xVector *vector, const void *key)
Chercher l&#39;index du premier élément correspondant à une clé
int iVectorAppend(xVector *vector, void *data)
Ajout en fin de tableau.
void ** data
Definition: vector.h:68
int iVectorReplace(xVector *vector, int index, void *data)
Modifie l&#39;élément pointé par une case.
int iVectorInitSearch(xVector *vector, pvVectorElmtKey fkey, iVectorElmtMatch fmatch)
Initialise les fonctions de recherche.
void *(* vVectorElmtNew)(void)
Fonction qui retourne un élément alloué avec une valeur par défaut.
Definition: vector.h:44
const void *(* pvVectorElmtKey)(const void *element)
Retourne la clé d&#39;un élément.
Definition: vector.h:60
int iVectorResize(xVector *vector, int new_size)
Modifie la taille.
void(* vVectorElmtDestroy)(void *data)
Fonction qui libère la mémoire allouée à une donnée de le vecteur.
Definition: vector.h:49
int alloc
Definition: vector.h:70
Vecteur dynamique.
Definition: vector.h:67
int size
Definition: vector.h:69
int iVectorInit(xVector *vector, int growth, vVectorElmtNew fnew, vVectorElmtDestroy fdestroy)
Initialise un tableau dynamique.
int iVectorSize(const xVector *vector)
Taille du tableau en nombre d&#39;éléments.
int growth
Definition: vector.h:71
int(* iVectorElmtMatch)(const void *key1, const void *key2)
Fonction de comparaison de 2 clés.
Definition: vector.h:55
void * pvVectorGet(const xVector *vector, int index)
Pointeur sur l&#39;élément.
int iVectorClear(xVector *vector)
Vide un tableau dynamique.
int iVectorRemove(xVector *vector, int index)
Retire un élément.
void * pvVectorFindFirst(const xVector *vector, const void *key)
Chercher le premier élément correspondant à une clé
void vVectorDestroy(xVector *vector)
Destruction d&#39;un tableau dynamique.