X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=dict-impl.h;fp=dict-impl.h;h=2c5514d17c8cf5fe9d6bb3b1e179f42f8a183166;hb=17755d5a91f1470057bf2308984a25e7432bcd8a;hp=0000000000000000000000000000000000000000;hpb=2eb18813b84ae8ad4faeb92b1d8570599135d537;p=wordgame diff --git a/dict-impl.h b/dict-impl.h new file mode 100644 index 0000000..2c5514d --- /dev/null +++ b/dict-impl.h @@ -0,0 +1,90 @@ +/* + * Copyright © 2006 Carl Worth + * + * This program is free software; you can redistribute it and\/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA." + */ + +#ifndef _DICT_IMPL_H_ +#define _DICT_IMPL_H_ + +#include + +#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; + +void +string_init (string_t *string); + +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); + +struct _dict { + trie_t *trie; +}; + +#endif /* _DICT_IMPL_H_ */