… | |
… | |
108 | g_hash_table_insert(member_hash, memb, g_list_append(g_hash_table_lookup(member_hash, memb), memb)); |
108 | g_hash_table_insert(member_hash, memb, g_list_append(g_hash_table_lookup(member_hash, memb), memb)); |
109 | } |
109 | } |
110 | |
110 | |
111 | void relations_process(struct relations *rel, FILE *nodes, FILE *ways, FILE *relations) |
111 | void relations_process(struct relations *rel, FILE *nodes, FILE *ways, FILE *relations) |
112 | { |
112 | { |
113 | char buffer[128]; |
113 | // char buffer_rel1[128]; |
|
|
114 | char *buffer_rel1 = g_malloc0(MAX_ITEMBIN_BYTES_); |
114 | struct item_bin *ib = (struct item_bin *) buffer; |
115 | struct item_bin *ib = (struct item_bin *) buffer_rel1; |
115 | long long *id; |
116 | long long *id; |
116 | struct coord *c = (struct coord *) (ib + 1), cn = |
117 | struct coord *c = (struct coord *) (ib + 1), cn = { 0, 0 }; |
117 | { 0, 0 }; |
|
|
118 | struct node_item *ni; |
118 | struct node_item *ni; |
119 | GList *l; |
119 | GList *l; |
120 | |
120 | |
121 | time_t start_tt, end_tt; |
121 | time_t start_tt, end_tt; |
122 | double diff_tt; |
122 | double diff_tt; |
… | |
… | |
124 | long long size_in; |
124 | long long size_in; |
125 | long long pos_in; |
125 | long long pos_in; |
126 | int _c = 0; |
126 | int _c = 0; |
127 | int _e = 8000000; |
127 | int _e = 8000000; |
128 | |
128 | |
129 | //fprintf(stderr,"relations_process:001\n"); |
129 | //fprintf_(stderr,"relations_process:001\n"); |
130 | |
130 | |
131 | if (nodes) |
131 | if (nodes) |
132 | { |
132 | { |
133 | //fprintf(stderr,"relations_process:002 nodes\n"); |
|
|
134 | |
|
|
135 | long long pos_now = (long long)ftello(nodes); // 64bit |
133 | long long pos_now = (long long)ftello(nodes); // 64bit |
136 | fseeko(nodes, 0, SEEK_END); |
134 | fseeko(nodes, 0, SEEK_END); |
137 | size_in = (long long)ftello(nodes); // 64bit |
135 | size_in = (long long)ftello(nodes); // 64bit |
138 | fprintf(stderr, "relations_process: pos nodes file=%lld\n", pos_now); |
136 | fprintf_(stderr, "relations_process: pos nodes file=%lld\n", pos_now); |
139 | fprintf(stderr, "relations_process:size nodes file=%lld\n", size_in); |
137 | fprintf_(stderr, "relations_process:size nodes file=%lld\n", size_in); |
140 | // seek to start of file |
138 | // seek to start of file |
141 | fseeko(nodes, 0, SEEK_SET); |
139 | fseeko(nodes, 0, SEEK_SET); |
142 | // reset timer |
140 | // reset timer |
143 | diff2_tt = 0; |
141 | diff2_tt = 0; |
144 | _c = 0; |
142 | _c = 0; |
… | |
… | |
146 | |
144 | |
147 | item_bin_init(ib, type_point_unkn); |
145 | item_bin_init(ib, type_point_unkn); |
148 | item_bin_add_coord(ib, &cn, 1); |
146 | item_bin_add_coord(ib, &cn, 1); |
149 | item_bin_add_attr_longlong(ib, attr_osm_nodeid, 0); |
147 | item_bin_add_attr_longlong(ib, attr_osm_nodeid, 0); |
150 | id = item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
148 | id = item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
|
|
149 | |
151 | while ((ni = read_node_item(nodes, 0))) |
150 | while ((ni = read_node_item(nodes, 0))) |
152 | { |
151 | { |
153 | _c++; |
152 | _c++; |
154 | |
153 | |
155 | *id = ni->id; |
154 | *id = ni->id; |
156 | *c = ni->c; |
155 | *c = ni->c; |
|
|
156 | |
157 | l = g_hash_table_lookup(rel->member_hash[0], id); |
157 | l = g_hash_table_lookup(rel->member_hash[0], id); |
158 | while (l) |
158 | while (l) |
159 | { |
159 | { |
160 | struct relations_member *memb = l->data; |
160 | struct relations_member *memb = l->data; |
161 | memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv); |
161 | memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv); |
… | |
… | |
173 | char outstring2[200]; |
173 | char outstring2[200]; |
174 | char outstring3[200]; |
174 | char outstring3[200]; |
175 | convert_to_human_time(diff_tt, outstring); |
175 | convert_to_human_time(diff_tt, outstring); |
176 | convert_to_human_bytes(pos_in, outstring2); |
176 | convert_to_human_bytes(pos_in, outstring2); |
177 | convert_to_human_bytes(size_in, outstring3); |
177 | convert_to_human_bytes(size_in, outstring3); |
178 | fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-NODES: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3); |
178 | fprintf_(stderr, "-RUNTIME-LOOP-REL-PROC-NODES: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3); |
179 | if (pos_in > 0) |
179 | if (pos_in > 0) |
180 | { |
180 | { |
181 | double eta_time = (diff_tt / pos_in) * (size_in - pos_in); |
181 | double eta_time = (diff_tt / pos_in) * (size_in - pos_in); |
182 | convert_to_human_time(eta_time, outstring); |
182 | convert_to_human_time(eta_time, outstring); |
183 | fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-NODES: %s left\n", outstring); |
183 | fprintf_(stderr, "-RUNTIME-LOOP-REL-PROC-NODES: %s left\n", outstring); |
184 | } |
184 | } |
185 | } |
185 | } |
186 | } |
186 | } |
187 | } |
187 | } |
188 | |
188 | |
189 | //fprintf(stderr,"relations_process:002.9\n"); |
189 | // fprintf_(stderr,"relations_process:002.9\n"); |
|
|
190 | |
|
|
191 | |
|
|
192 | // dont need the buffer here ------- |
|
|
193 | g_free(buffer_rel1); |
|
|
194 | ib = NULL; |
190 | |
195 | |
191 | if (ways) |
196 | if (ways) |
192 | { |
197 | { |
193 | //fprintf(stderr,"relations_process:003 ways\n"); |
198 | // fprintf_(stderr,"relations_process:003 ways\n"); |
194 | |
199 | |
195 | long long pos_now = (long long)ftello(ways); // 64bit |
200 | long long pos_now = (long long)ftello(ways); // 64bit |
196 | fseeko(ways, 0, SEEK_END); |
201 | fseeko(ways, 0, SEEK_END); |
197 | size_in = (long long)ftello(ways); // 64bit |
202 | size_in = (long long)ftello(ways); // 64bit |
198 | fprintf(stderr, "relations_process: pos ways file=%lld\n", pos_now); |
203 | fprintf_(stderr, "relations_process: pos ways file=%lld\n", pos_now); |
199 | fprintf(stderr, "relations_process:size ways file=%lld\n", size_in); |
204 | fprintf_(stderr, "relations_process:size ways file=%lld\n", size_in); |
200 | // seek to start of file |
205 | // seek to start of file |
201 | fseeko(ways, 0, SEEK_SET); |
206 | fseeko(ways, 0, SEEK_SET); |
202 | // reset timer |
207 | // reset timer |
203 | diff2_tt = 0; |
208 | diff2_tt = 0; |
204 | _c = 0; |
209 | _c = 0; |
205 | time(&start_tt); |
210 | time(&start_tt); |
206 | |
211 | |
|
|
212 | // fprintf_(stderr,"relations_process:004 ways\n"); |
|
|
213 | |
|
|
214 | // zero out buffer ------------------ |
|
|
215 | // bzero(ib_buffer_array[0], MAX_ITEMBIN_BYTES_); |
|
|
216 | // zero out buffer ------------------ |
|
|
217 | |
|
|
218 | |
207 | while ((ib = read_item(ways, 0))) |
219 | while ((ib = read_item(ways, 0))) |
208 | { |
220 | { |
209 | _c++; |
221 | _c++; |
210 | |
222 | |
211 | //fprintf(stderr,"relations_process:003.1\n"); |
223 | // fprintf_(stderr,"relations_process:003.1\n"); |
212 | |
224 | |
213 | id = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
|
|
214 | |
|
|
215 | //fprintf(stderr,"********DUMP relw***********\n"); |
|
|
216 | //dump_itembin(ib); |
|
|
217 | //fprintf(stderr,"********DUMP relw***********\n"); |
|
|
218 | |
|
|
219 | //char *labelxx=item_bin_get_attr(ib, attr_name, NULL); |
|
|
220 | //fprintf(stderr,"relations_process:003.2 %s\n", labelxx); |
|
|
221 | //labelxx=item_bin_get_attr(ib, attr_label, NULL); |
|
|
222 | //fprintf(stderr,"relations_process:003.3 %s\n", labelxx); |
|
|
223 | |
|
|
224 | if (id) |
225 | if (ib) |
225 | { |
226 | { |
226 | //fprintf(stderr,"relations_process:004 wayid:"LONGLONG_FMT"\n", id); |
|
|
227 | |
227 | |
228 | l = g_hash_table_lookup(rel->member_hash[1], id); |
228 | id = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
229 | while (l) |
229 | |
|
|
230 | //fprintf(stderr,"********DUMP relw***********\n"); |
|
|
231 | //dump_itembin(ib); |
|
|
232 | //fprintf(stderr,"********DUMP relw***********\n"); |
|
|
233 | |
|
|
234 | //char *labelxx=item_bin_get_attr(ib, attr_name, NULL); |
|
|
235 | //fprintf(stderr,"relations_process:003.2 %s\n", labelxx); |
|
|
236 | //labelxx=item_bin_get_attr(ib, attr_label, NULL); |
|
|
237 | //fprintf(stderr,"relations_process:003.3 %s\n", labelxx); |
|
|
238 | |
|
|
239 | if (id) |
230 | { |
240 | { |
|
|
241 | // fprintf_(stderr,"relations_process:004 wayid:"LONGLONG_FMT"\n", id); |
|
|
242 | |
|
|
243 | l = g_hash_table_lookup(rel->member_hash[1], id); |
|
|
244 | while (l) |
|
|
245 | { |
231 | //fprintf(stderr,"relations_process:005\n"); |
246 | // fprintf_(stderr,"relations_process:005\n"); |
232 | struct relations_member *memb = l->data; |
247 | struct relations_member *memb = l->data; |
233 | //fprintf(stderr,"relations_process:005.1 %d\n", memb->memberid); |
248 | // fprintf_(stderr,"relations_process:005.1 %d\n", memb->memberid); |
234 | memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv); |
249 | memb->func->func(memb->func->func_priv, memb->relation_priv, ib, memb->member_priv); |
235 | l = g_list_next(l); |
250 | l = g_list_next(l); |
|
|
251 | } |
236 | } |
252 | } |
|
|
253 | |
|
|
254 | if (_c > _e) |
|
|
255 | { |
|
|
256 | _c = 0; |
|
|
257 | |
|
|
258 | pos_in = ftello(ways); // 64bit |
|
|
259 | time(&end_tt); |
|
|
260 | diff_tt = difftime(end_tt,start_tt); |
|
|
261 | char outstring[200]; |
|
|
262 | char outstring2[200]; |
|
|
263 | char outstring3[200]; |
|
|
264 | convert_to_human_time(diff_tt, outstring); |
|
|
265 | convert_to_human_bytes(pos_in, outstring2); |
|
|
266 | convert_to_human_bytes(size_in, outstring3); |
|
|
267 | fprintf_(stderr, "-RUNTIME-LOOP-REL-PROC-WAYS: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3); |
|
|
268 | if (pos_in > 0) |
|
|
269 | { |
|
|
270 | double eta_time = (diff_tt / pos_in) * (size_in - pos_in); |
|
|
271 | convert_to_human_time(eta_time, outstring); |
|
|
272 | fprintf_(stderr, "-RUNTIME-LOOP-REL-PROC-WAYS: %s left\n", outstring); |
|
|
273 | } |
|
|
274 | } |
|
|
275 | |
237 | } |
276 | } |
238 | |
277 | |
239 | if (_c > _e) |
|
|
240 | { |
|
|
241 | _c = 0; |
|
|
242 | |
|
|
243 | pos_in = ftello(ways); // 64bit |
|
|
244 | time(&end_tt); |
|
|
245 | diff_tt = difftime(end_tt,start_tt); |
|
|
246 | char outstring[200]; |
|
|
247 | char outstring2[200]; |
|
|
248 | char outstring3[200]; |
|
|
249 | convert_to_human_time(diff_tt, outstring); |
|
|
250 | convert_to_human_bytes(pos_in, outstring2); |
|
|
251 | convert_to_human_bytes(size_in, outstring3); |
|
|
252 | fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-WAYS: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3); |
|
|
253 | if (pos_in > 0) |
|
|
254 | { |
|
|
255 | double eta_time = (diff_tt / pos_in) * (size_in - pos_in); |
|
|
256 | convert_to_human_time(eta_time, outstring); |
|
|
257 | fprintf(stderr, "-RUNTIME-LOOP-REL-PROC-WAYS: %s left\n", outstring); |
|
|
258 | } |
|
|
259 | } |
|
|
260 | } |
278 | } |
261 | } |
279 | } |
262 | } |
|
|
263 | |
280 | |
|
|
281 | // fprintf_(stderr,"relations_process:099\n"); |
|
|
282 | } |
|
|
283 | |
|
|
284 | void relations_destroy_func(void *key, GList *l, void *data) |
|
|
285 | { |
|
|
286 | while (l) |
|
|
287 | { |
|
|
288 | g_free(l->data); |
|
|
289 | l=g_list_next(l); |
|
|
290 | } |
|
|
291 | } |
|
|
292 | |
|
|
293 | void relations_destroy(struct relations *relations) |
|
|
294 | { |
|
|
295 | int i; |
|
|
296 | |
|
|
297 | for (i = 0 ; i < 3 ; i++) |
|
|
298 | { |
|
|
299 | g_hash_table_foreach(relations->member_hash[i], (GHFunc)relations_destroy_func, NULL); |
|
|
300 | g_hash_table_destroy(relations->member_hash[i]); |
|
|
301 | } |
|
|
302 | } |
|
|
303 | |
|
|
304 | |
|
|
305 | |