place_table is not enough; need tree

This commit is contained in:
Neil 2023-04-30 02:28:15 -07:00
parent 6866fab753
commit a07c9c5811
4 changed files with 32 additions and 6 deletions

View File

@ -118,7 +118,7 @@ int pair_to_date(const char *a, union date32 *const d) {
}
/** @return A djb2 <http://www.cse.yorku.ca/~oz/hash.html> 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++;

View File

@ -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

View File

@ -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;

View File

@ -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. */