]> git.cworth.org Git - wordgame/blob - dict-impl.h
Add printing to dict interface. Breakup grid prints by letter count.
[wordgame] / dict-impl.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_IMPL_H_
20 #define _DICT_IMPL_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 _string {
35     size_t size;
36     char *s;
37     size_t len;
38 } string_t;
39
40 void
41 string_init (string_t *string);
42
43 void
44 string_fini (string_t *string);
45
46 void
47 string_append_char (string_t *string, char c);
48
49 void
50 string_chop (string_t *string);
51
52 void
53 chomp (char *s);
54
55 #define TRIE_FLAGS_IS_WORD      (1<<0)
56
57 typedef struct _trie {
58     uint32_t flags;
59     struct _trie *next[26];
60 } trie_t;
61
62 typedef bool_t
63 (*trie_predicate_t) (trie_t *trie);
64
65 #define TRIE_CHAR_TO_INDEX(c)   (tolower (c) - 'a')
66 #define TRIE_INDEX_TO_CHAR(i)   (i + 'a')
67
68 trie_t *
69 trie_create (void);
70
71 void
72 trie_add (trie_t        *trie,
73           const char    *word_chunk);
74
75 trie_t *
76 trie_find (trie_t       *trie,
77            const char   *word_chunk);
78
79 #endif /* _DICT_IMPL_H_ */