void CompactWayList(WaysX *waysx,SegmentsX *segmentsx) { int fd; index_t cnumber; if(waysx->number==0) return; /* Print the start message */ printf_first("Sorting Ways and Compacting"); /* Allocate the array of indexes */ waysx->cdata=(index_t*)malloc(waysx->number*sizeof(index_t)); logassert(waysx->cdata,"Failed to allocate memory (try using slim mode?)"); /* Check malloc() worked */ /* Re-open the file read-only and a new file writeable */ waysx->fd=ReOpenFileBuffered(waysx->filename_tmp); DeleteFile(waysx->filename_tmp); fd=OpenFileBufferedNew(waysx->filename_tmp); /* Sort the ways to allow compacting according to the properties */ sortwaysx=waysx; sortsegmentsx=segmentsx; cnumber=filesort_fixed(waysx->fd,fd,sizeof(WayX),(int (*)(void*,index_t))delete_unused, (int (*)(const void*,const void*))sort_by_name_and_prop_and_id, (int (*)(void*,index_t))deduplicate_and_index_by_compact_id); /* Close the files */ waysx->fd=CloseFileBuffered(waysx->fd); CloseFileBuffered(fd); /* Free the data */ free(segmentsx->usedway); segmentsx->usedway=NULL; /* Print the final message */ printf_last("Sorted and Compacted Ways: Ways=%"Pindex_t" Unique=%"Pindex_t,waysx->number,cnumber); waysx->number=cnumber; }
void SortNodeList(NodesX *nodesx) { int fd; index_t xnumber; /* Print the start message */ printf_first("Sorting Nodes"); /* Close the file (finished appending) */ nodesx->fd=CloseFile(nodesx->fd); /* Re-open the file read-only and a new file writeable */ nodesx->fd=ReOpenFile(nodesx->filename); DeleteFile(nodesx->filename); fd=OpenFileNew(nodesx->filename); /* Allocate the array of indexes */ nodesx->idata=(node_t*)malloc(nodesx->number*sizeof(node_t)); assert(nodesx->idata); /* Check malloc() worked */ /* Sort by node indexes */ xnumber=nodesx->number; nodesx->number=0; sortnodesx=nodesx; filesort_fixed(nodesx->fd,fd,sizeof(NodeX),(int (*)(const void*,const void*))sort_by_id,(int (*)(void*,index_t))deduplicate_and_index_by_id); /* Close the files */ nodesx->fd=CloseFile(nodesx->fd); CloseFile(fd); /* Print the final message */ printf_last("Sorted Nodes: Nodes=%"Pindex_t" Duplicates=%"Pindex_t,xnumber,xnumber-nodesx->number); }
void SortNodeListGeographically(NodesX *nodesx) { int fd; /* Print the start message */ printf_first("Sorting Nodes Geographically"); /* Allocate the memory for the geographical index array */ nodesx->gdata=(index_t*)malloc(nodesx->number*sizeof(index_t)); assert(nodesx->gdata); /* Check malloc() worked */ /* Re-open the file read-only and a new file writeable */ nodesx->fd=ReOpenFile(nodesx->filename); DeleteFile(nodesx->filename); fd=OpenFileNew(nodesx->filename); /* Sort geographically */ sortnodesx=nodesx; filesort_fixed(nodesx->fd,fd,sizeof(NodeX),(int (*)(const void*,const void*))sort_by_lat_long,(int (*)(void*,index_t))index_by_lat_long); /* Close the files */ nodesx->fd=CloseFile(nodesx->fd); CloseFile(fd); /* Print the final message */ printf_last("Sorted Nodes Geographically"); }