summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-01-13 23:48:47 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-01-13 23:56:28 (GMT)
commita156dc15cccb54d662b0085c8e4f27767dd5542f (patch)
tree46fdadb99945b315f823a1359415ab5acbc5fad9 /src/common
parentd5b82c659081827182b2afbef468327b381fb850 (diff)
Fortified the tree of binary portions.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/sort.c40
-rw-r--r--src/common/sort.h3
2 files changed, 36 insertions, 7 deletions
diff --git a/src/common/sort.c b/src/common/sort.c
index 750034b..7da9a29 100644
--- a/src/common/sort.c
+++ b/src/common/sort.c
@@ -194,7 +194,7 @@ void *qinsert(void *base, size_t *nmemb, size_t size, __compar_fn_t compar, void
#ifndef NDEBUG
found = bsearch_index(new, base, *nmemb, size, compar, &index);
- //assert(!found); FIXME (portions)
+ assert(!found);
#else
bsearch_index(new, base, *nmemb, size, compar, &index);
#endif
@@ -208,6 +208,37 @@ void *qinsert(void *base, size_t *nmemb, size_t size, __compar_fn_t compar, void
/******************************************************************************
* *
+* 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. *
+* inde = indice du point de suppression. *
+* *
+* Description : Supprime un élément dans un tableau trié. *
+* *
+* Retour : Nouvel emplacement du tableau rétréci. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void *_qdelete(void *base, size_t *nmemb, size_t size, size_t index)
+{
+ void *result; /* Tableau trié à retourner */
+
+ if ((index + 1) < *nmemb)
+ memmove((char *)base + index * size, (char *)base + (index + 1) * size, (*nmemb - index - 1) * size);
+
+ (*nmemb)--;
+
+ result = realloc(base, *nmemb * size);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* 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. *
@@ -237,12 +268,7 @@ void *qdelete(void *base, size_t *nmemb, size_t size, __compar_fn_t compar, void
bsearch_index(target, base, *nmemb, size, compar, &index);
#endif
- if ((index + 1) < *nmemb)
- memmove((char *)base + index * size, (char *)base + (index + 1) * size, (*nmemb - index - 1) * size);
-
- (*nmemb)--;
-
- result = realloc(base, *nmemb * size);
+ result = _qdelete(base, nmemb, size, index);
return result;
diff --git a/src/common/sort.h b/src/common/sort.h
index 9fcc240..fb47a5e 100644
--- a/src/common/sort.h
+++ b/src/common/sort.h
@@ -43,6 +43,9 @@ void *_qinsert(void *, size_t *, size_t, void *, size_t);
void *qinsert(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);
+
+/* Supprime un élément dans un tableau trié. */
void *qdelete(void *, size_t *, size_t, __compar_fn_t, void *);