int
trie_print_unseen (trie_t *trie, string_t *word);
-struct _dict {
- trie_t *trie;
-};
-
#endif /* _DICT_IMPL_H_ */
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)
+dict_init (dict_t *dict)
{
- dict->trie = trie_create ();
+ trie_init (dict);
+}
+
+void
+dict_fini (dict_t *dict)
+{
+ trie_fini (dict);
}
void
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);
}
#include "dict-impl.h"
/* Only looks opaque. Perfectly stack-allocatable */
-typedef struct _dict dict_t;
+typedef trie_t dict_t;
void
dict_init (dict_t *dict);
char letters[4][4];
/* Private, transient state used by enumerate */
- trie_t *result_trie;
+ dict_t *result_trie;
} board_t;
int
for (y = 0; y < 4; y++)
for (x = 0; x < 4; x++)
- board_enumerate (board, x, y, seen, &word, dict->trie);
+ board_enumerate (board, x, y, seen, &word, dict);
string_fini (&word);
}
else
t->flags |= TRIE_FLAGS_SEEN;
} else {
- t = trie_find (dict.trie, response);
+ t = trie_find (&dict, response);
if (t && (t->flags & TRIE_FLAGS_IS_WORD))
printf ("(a good word, but it's not in the puzzle)\n");
else