diff --git a/src/scores.h b/src/scores.h index 4a2210d..5e0e061 100644 --- a/src/scores.h +++ b/src/scores.h @@ -1,6 +1,10 @@ #include "pair.h" /* pair */ #include "journal.h" /* size_t, date32, line64 */ -struct score { struct pair key, name; union date32 date; unsigned edges; }; +struct score { + struct pair key, name; + union date32 date, last; + unsigned edges; +}; #define ARRAY_NAME scorelist #define ARRAY_TYPE struct score diff --git a/src/scores.re.c b/src/scores.re.c index 54c0e38..39c2b70 100644 --- a/src/scores.re.c +++ b/src/scores.re.c @@ -4,20 +4,14 @@ Scan journal entries for score. */ #if 0 -#include "../src/journal.h" -#include "../src/scan_score.h" #include /* C99 */ #include -#include -#include #include #endif #include "../src/journal.h" #include "../src/scores.h" #include -//#include -//#include #include @@ -100,9 +94,11 @@ static int scan(union date32 date, const char *const buffer, { errno = ERANGE; why = "too many lines of text"; goto catch; } if(!(idx = pair_map_table_get(&scores->map, keyword))) { why = "keyword not introduced"; goto catch; } - /* fixme: bulk */ - switch(score_tree_try(&scores->dates, key, &pidx)) { - case TREE_PRESENT: why = "duplicate key"; /* _Sic_. */ + if(scores->list.data[idx].last.u32 >= date.u32) + { why = "duplicate key in same day"; goto catch; } + scores->list.data[idx].last.u32 = date.u32; + switch(score_tree_bulk_try(&scores->dates, key, &pidx)) { + case TREE_PRESENT: assert(0); why = "duplicate key"; /* _Sic_. */ case TREE_ERROR: goto catch; case TREE_ABSENT: *pidx = idx; break; } @@ -123,7 +119,7 @@ static int scan(union date32 date, const char *const buffer, /*struct pair key, name; union date32 date; unsigned edges;*/ score->key.a = s0, score->key.b = s1; score->name.a = 0, score->name.b = 0; - score->date.u32 = 0; + score->date.u32 = score->last.u32 = 0; score->edges = 0; date32_to_string(date, &datestr); fprintf(stderr, "%s: new score <%.*s> stored in list at %zu.\n", @@ -197,6 +193,8 @@ finally: int scores_is_empty(const struct scores *const s) { return !s || !s->dates.root.node; } +#include + int main(void) { struct journal j = journal(); if(journal_is_empty(&j)) goto catch; @@ -204,7 +202,8 @@ int main(void) { if(scores_is_empty(&s)) goto catch; goto finally; catch: - scores_(&s); + perror("score"); finally: + scores_(&s); return EXIT_SUCCESS; } diff --git a/src/tree.h b/src/tree.h index fffdbc5..e36254a 100644 --- a/src/tree.h +++ b/src/tree.h @@ -593,10 +593,10 @@ static PB_(key) B_(tree_more_or)(const struct B_(tree) *const tree, `TREE_ABSENT`, added, the `value` (if applicable) is uninitialized. @throws[EDOM] `x` is smaller than the largest key in `tree`. @throws[malloc] @order \O(\log |`tree`|) @allow */ -static enum tree_result B_(tree_bulk_add)(struct B_(tree) *const tree, +static enum tree_result B_(tree_bulk_try)(struct B_(tree) *const tree, PB_(key) key, PB_(value) **const value) { #else /* map -->