]> git.cworth.org Git - wordgame/blobdiff - dict.c
Move IS_WORD flag from trie to dict layer
[wordgame] / dict.c
diff --git a/dict.c b/dict.c
index 50b741eb9cd5697e066d4df81e92f9c0ef6c9ef8..cef51d4a08e1fb6163618aff084c623eef8b5ce9 100644 (file)
--- a/dict.c
+++ b/dict.c
@@ -32,8 +32,6 @@ typedef struct _string {
     size_t len;
 } string_t;
 
-#define TRIE_FLAGS_IS_WORD     (1<<0)
-
 typedef bool_t
 (*trie_predicate_t) (trie_t *trie);
 
@@ -165,23 +163,21 @@ trie_destroy (trie_t *trie)
     free (trie);
 }
 
-static void
+static trie_t *
 trie_add (trie_t       *trie,
          const char    *word_chunk)
 {
     char c = word_chunk[0];
     int i;
 
-    if (c == '\0') {
-       trie->flags |= TRIE_FLAGS_IS_WORD;
-       return;
-    }
+    if (c == '\0')
+       return trie;
 
     i = TRIE_CHAR_TO_INDEX (c);
     if (trie->next[i] == NULL)
        trie->next[i] = trie_create ();
 
-    trie_add (trie->next[i], word_chunk + 1);
+    return trie_add (trie->next[i], word_chunk + 1);
 }
 
 static trie_t *
@@ -269,7 +265,10 @@ void
 dict_add_word (dict_t          *dict,
               const char       *word)
 {
-    trie_add (dict, word);
+    trie_t *trie;
+
+    trie = trie_add (dict, word);
+    trie->flags |= DICT_ENTRY_FLAG_IS_WORD;
 }
 
 void