X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=dict.h;h=e58c8b4c4e3c992ca82ff67c0c04039af43fc8f1;hb=003aa44c1c2fecd15ff55f62aea88cda1a83be85;hp=4d4885c7e9423651b592d85e1c6e28cc4c9b1f31;hpb=2eb18813b84ae8ad4faeb92b1d8570599135d537;p=wordgame diff --git a/dict.h b/dict.h index 4d4885c..e58c8b4 100644 --- a/dict.h +++ b/dict.h @@ -19,77 +19,20 @@ #ifndef _DICT_H_ #define _DICT_H_ -#include +#include "dict-impl.h" -#ifndef FALSE -# define FALSE 0 -#endif - -#ifndef TRUE -# define TRUE 1 -#endif - -typedef int bool_t; - -typedef struct _string { - size_t size; - char *s; - size_t len; -} string_t; +/* Only looks opaque. Perfectly stack-allocatable */ +typedef trie_t dict_t; void -string_init (string_t *string); +dict_init (dict_t *dict); void -string_fini (string_t *string); - -void -string_append_char (string_t *string, char c); - -void -string_chop (string_t *string); - -void -chomp (char *s); - -#define TRIE_FLAGS_IS_WORD (1<<0) -#define TRIE_FLAGS_SEEN (1<<1) - -typedef struct _trie { - uint32_t flags; - struct _trie *next[26]; -} trie_t; - -typedef bool_t -(*trie_predicate_t) (trie_t *trie); - -#define TRIE_CHAR_TO_INDEX(c) (tolower (c) - 'a') -#define TRIE_INDEX_TO_CHAR(i) (i + 'a') - -trie_t * -trie_create (void); - -void -trie_add (trie_t *trie, - const char *word_chunk); - -trie_t * -trie_find (trie_t *trie, - const char *word_chunk); - -int -trie_print_seen (trie_t *trie, string_t *word); - -int -trie_print_unseen (trie_t *trie, string_t *word); - -typedef struct _dict { - trie_t *trie; -} dict_t; - +dict_add_word (dict_t *dict, + const char *word); void -dict_init (dict_t *dict, - const char *filename); +dict_add_words_from_file (dict_t *dict, + const char *filename); void dict_fini (dict_t *dict);