2 * Copyright © 2006 Carl Worth
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)
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.
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."
22 /* Portably, schmortability. I want ease of programming. */
38 typedef struct _trie {
40 struct _trie *next[26];
43 typedef trie_t dict_t;
44 typedef trie_t *dict_cursor_t;
45 typedef uint32_t dict_entry_t;
47 /* Initialization and cleanup */
49 dict_init (dict_t *dict);
52 dict_fini (dict_t *dict);
54 /* Adding new words */
56 dict_add_word (dict_t *dict,
59 dict_add_words_from_file (dict_t *dict,
60 const char *filename);
62 /* Looking up an entry in the dictionary */
64 dict_lookup (dict_t *dict,
68 (*dict_entry_predicate_t) (dict_entry_t entry);
71 dict_count (dict_t *dict,
72 dict_entry_predicate_t predicate);
74 /* Querying a dictionary entry. The dict interface uses 1 bit.
75 * All of the remaining bits are available for application use.
77 #define DICT_ENTRY_FLAG_IS_WORD (1<<0)
79 #define DICT_ENTRY_IS_WORD(entry) ((entry) && ((*entry) & DICT_ENTRY_FLAG_IS_WORD))
81 /* Printing the dictionary */
83 dict_print (dict_t *dict);
86 dict_print_if (dict_t *dict,
87 dict_entry_predicate_t predicate);
90 dict_print_by_length_if (dict_t *dict,
91 dict_entry_predicate_t predicate);
93 /* Character-by-character perusal of the dictionary */
95 dict_root (dict_t *dict);
98 dict_cursor_next (dict_cursor_t cursor,
102 dict_cursor_resolve (dict_cursor_t cursor);
104 #define DICT_CURSOR_NIL NULL
106 #endif /* _DICT_H_ */