commit 36a02dfb17c55c9412724807b6e47237adc89e9d
parent ec036f403645a3a1821e5a8b84482b74f03083a7
Auteur: Loïc Daignault-Pichette <loic@asteride.xyz>
Date: Thu, 9 Apr 2026 13:53:57 -0400
Faire que -1 marque la fin des transitions
Ce changement permet de manipuler les listes chaînées indépendamment du champ
ntrans.
Diffstat:
2 fichiers modifiés, 10 insertions(+), 2 suppressions(-)
diff --git a/tfm.c b/tfm.c
@@ -79,6 +79,11 @@ tfm_ajt(struct tfm *tfm, size_t es, size_t ed, ssize_t se, ssize_t ss)
/* Assurer que l’état source existe. */
if (tampex_minim((void **)&tfm->etats, es) < 0)
return -1;
+ if (!tfm->etats[es].existe) {
+ tfm->etats[es].existe = 1;
+ tfm->etats[es].trans = -1;
+ }
+
/* Ajouter une transitions. */
if ((itrans = tampex_empl((void **)&tfm->trans)) < 0)
@@ -94,6 +99,8 @@ tfm_ajt(struct tfm *tfm, size_t es, size_t ed, ssize_t se, ssize_t ss)
tfm->etats[es].trans = itrans;
tfm->etats[es].ntrans++;
tfm->etats[es].trie = 0;
+
+ /* Mettre à jour le tfm. */
tfm->trie = 0;
TFM_COHERENT(tfm);
diff --git a/tfm.h b/tfm.h
@@ -33,8 +33,9 @@ struct tfm {
* être marqué comme final. trans est un indice dans le tampon tfm->trans. */
struct etat {
- size_t trans; /* Liste chaînée de transitions. */
+ ssize_t trans; /* Liste chaînée de transitions. -1 marque la fin. */
size_t ntrans; /* Nombre de transitions. */
+ bool existe; /* Si l’état existe. */
bool final; /* État final? */
bool trie; /* Si les transitions sont triées. */
};
@@ -51,7 +52,7 @@ struct trans {
ssize_t se; /* Symbole d’entrée. */
ssize_t ss; /* Symbole de sortie. */
size_t ed; /* État destination. */
- size_t prch; /* Prochaine transition. */
+ ssize_t prch; /* Prochaine transition. -1 marque la fin. */
};
/* Initialiser un tfm.