From eb328d6c47b7bee8aad03c6c7a2be19a7f4aa7eb Mon Sep 17 00:00:00 2001 From: steffen Date: Tue, 23 Jul 2013 21:07:21 +0000 Subject: [PATCH] speeding up things.. --- ChangeLog | 4 ++++ mapsys/map.h | 2 ++ mapsys/map_area.c | 21 +++++++++++++++++++++ mapsys/map_hash.c | 4 ++-- mapsys/map_way.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b215703..a57bb51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ Version 0.0.2: name changed to spOSMroute, since on there had been another OSMroute already. ============================================================================= +(2013-07-23): +- added map_way_append_to_hash and map_area_append_to_hash to speedup + map_hash_realloc, which took most almost 30% of all time. + (2013-07-19): - speeding up converting process. diff --git a/mapsys/map.h b/mapsys/map.h index 7fef18e..e82d024 100644 --- a/mapsys/map.h +++ b/mapsys/map.h @@ -376,6 +376,7 @@ extern struct map_way *map_way_find (struct map_hash *mh, unsigned long long int extern void map_way_copy (struct map_way *dest, struct map_way *src); extern int map_way_add (struct map_way *way, int loadflags); extern int map_way_add_to_hash (struct map_hash *mh, struct map_way *mw); +extern int map_way_append_to_hash (struct map_hash *mh, struct map_way *mw); extern int map_way_getsize (struct map_way *way); extern int map_way_findclosest (struct map_pos *pos, struct map_pos *waypos, int idh, char *name, int namelen, unsigned long long int *closest_id, unsigned short int *closest_sid); extern float map_way_getdistance (struct map_way *mw, struct map_pos *pos, struct map_pos *waypos); @@ -390,6 +391,7 @@ extern struct map_area *map_area_find (struct map_hash *mh, unsigned long long i extern void map_area_copy (struct map_area *dest, struct map_area *src); extern int map_area_add (struct map_area *area, int loadflags); extern int map_area_add_to_hash (struct map_hash *mh, struct map_area *ma); +extern int map_area_append_to_hash (struct map_hash *mh, struct map_area *ma); extern int map_area_getsize (struct map_area *area); diff --git a/mapsys/map_area.c b/mapsys/map_area.c index 66a865d..5048b1d 100644 --- a/mapsys/map_area.c +++ b/mapsys/map_area.c @@ -33,6 +33,27 @@ */ /* + * add the area without checking for it's size, also no update is done + */ +int map_area_append_to_hash (struct map_hash *mh, struct map_area *ma) { + int size; + struct map_area *a = mh->areas; + + mh->areas = (struct map_area*) map_hash_getfree_aligned (mh, POINTERALIGNMENT); + + /* copy the area data to the free entry + * calc size and set free entry to it's new place */ + size = map_area_getsize (ma); + map_area_copy (mh->areas, ma); + mh->areas->next = a; + mh->free = mh->free + size; + mh->areascnt++; + SETFLAG(mh->status, MS_changed); + + return 1; +}; + +/* * add the area without checking for it's size, but do an update */ int map_area_add_to_hash (struct map_hash *mh, struct map_area *ma) { diff --git a/mapsys/map_hash.c b/mapsys/map_hash.c index 3c69774..fb7de83 100644 --- a/mapsys/map_hash.c +++ b/mapsys/map_hash.c @@ -208,7 +208,7 @@ void map_hash_copy (struct map_hash *hd, struct map_hash *hs) { i = 0; mw = hs->ways; while (mw && i < hs->wayscnt) { - map_way_add_to_hash (hd, mw); + map_way_append_to_hash (hd, mw); mw = mw->next; i++; } @@ -220,7 +220,7 @@ void map_hash_copy (struct map_hash *hd, struct map_hash *hs) { ma = hs->areas; i = 0; while (ma && i < hs->areascnt) { - map_area_add_to_hash (hd, ma); + map_area_append_to_hash (hd, ma); ma = ma->next; i++; } diff --git a/mapsys/map_way.c b/mapsys/map_way.c index d99da8a..d1dd24f 100644 --- a/mapsys/map_way.c +++ b/mapsys/map_way.c @@ -88,6 +88,36 @@ int map_way_add_to_hash (struct map_hash *mh, struct map_way *mw) { }; +/* + * append the way without checking for it's size or double entry, no update done + */ +int map_way_append_to_hash (struct map_hash *mh, struct map_way *mw) { + int size; + struct map_way *w = mh->ways; + + /* check if the hash pos and the waypos are valid */ + if (mw->p_cnt > 0) if (map_geo2igeo (mw->p[0].lon) != mh->pos.ilon || + map_geo2igeo (mw->p[0].lat) != mh->pos.ilat) { + d_printf ("p[0]:%d,%d mhpos:%d,%d way does not bleong to hash.", __FUNCTION__, map_geo2igeo (mw->p[0].lon), map_geo2igeo (mw->p[0].lat), mh->pos.ilon, mh->pos.ilat); + errorexit (-1); + } + + /* check if the first element is already the one we want to update */ + mh->ways = (struct map_way*) map_hash_getfree_aligned (mh, POINTERALIGNMENT); + + /* copy the way data to the free entry + * calc size and set free entry to it's new place */ + size = map_way_getsize (mw); + map_way_copy (mh->ways, mw); + mh->ways->next = w; + mh->free = mh->free + size; + mh->wayscnt++; + SETFLAG(mh->status, MS_changed); + + return 1; +}; + + /****************************************************************************** * Add/Update way information * - load/ get hash table