static GtkProgressBar *dbpw=NULL;
/* Cache hash tables */
-static GHashTable *place_cache;
+struct osm_place_cache {
+ GHashTable *cache;
+ guint hit;
+ guint miss;
+};
+static struct osm_place_cache pcache;
static guint way_dist_range=OSM_RANGE_WAY;
gboolean
osm_db_prepare(sqlite3 *db)
{
-/* Place */
/* Select nearest place inside lat,lon+-range */
if (sqlite3_prepare_v2(db, "select name,(($LAT-ilat)*($LAT-ilat))+(($LON-ilon)*($LON-ilon)) as dist,"
" ilat,ilon,places.nid,isin_p,isin_c "
void
osm_deinit(void)
{
-if (osmdb!=NULL) {
- sqlite3_finalize(sql.select_way_ref);
- sqlite3_finalize(sql.select_way_name);
- sqlite3_finalize(sql.select_way_next_seg);
- sqlite3_finalize(sql.select_way_prev_seg);
- sqlite3_finalize(sql.select_way_name_search);
- sqlite3_finalize(sql.select_way2);
- sqlite3_finalize(sql.select_place);
- sqlite3_finalize(sql.select_near_place);
+if (osmdb) {
+ if (sql.select_way_ref)
+ sqlite3_finalize(sql.select_way_ref);
+ if (sql.select_way_name)
+ sqlite3_finalize(sql.select_way_name);
+ if (sql.select_way_next_seg)
+ sqlite3_finalize(sql.select_way_next_seg);
+ if (sql.select_way_prev_seg)
+ sqlite3_finalize(sql.select_way_prev_seg);
+ if (sql.select_way_name_search)
+ sqlite3_finalize(sql.select_way_name_search);
+ if (sql.select_way2)
+ sqlite3_finalize(sql.select_way2);
+ if (sql.select_place)
+ sqlite3_finalize(sql.select_place);
+ if (sql.select_near_place)
+ sqlite3_finalize(sql.select_near_place);
+ if (sql.select_node_next)
+ sqlite3_finalize(sql.select_node_next);
+ if (sql.select_node_prev)
+ sqlite3_finalize(sql.select_node_prev);
}
osmdb=NULL;
osm_db_ok=FALSE;
-g_hash_table_destroy(place_cache);
+memset(&sql, 0, sizeof(sql));
+g_hash_table_destroy(pcache.cache);
+pcache.hit=0;
+pcache.miss=0;
g_timer_destroy(dbt);
}
osm_init(sqlite3 **db)
{
osm_db_ok=FALSE;
-place_cache=g_hash_table_new(g_direct_hash, g_direct_equal);
+pcache.cache=g_hash_table_new(g_direct_hash, g_direct_equal);
dbt=g_timer_new();
if (!db || !*db) {
}
osmdb=*db;
+memset(&sql, 0, sizeof(sql));
if (osm_db_prepare(osmdb)==FALSE) {
g_printerr("Failed to prepare OSM SQL statements:");
g_printf("SQLITE: %s\n", sqlite3_errmsg(osmdb));
static osm_place *
osm_place_cache_lookup(guint32 id)
{
-return g_hash_table_lookup(place_cache, GINT_TO_POINTER(id));
+osm_place *r;
+r=g_hash_table_lookup(pcache.cache, GINT_TO_POINTER(id));
+if (r)
+ pcache.hit++;
+else
+ pcache.miss++;
+
+g_debug("OSM: Cache %d/%d", pcache.hit, pcache.miss);
+return r;
}
static void
osm_place_cache_add(osm_place *p)
{
if (osm_place_cache_lookup(p->id)==NULL)
- g_hash_table_insert(place_cache, GINT_TO_POINTER(p->id), p);
+ g_hash_table_insert(pcache.cache, GINT_TO_POINTER(p->id), p);
}
static void
osm_place_cache_gc(void)
{
-gint r;
-r=g_hash_table_foreach_remove(place_cache, osm_place_remove, NULL);
+guint r;
+
+r=g_hash_table_foreach_remove(pcache.cache, osm_place_remove, NULL);
+g_debug("OSM: Cache cleared (%d)", r);
+pcache.hit=0;
+pcache.miss=0;
}
static void
n=*nr;
n=osm_place_cache_lookup(id);
if (n) {
- g_print("*P!\n");
osm_place_update_distance(n, lat, lon);
return TRUE;
}
n=NULL;
/* XXX: better place for this */
-if (g_hash_table_size(place_cache)>OSM_PLACE_CACHE_MAX_ITEMS)
+if (g_hash_table_size(pcache.cache)>OSM_PLACE_CACHE_MAX_ITEMS)
osm_place_cache_gc();
sqlite3_clear_bindings(sql.select_place);