commit 00964abc46fe4ab3823190f62914f24ffd20258f
parent 599c4f6df5f92e3760a2179446c2ed6709a7f498
Auteur: Loïc Daignault-Pichette <loic@asteride.xyz>
Date: Fri, 10 Apr 2026 12:59:21 -0400
Extraire la la comparison du tri
Diffstat:
| M | tfm.c | | | 20 | +++++++++++++++++++- |
1 fichier modifié, 19 insertions(+), 1 suppression(-)
diff --git a/tfm.c b/tfm.c
@@ -1,4 +1,5 @@
#include <assert.h>
+#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@@ -28,6 +29,11 @@ static ssize_t tfm_symb_chercher(char *te, char *symb, size_t lngr);
* Renvoie 0, ou -1 en cas d’erreur. */
static void trier_etat(struct tfm *tfm, size_t ietat);
+/* Comparer deux transition pour les trier.
+ * Renvoie -1 si t1 est inférieure t2, 0 s’ils sont égales et 1 si t2 est
+ * inférieure à t1. */
+static int trans_comparer(struct tfm *tfm, size_t t1, size_t t2);
+
struct tfm *
tfm_init(void)
{
@@ -267,7 +273,7 @@ trier_etat(struct tfm *tfm, size_t ietat)
while ((ts1 > 0) || ((ts2 > 0) && (s2 != -1))) {
if (ts1 == 0) goto des2;
if (ts2 == 0 || s2 == -1) goto des1;
- if (tfm->trans[s1].se <= tfm->trans[s2].se) {
+ if (trans_comparer(tfm, s1, s2) <= 0) {
des1:
trans = s1;
s1 = tfm->trans[s1].prch;
@@ -297,6 +303,18 @@ trier_etat(struct tfm *tfm, size_t ietat)
tfm->etats[ietat].trans = liste;
}
+static int
+trans_comparer(struct tfm *tfm, size_t t1, size_t t2)
+{
+ TFM_COHERENT(tfm);
+
+ if (tfm->trans[t1].se < tfm->trans[t2].se)
+ return -1;
+ if (tfm->trans[t1].se == tfm->trans[t2].se)
+ return 0;
+ return 1;
+}
+
static ssize_t
tfm_symb_chercher(char *ti, char *symb, size_t lngr)
{