interface trie avec des strings

This commit is contained in:
2025-05-07 21:21:48 +02:00
parent d5a120cd9a
commit ddebd453df
4 changed files with 40 additions and 21 deletions

View File

@ -31,8 +31,8 @@ function dico($longueur_max) {
break;
}
$mot = str_split(strtoupper($mot));
$longueur = count($mot);
$mot = strtoupper($mot);
$longueur = strlen($mot);
if (!isset($dico[$longueur])) $dico[$longueur] = new Trie();
if (!isset($dico[$longueur][$mot])) $dico[$longueur][$mot] = [];
if (strlen($definition)) $dico[$longueur][$mot][] = $definition;
@ -50,9 +50,9 @@ function mots_espaces($longueur_max) {
for ($longueur = 1; $longueur <= $longueur_max; $longueur++) {
for ($position_espace = MIN_PREMIER_MOT; $position_espace + MIN_MOTS_SUIVANTS < $longueur; $position_espace++) {
$mots_suivants = $dico[$longueur - $position_espace - 1];
foreach ($dico[$position_espace] as $premier_mot => $definition) {
foreach ($dico[$position_espace]->arrayIterator() as $premier_mot => $definition) {
$premier_mot[] = " ";
$dico[$longueur][$premier_mot] = $mots_suivants;
$dico[$longueur]->arraySet($premier_mot, $mots_suivants);
}
}
}