X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=dict.h;h=6152c724e303c8d4177a44ea0cb024c8c9a2e69e;hb=aa0ff4160f5b7311fca900d90b1436dbaebef70a;hp=ca0e6f6e9a209efe442a3ea8083e0d2480cc7e1b;hpb=6717cd95edcf1332c81daaa6c608c293dc8ffb4a;p=wordgame diff --git a/dict.h b/dict.h index ca0e6f6..6152c72 100644 --- a/dict.h +++ b/dict.h @@ -19,6 +19,10 @@ #ifndef _DICT_H_ #define _DICT_H_ +/* Portably, schmortability. I want ease of programming. */ +#define _GNU_SOURCE +#include +#include #include #ifndef FALSE @@ -70,12 +74,17 @@ dict_count (dict_t *dict, /* Querying a dictionary entry. The dict interface uses 1 bit. * All of the remaining bits are available for application use. */ -#define DICT_ENTRY_IS_WORD(entry) ((entry) && ((*entry) & 0x01)) +#define DICT_ENTRY_FLAG_IS_WORD (1<<0) + +#define DICT_ENTRY_IS_WORD(entry) ((entry) && ((*entry) & DICT_ENTRY_FLAG_IS_WORD)) /* Printing the dictionary */ int dict_print (dict_t *dict); +int +dict_print_by_length (dict_t *dict); + int dict_print_if (dict_t *dict, dict_entry_predicate_t predicate); @@ -84,6 +93,31 @@ int dict_print_by_length_if (dict_t *dict, dict_entry_predicate_t predicate); +/* More general callback-based iteration of all entries */ +typedef void (* dict_action_t) (void *closure, char *word); + +int +dict_for_each (dict_t *dict, + dict_action_t action, + void *closure); + +int +dict_for_each_by_length (dict_t *dict, + dict_action_t action, + void *closure); + +int +dict_for_each_if (dict_t *dict, + dict_action_t action, + void *closure, + dict_entry_predicate_t predicate); + +int +dict_for_each_by_length_if (dict_t *dict, + dict_action_t action, + void *closure, + dict_entry_predicate_t predicate); + /* Character-by-character perusal of the dictionary */ dict_cursor_t dict_root (dict_t *dict);