]> git.cworth.org Git - wordgame/blobdiff - dict.h
grid: Don't consider 2-letter words as valid.
[wordgame] / dict.h
diff --git a/dict.h b/dict.h
index 16a345cf0a7f970f78799be533a539f2c37a688b..af21015650d906b7e7e9e0c2de6f86c6f4329d7c 100644 (file)
--- a/dict.h
+++ b/dict.h
 #ifndef _DICT_H_
 #define _DICT_H_
 
-#include "dict-impl.h"
+/* Portably, schmortability. I want ease of programming. */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
 
-/* Only looks opaque. Perfectly stack-allocatable */
-typedef struct _dict dict_t;
+#ifndef FALSE
+# define FALSE 0
+#endif
 
+#ifndef TRUE
+# define TRUE 1
+#endif
+
+typedef int bool_t;
+
+typedef struct _trie {
+    uint32_t flags;
+    struct _trie *next[26];
+} trie_t;
+
+typedef trie_t dict_t;
+typedef trie_t *dict_cursor_t;
+typedef uint32_t dict_entry_t;
+
+/* Initialization and cleanup */
 void
 dict_init (dict_t *dict);
 
+void
+dict_fini (dict_t *dict);
+
+/* Adding new words */
 void
 dict_add_word (dict_t          *dict,
               const char       *word);
@@ -34,7 +59,48 @@ void
 dict_add_words_from_file (dict_t       *dict,
                          const char    *filename);
 
-void
-dict_fini (dict_t *dict);
+/* Looking up an entry in the dictionary */
+dict_entry_t *
+dict_lookup (dict_t    *dict,
+            const char *word);
+
+typedef bool_t
+(*dict_entry_predicate_t) (dict_entry_t entry);
+
+int
+dict_count (dict_t                     *dict,
+           dict_entry_predicate_t      predicate);
+
+/* Querying a dictionary entry. The dict interface uses 1 bit.
+ * All of the remaining bits are available for application use.
+ */
+#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_if (dict_t                  *dict,
+              dict_entry_predicate_t    predicate);
+
+int
+dict_print_by_length_if (dict_t                        *dict,
+                        dict_entry_predicate_t  predicate);
+
+/* Character-by-character perusal of the dictionary */
+dict_cursor_t
+dict_root (dict_t *dict);
+
+dict_cursor_t
+dict_cursor_next (dict_cursor_t cursor,
+                 char          next);
+
+dict_entry_t *
+dict_cursor_resolve (dict_cursor_t cursor);
+
+#define DICT_CURSOR_NIL NULL
 
 #endif /* _DICT_H_ */