@@ -41,6 +41,7 @@ struct ramNode {
4141struct ramWay {
4242 struct keyval * tags ;
4343 int * ndids ;
44+ int pending ;
4445};
4546
4647struct ramRel {
@@ -75,9 +76,7 @@ static int node_blocks;
7576static int way_blocks ;
7677
7778static int way_out_count ;
78- #if 0
7979static int rel_out_count ;
80- #endif
8180
8281static inline int id2block (int id )
8382{
@@ -148,10 +147,7 @@ static int ram_ways_set(int id, int *nds, int nd_count, struct keyval *tags, int
148147 int block = id2block (id );
149148 int offset = id2offset (id );
150149 struct keyval * p ;
151-
152- if ( !pending ) /* If it's not still to be done, don't bother storing it at all */
153- return 0 ;
154-
150+
155151 if (!ways [block ]) {
156152 ways [block ] = calloc (PER_BLOCK , sizeof (struct ramWay ));
157153 if (!ways [block ]) {
@@ -171,6 +167,7 @@ static int ram_ways_set(int id, int *nds, int nd_count, struct keyval *tags, int
171167 ways [block ][offset ].ndids = malloc ( (nd_count + 1 )* sizeof (int ) );
172168 memcpy ( ways [block ][offset ].ndids + 1 , nds , nd_count * sizeof (int ) );
173169 ways [block ][offset ].ndids [0 ] = nd_count ;
170+ ways [block ][offset ].pending = pending ;
174171
175172 if (!ways [block ][offset ].tags ) {
176173 p = malloc (sizeof (struct keyval ));
@@ -184,8 +181,7 @@ static int ram_ways_set(int id, int *nds, int nd_count, struct keyval *tags, int
184181 } else
185182 resetList (ways [block ][offset ].tags );
186183
187- while ((p = popItem (tags )) != NULL )
188- pushItem (ways [block ][offset ].tags , p );
184+ cloneList (ways [block ][offset ].tags , tags );
189185
190186 return 0 ;
191187}
@@ -215,8 +211,7 @@ static int ram_relations_set(int id, struct member *members, int member_count, s
215211 } else
216212 resetList (rels [block ][offset ].tags );
217213
218- while ((p = popItem (tags )) != NULL )
219- pushItem (rels [block ][offset ].tags , p );
214+ cloneList (rels [block ][offset ].tags , tags );
220215
221216 if (!rels [block ][offset ].members )
222217 free ( rels [block ][offset ].members );
@@ -232,7 +227,6 @@ static int ram_relations_set(int id, struct member *members, int member_count, s
232227 }
233228
234229 return 0 ;
235- //return out_pgsql.relation(id, tags, nodes, ndCount)
236230}
237231
238232static int ram_nodes_get_list (struct osmNode * nodes , int * ndids , int nd_count )
@@ -250,9 +244,35 @@ static int ram_nodes_get_list(struct osmNode *nodes, int *ndids, int nd_count)
250244 return count ;
251245}
252246
253- static void ram_iterate_relations (int (* callback )(int id , struct member * members , int member_count , struct keyval * tags , int ) __unused )
247+ static void ram_iterate_relations (int (* callback )(int id , struct member * members , int member_count , struct keyval * tags , int ))
254248{
255- /* Void */
249+ int block , offset ;
250+
251+ fprintf (stderr , "\n" );
252+ for (block = NUM_BLOCKS - 1 ; block >=0 ; block -- ) {
253+ if (!rels [block ])
254+ continue ;
255+
256+ for (offset = 0 ; offset < PER_BLOCK ; offset ++ ) {
257+ if (rels [block ][offset ].members ) {
258+ int id = block2id (block , offset );
259+ rel_out_count ++ ;
260+ if (rel_out_count % 1000 == 0 )
261+ fprintf (stderr , "\rWriting rel(%uk)" , rel_out_count /1000 );
262+
263+ callback (id , rels [block ][offset ].members , rels [block ][offset ].member_count , rels [block ][offset ].tags , 0 );
264+ }
265+ free (rels [block ][offset ].members );
266+ rels [block ][offset ].members = NULL ;
267+ resetList (rels [block ][offset ].tags );
268+ free (rels [block ][offset ].tags );
269+ rels [block ][offset ].tags = NULL ;
270+ }
271+ free (rels [block ]);
272+ rels [block ] = NULL ;
273+ }
274+
275+ fprintf (stderr , "\rWriting rel(%uk)\n" , rel_out_count /1000 );
256276}
257277
258278static void ram_iterate_ways (int (* callback )(int id , struct keyval * tags , struct osmNode * nodes , int count , int exists ))
@@ -271,18 +291,18 @@ static void ram_iterate_ways(int (*callback)(int id, struct keyval *tags, struct
271291 if (way_out_count % 1000 == 0 )
272292 fprintf (stderr , "\rWriting way(%uk)" , way_out_count /1000 );
273293
274- if (ways [block ][offset ].tags )
275- if ( getItem ( ways [ block ][ offset ]. tags , "multipolygon" ) )
276- continue ;
277-
278- /* First element contains number of nodes */
279- nodes = malloc ( sizeof ( struct osmNode ) * ways [ block ][ offset ]. ndids [ 0 ]);
280- ndCount = ram_nodes_get_list ( nodes , ways [ block ][ offset ]. ndids + 1 , ways [ block ][ offset ]. ndids [ 0 ] );
281-
282- if (nodes ) {
283- int id = block2id ( block , offset );
284- callback ( id , ways [ block ][ offset ]. tags , nodes , ndCount , 0 );
285- free ( nodes ) ;
294+ if (ways [block ][offset ].pending ) {
295+ /* First element contains number of nodes */
296+ nodes = malloc ( sizeof ( struct osmNode ) * ways [ block ][ offset ]. ndids [ 0 ]) ;
297+ ndCount = ram_nodes_get_list ( nodes , ways [ block ][ offset ]. ndids + 1 , ways [ block ][ offset ]. ndids [ 0 ]);
298+
299+ if ( nodes ) {
300+ int id = block2id ( block , offset );
301+ callback ( id , ways [ block ][ offset ]. tags , nodes , ndCount , 0 );
302+ free (nodes );
303+ }
304+
305+ ways [ block ][ offset ]. pending = 0 ;
286306 }
287307
288308 if (ways [block ][offset ].tags ) {
@@ -324,17 +344,15 @@ static int ram_ways_get( int id, struct keyval *tags_ptr, struct osmNode **nodes
324344 return 1 ;
325345}
326346
327- // Makrs the way so that iterate ways skips it
347+ // Marks the way so that iterate ways skips it
328348static int ram_ways_done ( int id )
329349{
330350 int block = id2block (id ), offset = id2offset (id );
331351
332352 if (!ways [block ])
333353 return 1 ;
334354
335- if ( ways [block ][offset ].tags )
336- addItem ( ways [block ][offset ].tags , "multipolygon" , "1" , 1 );
337-
355+ ways [block ][offset ].pending = 0 ;
338356 return 0 ;
339357}
340358
@@ -394,10 +412,13 @@ struct middle_t mid_ram = {
394412// nodes_get: ram_nodes_get,
395413 nodes_get_list : ram_nodes_get_list ,
396414 ways_set : ram_ways_set ,
397- relations_set : ram_relations_set ,
398415 ways_get : ram_ways_get ,
399416 ways_done : ram_ways_done ,
400- // iterate_nodes: ram_iterate_nodes,
417+
418+ relations_set : ram_relations_set ,
419+
420+ // iterate_nodes: ram_iterate_nodes,
401421 iterate_ways : ram_iterate_ways ,
402422 iterate_relations : ram_iterate_relations
403423};
424+
0 commit comments