From 60671ccb47c39ae2febd6c39683b67e41feb410d Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 14 Dec 2022 20:44:36 -0800 Subject: [PATCH] Updated table to simplify iteration. Iterated. --- kjv/Makefile | 2 +- kjv/src/kjv.re_c.c | 12 ++++++++++ kjv/src/table.h | 59 ++++++++++++++++++++-------------------------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/kjv/Makefile b/kjv/Makefile index 13a5e89..b0059b7 100644 --- a/kjv/Makefile +++ b/kjv/Makefile @@ -74,7 +74,7 @@ gperf := gperf target := # -mwindows optimize := -ffast-math -warnbasic := -Wall -pedantic -ansi # -std=c99 +warnbasic := -Wall -pedantic #-ansi # -std=c99 # Some stuff is really new. warnclang := -Wextra \ -Weverything \ diff --git a/kjv/src/kjv.re_c.c b/kjv/src/kjv.re_c.c index ec11c97..cfef770 100644 --- a/kjv/src/kjv.re_c.c +++ b/kjv/src/kjv.re_c.c @@ -269,6 +269,7 @@ static void words_to_string(const union kjvcite x, char (*const a)[12]) #define TABLE_KEY union kjvcite #define TABLE_UINT uint32_t #define TABLE_VALUE unsigned +#define TABLE_DEFUALT 0 #define TABLE_INVERSE #define TABLE_TO_STRING #include "../src/table.h" @@ -338,6 +339,17 @@ int main(void) { printf("words: %s\n", words_table_to_string(&words)); printf("kjv: %zu words\n", cum_words); + { + union kjvcite c; + struct words_table_iterator it = words_table_begin(&words); + unsigned *w; + while(words_table_next(&it, &c, &w)) + printf("%s %u:%u -> %u\n", + kjv_book_string[c.book], c.chapter, c.verse, *w); + c.u32 = 0; /* Unnecessary? */ + c.book = Genesis, c.chapter = 1, c.verse = 1; + printf("%u\n", words_table_get_or(&words, c, 0)); /* Why not get? */ + } goto finally; catch: success = EXIT_FAILURE; diff --git a/kjv/src/table.h b/kjv/src/table.h index 2eb50fd..4673ea1 100644 --- a/kjv/src/table.h +++ b/kjv/src/table.h @@ -13,6 +13,8 @@ It must be supplied hash_fn> `hash` and, is_equal_fn> `is_equal` or unhash_fn> `unhash`. + (Fixme: remove entry as public struct, this should be entirely private.) + @param[TABLE_NAME, TABLE_KEY] `` that satisfies `C` naming conventions when mangled and a valid key> associated therewith; required. `` is private, whose @@ -607,40 +609,28 @@ static void N_(table_)(struct N_(table) *const table) static struct N_(table_iterator) N_(table_begin)(struct N_(table) *const table) { struct N_(table_iterator) it; it._ = PN_(iterator)(table); return it; } -/** Advances `it`. The awkwardness of this function because entry> - is not necessarily nullifyable, so we are not guaranteed to have an - out-of-band entry to indicate completion. (May be changed in the future.) - @param[entry] If non-null, the entry is filled with the next element only if - it has a next. @return Whether it had a next element. @allow */ +#ifdef TABLE_VALUE /* */ +#endif /* set --> */ /** Removes the entry at `it`. Whereas table_remove> invalidates the iterator, this corrects for a signal `it`. @return Success, or there was no entry at the iterator's position, (anymore.) @@ -825,14 +815,15 @@ static void PN_(unused_base)(void) { PN_(entry) e; PN_(key) k; PN_(value) v; memset(&e, 0, sizeof e); memset(&k, 0, sizeof k); memset(&v, 0, sizeof v); PN_(is_element)(0); - N_(table)(); N_(table_)(0); N_(table_begin)(0); N_(table_next)(0, 0); + N_(table)(); N_(table_)(0); N_(table_begin)(0); N_(table_buffer)(0, 0); N_(table_clear)(0); N_(table_is)(0, k); N_(table_query)(0, k, 0); N_(table_get_or)(0, k, v); N_(table_try)(0, e); N_(table_update)(0, e, 0); N_(table_policy)(0,e,0,0); - N_(table_remove)(0, k); N_(table_begin)(0); N_(table_next)(0, 0); - N_(table_has_next)(0); N_(table_iterator_remove)(0); + N_(table_remove)(0, k); N_(table_iterator_remove)(0); #ifdef TABLE_VALUE - N_(table_assign)(0, k, 0); N_(table_next_key)(0); N_(table_next_value)(0); + N_(table_next)(0, 0, 0); N_(table_assign)(0, k, 0); +#else + N_(table_next)(0, 0); #endif PN_(unused_base_coda)(); }