chiark / gitweb /
WIP routesearch; construct archipelago lookup table
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 7 Oct 2009 23:20:57 +0000 (00:20 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 7 Oct 2009 23:20:57 +0000 (00:20 +0100)
yarrg/rscommon.h
yarrg/rssearch.c
yarrg/x.gdb

index 873ff30810f708bf7282ebcdcc0f21c828dcb3b1..f0215b29c9559b49873eaed7f0a975b810090e33 100644 (file)
@@ -118,6 +118,10 @@ extern int max_dist;
 
 extern int islandtablesz;
 
+extern int narches;
+extern char **archnames;
+extern int *islandid2arch;
+
 
 #define ONDEMAND(pointer_lvalue, calloc_size_count)                         \
   ((pointer_lvalue) ? :                                                             \
index 0a17adfd8d79f564afcd1d98549baa8be541f341..fa43d8939d26a250c61c3108c9b30194d79c058a 100644 (file)
@@ -140,9 +140,43 @@ void search(int start_isle, PotentialResult ****strat_base_io) {
   recurse(start_isle,0,0,1e6);
 }
 
+
+int narches;
+char **archnames;
+int *islandid2arch;
+
 void setup_search(void) {
   neighbours= mcalloc(sizeof(*neighbours) * islandtablesz);
 
   SQL_PREPARE(ss_neigh,
              "SELECT biid, dist FROM routes WHERE aiid=?");
+
+  int max_narches=
+    sql_single_int(" SELECT count(*) FROM (\n"
+                  "  SELECT DISTINCT archipelago\n"
+                  "   FROM islands\n"
+                  "  )");
+  archnames= mcalloc(sizeof(*archnames) * max_narches);
+  islandid2arch= mmalloc(sizeof(*islandid2arch) * islandtablesz);
+  int i;
+  for (i=0; i<islandtablesz; i++) islandid2arch[i]=-1;
+
+  sqlite3_stmt *archs;
+  SQL_PREPARE(archs,
+             " SELECT islandid, archipelago\n"
+             "  FROM islands\n"
+             "  ORDER BY archipelago");
+  while (SQL_STEP(archs)) {
+    int isle= sqlite3_column_int(archs,0);
+    const char *archname= (const char*)sqlite3_column_text(archs,1);
+    int arch;
+    for (arch=0; arch<narches; arch++)
+      if (!strcmp(archnames[arch], archname)) goto found;
+    assert(narches < max_narches);
+    arch= narches++;
+    archnames[arch]= masprintf("%s",archname);
+  found:
+    islandid2arch[isle]= arch;
+  }
+  sqlite3_finalize(archs);
 }
index 06e18f8b0021441f73ccb72f05baac862652b4aa..42aaddc03ad9a3536c06597f6a3c8ce939e3bb68 100644 (file)
@@ -1,4 +1,5 @@
 file ./routesearch
-set args 13460 20210 -1 0.0005 search 20 7
-break ipair_get if si==7 && di==5
+set args -DN 13460 20210 -1 0.0005 search 10  4 19 134 32 13 24 36
+break setup_search
 run
+finish