]> git.cworth.org Git - wordgame/blob - dict.h
Add printing to dict interface. Breakup grid prints by letter count.
[wordgame] / dict.h
1 /*
2  * Copyright © 2006 Carl Worth
3  *
4  * This program is free software; you can redistribute it and\/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
17  */
18
19 #ifndef _DICT_H_
20 #define _DICT_H_
21
22 #include "dict-impl.h"
23
24 /* Only looks opaque. Perfectly stack-allocatable */
25 typedef trie_t dict_t;
26 typedef trie_t *dict_cursor_t;
27 typedef uint32_t dict_entry_t;
28
29 /* Initialization and cleanup */
30 void
31 dict_init (dict_t *dict);
32
33 void
34 dict_fini (dict_t *dict);
35
36 /* Adding new words */
37 void
38 dict_add_word (dict_t           *dict,
39                const char       *word);
40 void
41 dict_add_words_from_file (dict_t        *dict,
42                           const char    *filename);
43
44 /* Looking up an entry in the dictionary */
45 dict_entry_t *
46 dict_lookup (dict_t     *dict,
47              const char *word);
48
49 typedef bool_t
50 (*dict_entry_predicate_t) (dict_entry_t entry);
51
52 int
53 dict_count (dict_t                      *dict,
54             dict_entry_predicate_t      predicate);
55
56 /* Querying a dictionary entry. The dict interface uses 1 bit.
57  * All of the remaining bits are available for application use.
58  */
59 #define DICT_ENTRY_IS_WORD(entry) ((entry) && ((*entry) & 0x01))
60
61 /* Printing the dictionary */
62 int
63 dict_print (dict_t *dict);
64
65 int
66 dict_print_if (dict_t                   *dict,
67                dict_entry_predicate_t    predicate);
68
69 int
70 dict_print_by_length_if (dict_t                 *dict,
71                          dict_entry_predicate_t  predicate);
72
73 /* Character-by-character perusal of the dictionary */
74 dict_cursor_t
75 dict_root (dict_t *dict);
76
77 dict_cursor_t
78 dict_cursor_next (dict_cursor_t cursor,
79                   char          next);
80
81 dict_entry_t *
82 dict_cursor_resolve (dict_cursor_t cursor);
83
84 #define DICT_CURSOR_NIL NULL
85
86 #endif /* _DICT_H_ */