From: Carl Worth Date: Thu, 21 Sep 2006 09:11:58 +0000 (-0700) Subject: Move IS_WORD flag from trie to dict layer X-Git-Url: https://git.cworth.org/git?p=wordgame;a=commitdiff_plain;h=54a35ad5a96cc57816a9e05ab9d1e1513c202894 Move IS_WORD flag from trie to dict layer --- diff --git a/dict.c b/dict.c index 50b741e..cef51d4 100644 --- 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 ca0e6f6..d5aa1cd 100644 --- 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