Enforced one day per score.
This commit is contained in:
parent
7e8983ef66
commit
6d96736fad
@ -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
|
||||
|
@ -4,20 +4,14 @@
|
||||
Scan journal entries for score. */
|
||||
|
||||
#if 0
|
||||
#include "../src/journal.h"
|
||||
#include "../src/scan_score.h"
|
||||
#include <inttypes.h> /* C99 */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#include "../src/journal.h"
|
||||
#include "../src/scores.h"
|
||||
#include <stdio.h>
|
||||
//#include <string.h>
|
||||
//#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
@ -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 <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
10
src/tree.h
10
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 --><!-- set */
|
||||
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) {
|
||||
#endif
|
||||
struct PB_(node) *node = 0, *head = 0; /* The original and new. */
|
||||
@ -697,7 +697,7 @@ catch: /* Didn't work. Reset. */
|
||||
#endif
|
||||
|
||||
/** Distributes `tree` (can be null) on the right side so that, after a series
|
||||
of <fn:<B>tree_bulk_add>, it will be consistent with the minimum number of
|
||||
of <fn:<B>tree_bulk_try>, it will be consistent with the minimum number of
|
||||
keys in a node. @return The re-distribution was a success and all nodes are
|
||||
within rules. (Only when intermixing bulk and regular operations, can the
|
||||
function return false.) @order \O(\log |`tree`|) @allow */
|
||||
@ -1565,10 +1565,10 @@ static void PB_(unused_base)(void) {
|
||||
B_(tree_less_or)(0, k, k); B_(tree_more_or)(0, k, k);
|
||||
B_(tree_next)(0); B_(tree_has_element)(0);
|
||||
#ifdef TREE_VALUE
|
||||
B_(tree_bulk_add)(0, k, 0); B_(tree_try)(0, k, 0);
|
||||
B_(tree_bulk_try)(0, k, 0); B_(tree_try)(0, k, 0);
|
||||
B_(tree_assign)(0, k, 0, 0); B_(tree_value)(0);
|
||||
#else
|
||||
B_(tree_bulk_add)(0, k); B_(tree_try)(0, k);
|
||||
B_(tree_bulk_try)(0, k); B_(tree_try)(0, k);
|
||||
B_(tree_assign)(0, k, 0);
|
||||
#endif
|
||||
B_(tree_bulk_finish)(0); B_(tree_remove)(0, k); B_(tree_clone)(0, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user