summaryrefslogtreecommitdiff
path: root/src/common/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/array.c')
-rw-r--r--src/common/array.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/common/array.c b/src/common/array.c
index 641a885..e4e7bb1 100644
--- a/src/common/array.c
+++ b/src/common/array.c
@@ -34,6 +34,9 @@
#include <string.h>
+#include "sort.h"
+
+
/**
* L'expression du besoin d'une gestion optimisée des tableaux se base sur la
@@ -259,6 +262,64 @@ void add_item_to_flat_array(flat_array_t **array, const void *item, size_t size)
/******************************************************************************
* *
+* Paramètres : array = tableau compressé à mettre à jour. [OUT] *
+* item = adresse de l'élément à rajouter. *
+* size = taille de ce nouvel élément. *
+* compar = méthode de comparaison entre éléments. *
+* *
+* Description : Ajoute un élément supplémentaire à un tableau trié. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void insert_item_into_flat_array(flat_array_t **array, void *item, size_t size, __compar_fn_t compar)
+{
+ ext_flat_array_t *extended; /* Version de tableau étendue */
+
+ assert(FLAT_ARRAY_IS_LOCKED(*array));
+
+ if (FLAT_ARRAY_IS_EMPTY(*array))
+ {
+ *array = malloc(size);
+ memcpy(*array, item, size);
+
+ lock_flat_array(array);
+
+ }
+
+ else
+ {
+ if (FLAT_ARRAY_HAS_NO_INDEX(*array))
+ {
+ extended = (ext_flat_array_t *)malloc(sizeof(ext_flat_array_t));
+
+ extended->items = malloc(size);
+ extended->count = 1;
+
+ memcpy(extended->items, GET_LONELY_ITEM(*array), size);
+
+ FLAT_ARRAY_SET_INDEX(extended);
+
+ *array = (flat_array_t *)extended;
+
+ lock_flat_array(array);
+
+ }
+
+ extended = EXTENDED_ARRAY(*array);
+
+ extended->items = qinsert(extended->items, &extended->count, size, compar, item);
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : array = tableau compressé à mettre à jour. *
* index = indice de l'élément à remplacer. *
* new = adresse de l'élément à rajouter. *