summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-05-30 10:36:48 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-05-30 10:36:48 (GMT)
commitdde622ccf567e3ac01b471ea5d35cca4acf81277 (patch)
tree8d7e3f66986f8df37a62b75e26130432339407ee /src/common
parent00e93226e72bdb18853580f553e32df111422936 (diff)
Extended the API to insert items in a sorted array.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/sort.c30
-rw-r--r--src/common/sort.h3
2 files changed, 33 insertions, 0 deletions
diff --git a/src/common/sort.c b/src/common/sort.c
index eee11a3..e34d995 100644
--- a/src/common/sort.c
+++ b/src/common/sort.c
@@ -305,6 +305,36 @@ void *qinsert(void *base, size_t *nmemb, size_t size, __compar_fn_t compar, void
/******************************************************************************
* *
+* Paramètres : base = adresse du tableau à parcourir. *
+* nmemb = nombre d'éléments présents au total. [OUT] *
+* size = taille de chaque élément du tableau. *
+* compar = méthode de comparaison entre éléments. *
+* new = nouvel élément à insérer. *
+* *
+* Description : Ajoute au bon endroit un élément dans un tableau trié. *
+* *
+* Retour : Nouvel emplacement du tableau agrandi. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void *qinsert_multi(void *base, size_t *nmemb, size_t size, __compar_fn_t compar, void *new)
+{
+ void *result; /* Tableau trié à retourner */
+ size_t index; /* Indice du point d'insertion */
+
+ bsearch_index(new, base, *nmemb, size, compar, &index);
+
+ result = _qinsert(base, nmemb, size, new, index);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : base = adresse du tableau à parcourir. *
* nmem = nombre d'éléments présents au total. [OUT] *
* size = taille de chaque élément du tableau. *
diff --git a/src/common/sort.h b/src/common/sort.h
index 2d9e672..eb86ccb 100644
--- a/src/common/sort.h
+++ b/src/common/sort.h
@@ -52,6 +52,9 @@ void *_qinsert(void *, size_t *, size_t, void *, size_t);
/* Ajoute au bon endroit un élément dans un tableau trié. */
void *qinsert(void *, size_t *, size_t, __compar_fn_t, void *);
+/* Ajoute au bon endroit un élément dans un tableau trié. */
+void *qinsert_multi(void *, size_t *, size_t, __compar_fn_t, void *);
+
/* Supprime un élément dans un tableau trié. */
void *_qdelete(void *, size_t *, size_t, size_t);