trie->next[i] = NULL;
}
+void
+trie_destroy (trie_t *trie);
+
+static void
+trie_fini (trie_t *trie)
+{
+ int i;
+
+ for (i = 0; i < 26; i++)
+ if (trie->next[i])
+ trie_destroy (trie->next[i]);
+}
+
trie_t *
trie_create (void)
{
void
trie_destroy (trie_t *trie)
{
- int i;
-
- for (i = 0; i < 26; i++)
- if (trie->next[i])
- trie_destroy (trie->next[i]);
+ trie_fini (trie);
free (trie);
}
}
void
-dict_init (dict_t *dict,
- const char *filename)
+dict_init (dict_t *dict)
+{
+ trie_init (dict);
+}
+
+void
+dict_fini (dict_t *dict)
+{
+ trie_fini (dict);
+}
+
+void
+dict_add_words_from_file (dict_t *dict,
+ const char *filename)
{
FILE *file;
char *line = NULL;
exit (1);
}
- dict->trie = trie_create ();
-
while (1) {
bytes_read = getline (&line, &line_size, file);
if (bytes_read == -1)
break;
chomp (line);
- trie_add (dict->trie, line);
+ trie_add (dict, line);
}
if (line)
free (line);
fclose (file);
}
-void
-dict_fini (dict_t *dict)
-{
- trie_destroy (dict->trie);
-}
-
void
dict_print (dict_t *dict)
{
string_init (&string);
- trie_print (dict->trie, &string, NULL);
+ trie_print (dict, &string, NULL);
string_fini (&string);
}