X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=dict.h;h=622165195daf12151776f2cec9316f0aa35106b8;hb=0a8d1f741a919c9c7e5ae0b8d0261759cca9bc05;hp=d5aa1cd529ad8fad71a21658811c3e40177e9305;hpb=54a35ad5a96cc57816a9e05ab9d1e1513c202894;p=wordgame diff --git a/dict.h b/dict.h index d5aa1cd..6221651 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 @@ -64,8 +68,11 @@ typedef bool_t (*dict_entry_predicate_t) (dict_entry_t entry); int -dict_count (dict_t *dict, - dict_entry_predicate_t predicate); +dict_count_if (dict_t *dict, + dict_entry_predicate_t predicate); + +int +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. @@ -78,14 +85,54 @@ dict_count (dict_t *dict, int dict_print (dict_t *dict); +int +dict_print_of_length (dict_t *dict, + int min_length, + int max_length); + int dict_print_if (dict_t *dict, dict_entry_predicate_t predicate); +int +dict_print_of_length_if (dict_t *dict, + int min_length, + int max_length, + dict_entry_predicate_t predicate); + 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, dict_entry_t *entry); + +int +dict_for_each (dict_t *dict, + dict_action_t action, + void *closure); + +int +dict_for_each_of_length (dict_t *dict, + dict_action_t action, + void *closure, + int min_length, + int max_length); + +int +dict_for_each_if (dict_t *dict, + dict_action_t action, + void *closure, + dict_entry_predicate_t predicate); + +int +dict_for_each_of_length_if (dict_t *dict, + dict_action_t action, + void *closure, + int min_length, + int max_length, + dict_entry_predicate_t predicate); + /* Character-by-character perusal of the dictionary */ dict_cursor_t dict_root (dict_t *dict);