X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=dict.c;h=715e48f8deaa52c73bf499a3aae856dcc16a1e24;hb=dd4b319cdb6e2883ae76317036b57b670344160a;hp=a783ffcef36809a732f1b2789314ed838ae7891c;hpb=003aa44c1c2fecd15ff55f62aea88cda1a83be85;p=wordgame diff --git a/dict.c b/dict.c index a783ffc..715e48f 100644 --- a/dict.c +++ b/dict.c @@ -247,6 +247,13 @@ dict_fini (dict_t *dict) trie_fini (dict); } +void +dict_add_word (dict_t *dict, + const char *word) +{ + trie_add (dict, word); +} + void dict_add_words_from_file (dict_t *dict, const char *filename) @@ -268,7 +275,7 @@ dict_add_words_from_file (dict_t *dict, if (bytes_read == -1) break; chomp (line); - trie_add (dict, line); + dict_add_word (dict, line); } if (line) free (line); @@ -276,6 +283,52 @@ dict_add_words_from_file (dict_t *dict, fclose (file); } +dict_entry_t * +dict_lookup (dict_t *dict, + const char *word) +{ + trie_t *trie; + + trie = trie_find (dict, word); + if (trie == NULL) + return NULL; + else + return &trie->flags; +} + +/* Yes, this function is rather silly. I have it here in the hope that + * it could be used for some better type-checking, (if only C had such + * a thing). */ +dict_cursor_t +dict_root (dict_t *dict) +{ + return dict; +} + +dict_cursor_t +dict_cursor_next (dict_cursor_t cursor, + char next) +{ + trie_t *trie = cursor; + + if (trie == NULL) + return DICT_CURSOR_NIL; + + return trie->next[TRIE_CHAR_TO_INDEX (next)]; +} + +dict_entry_t * +dict_cursor_resolve (dict_cursor_t cursor) +{ + trie_t *trie; + + if (cursor == DICT_CURSOR_NIL) + return NULL; + + trie = cursor; + return &trie->flags; +} + void dict_print (dict_t *dict) {