]> git.cworth.org Git - wordgame/blob - dict.h
Move private portions of dict from dict-impl.h back to dict.c
[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 <stdint.h>
23
24 #ifndef FALSE
25 # define FALSE 0
26 #endif
27
28 #ifndef TRUE
29 # define TRUE 1
30 #endif
31
32 typedef int bool_t;
33
34 typedef struct _trie {
35     uint32_t flags;
36     struct _trie *next[26];
37 } trie_t;
38
39 typedef trie_t dict_t;
40 typedef trie_t *dict_cursor_t;
41 typedef uint32_t dict_entry_t;
42
43 /* Initialization and cleanup */
44 void
45 dict_init (dict_t *dict);
46
47 void
48 dict_fini (dict_t *dict);
49
50 /* Adding new words */
51 void
52 dict_add_word (dict_t           *dict,
53                const char       *word);
54 void
55 dict_add_words_from_file (dict_t        *dict,
56                           const char    *filename);
57
58 /* Looking up an entry in the dictionary */
59 dict_entry_t *
60 dict_lookup (dict_t     *dict,
61              const char *word);
62
63 typedef bool_t
64 (*dict_entry_predicate_t) (dict_entry_t entry);
65
66 int
67 dict_count (dict_t                      *dict,
68             dict_entry_predicate_t      predicate);
69
70 /* Querying a dictionary entry. The dict interface uses 1 bit.
71  * All of the remaining bits are available for application use.
72  */
73 #define DICT_ENTRY_IS_WORD(entry) ((entry) && ((*entry) & 0x01))
74
75 /* Printing the dictionary */
76 int
77 dict_print (dict_t *dict);
78
79 int
80 dict_print_if (dict_t                   *dict,
81                dict_entry_predicate_t    predicate);
82
83 int
84 dict_print_by_length_if (dict_t                 *dict,
85                          dict_entry_predicate_t  predicate);
86
87 /* Character-by-character perusal of the dictionary */
88 dict_cursor_t
89 dict_root (dict_t *dict);
90
91 dict_cursor_t
92 dict_cursor_next (dict_cursor_t cursor,
93                   char          next);
94
95 dict_entry_t *
96 dict_cursor_resolve (dict_cursor_t cursor);
97
98 #define DICT_CURSOR_NIL NULL
99
100 #endif /* _DICT_H_ */