From a07c9c58111720df1216a822c4aec36aa069d9e7 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 30 Apr 2023 02:28:15 -0700 Subject: [PATCH] place_table is not enough; need tree --- src/pair.c | 2 +- src/pair.h | 3 ++- src/scan.h | 14 ++++++++++---- src/scan.re.c | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/pair.c b/src/pair.c index b0da5e1..14df279 100644 --- a/src/pair.c +++ b/src/pair.c @@ -118,7 +118,7 @@ int pair_to_date(const char *a, union date32 *const d) { } /** @return A djb2 hash of `p`. */ -static uint32_t pair_djb2(struct pair p) { +uint32_t pair_djb2(struct pair p) { uint32_t hash = 5381, c; while(p.a < p.b) { c = (unsigned char)*p.a++; diff --git a/src/pair.h b/src/pair.h index 21eef23..3565357 100644 --- a/src/pair.h +++ b/src/pair.h @@ -14,7 +14,8 @@ int pair_hours_to_minutes(const char *h0, const char *const h1, int pair_is_equal(struct pair, struct pair); int pair_is_string(struct pair, const char *); #include "journal.h" /* date32 */ -int pair_to_date(const char *a, union date32 *const d); +int pair_to_date(const char *, union date32 *); +uint32_t pair_djb2(struct pair); /* Supporting pair -> size_t for looking up in arrays. */ #define TABLE_NAME pairmap diff --git a/src/scan.h b/src/scan.h index 8f83687..ccaca4e 100644 --- a/src/scan.h +++ b/src/scan.h @@ -15,6 +15,15 @@ struct source { struct pair name, desc; }; #define ARRAY_HEAD #include "../src/array.h" +/* Place table. */ +struct place { double x, y; }; +#define TABLE_NAME place +#define TABLE_KEY struct pair +#define TABLE_VALUE struct place +#define TABLE_UINT uint32_t +#define TABLE_HEAD +#include "../src/table.h" + /* Score array. */ struct score { struct pair key, name; @@ -27,10 +36,6 @@ struct score { #include "../src/array.h" -//////// fixme: place - - - /* Glider array. */ #define LAUNCH_TYPE \ X(MotorCarTow),\ @@ -88,6 +93,7 @@ struct scan { struct pairmap_table map; struct linemap_tree dates; } scores; + struct place_table places; struct glider_tree gliders; struct flight_tree flights; struct kjv_tree kjvs; diff --git a/src/scan.re.c b/src/scan.re.c index f8f05e0..2d954bd 100644 --- a/src/scan.re.c +++ b/src/scan.re.c @@ -23,6 +23,18 @@ static int linemap_compare(const union line64 a, const union line64 b) #define TREE_BODY #include "../src/tree.h" +/* Looking up places with labels. */ +static int place_is_equal(const struct pair a, const struct pair b) + { return pair_is_equal(a, b); } +static uint32_t place_hash(const struct pair a) + { return pair_djb2(a); } +#define TABLE_NAME place +#define TABLE_KEY struct pair +#define TABLE_VALUE struct place +#define TABLE_UINT uint32_t +#define TABLE_BODY +#include "../src/table.h" + /* Array of sources. */ static void source_to_string(const struct source *const s, char (*const z)[12]) { @@ -557,9 +569,16 @@ catch: void scan_(struct scan *const scan) { if(!scan) return; + kjv_tree_(&scan->kjvs); + flight_tree_(&scan->flights); + glider_tree_(&scan->gliders); + place_table_(&scan->places); linemap_tree_(&scan->scores.dates); pair_map_table_(&scan->scores.map); score_array_(&scan->scores.array); + linemap_tree_(&scan->sources.dates); + pair_map_table_(&scan->sources.map); + source_array_(&scan->sources.array); } /** @param[jrnl] Must be constant throughout the use of the returned value. */