]> git.cworth.org Git - wordgame/commitdiff
Move IS_WORD flag from trie to dict layer
authorCarl Worth <cworth@raht.cworth.org>
Thu, 21 Sep 2006 09:11:58 +0000 (02:11 -0700)
committerCarl Worth <cworth@raht.cworth.org>
Thu, 21 Sep 2006 09:11:58 +0000 (02:11 -0700)
dict.c
dict.h

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
diff --git a/dict.h b/dict.h
index ca0e6f6e9a209efe442a3ea8083e0d2480cc7e1b..d5aa1cd529ad8fad71a21658811c3e40177e9305 100644 (file)
--- a/dict.h
+++ b/dict.h
@@ -70,7 +70,9 @@ dict_count (dict_t                    *dict,
 /* Querying a dictionary entry. The dict interface uses 1 bit.
  * All of the remaining bits are available for application use.
  */
-#define DICT_ENTRY_IS_WORD(entry) ((entry) && ((*entry) & 0x01))
+#define DICT_ENTRY_FLAG_IS_WORD                (1<<0)
+
+#define DICT_ENTRY_IS_WORD(entry) ((entry) && ((*entry) & DICT_ENTRY_FLAG_IS_WORD))
 
 /* Printing the dictionary */
 int