SegmentsX *CreateSuperSegments(NodesX *nodesx,SegmentsX *segmentsx,WaysX *waysx) { index_t i; SegmentsX *supersegmentsx; index_t sn=0,ss=0; supersegmentsx=NewSegmentList(0); if(segmentsx->number==0 || waysx->number==0) return(supersegmentsx); /* Print the start message */ printf_first("Creating Super-Segments: Super-Nodes=0 Super-Segments=0"); /* Map into memory / open the files */ #if !SLIM segmentsx->data=MapFile(segmentsx->filename); waysx->data=MapFile(waysx->filename); #else segmentsx->fd=ReOpenFile(segmentsx->filename); waysx->fd=ReOpenFile(waysx->filename); #endif /* Create super-segments for each super-node. */ for(i=0;i<nodesx->number;i++) { if(IsBitSet(nodesx->super,i)) { SegmentX *segmentx; int count=0,match; Way prevway[MAX_SEG_PER_NODE]; segmentx=FirstSegmentX(segmentsx,i,1); while(segmentx) { WayX *wayx=LookupWayX(waysx,segmentx->way,1); /* Check that this type of way hasn't already been routed */ match=0; if(count>0) { int j; for(j=0;j<count;j++) if(!WaysCompare(&prevway[j],&wayx->way)) { match=1; break; } } assert(count<MAX_SEG_PER_NODE); /* Only a limited amount of history stored. */ prevway[count++]=wayx->way; /* Route the way and store the super-segments. */ if(!match) { Results *results=FindRoutesWay(nodesx,segmentsx,waysx,i,&wayx->way); Result *result=FirstResult(results); while(result) { if(IsBitSet(nodesx->super,result->node) && result->segment!=NO_SEGMENT) { if(wayx->way.type&Way_OneWay && result->node!=i) AppendSegment(supersegmentsx,segmentx->way,i,result->node,DISTANCE((distance_t)result->score)|ONEWAY_1TO2); else AppendSegment(supersegmentsx,segmentx->way,i,result->node,DISTANCE((distance_t)result->score)); ss++; } result=NextResult(results,result); } FreeResultsList(results); } segmentx=NextSegmentX(segmentsx,segmentx,i); } sn++; if(!(sn%10000)) printf_middle("Creating Super-Segments: Super-Nodes=%"Pindex_t" Super-Segments=%"Pindex_t,sn,ss); } } /* Unmap from memory / close the files */ #if !SLIM segmentsx->data=UnmapFile(segmentsx->filename); waysx->data=UnmapFile(waysx->filename); #else segmentsx->fd=CloseFile(segmentsx->fd); waysx->fd=CloseFile(waysx->fd); #endif /* Print the final message */ printf_last("Created Super-Segments: Super-Nodes=%"Pindex_t" Super-Segments=%"Pindex_t,sn,ss); return(supersegmentsx); }
void SortWayNames(WaysX *waysx) { index_t i; int nfd; char *names[2]={NULL,NULL}; int namelen[2]={0,0}; int nnames=0; uint32_t lastlength=0; /* Print the start message */ printf_first("Sorting Way Names"); /* Re-open the file read-only and new file writeable */ waysx->nfd=ReOpenFileBuffered(waysx->nfilename_tmp); DeleteFile(waysx->nfilename_tmp); nfd=OpenFileBufferedNew(waysx->nfilename_tmp); /* Sort the way names */ waysx->nlength=0; filesort_vary(waysx->nfd,nfd,NULL, (int (*)(const void*,const void*))sort_by_name, NULL); /* Close the files */ waysx->nfd=CloseFileBuffered(waysx->nfd); CloseFileBuffered(nfd); /* Print the final message */ printf_last("Sorted Way Names: Ways=%"Pindex_t,waysx->number); /* Print the start message */ printf_first("Updating Ways with Names: Ways=0 Names=0"); /* Map into memory / open the file */ #if !SLIM waysx->data=MapFileWriteable(waysx->filename_tmp); #else waysx->fd=SlimMapFileWriteable(waysx->filename_tmp); #endif /* Re-open the file read-only and new file writeable */ waysx->nfd=ReOpenFileBuffered(waysx->nfilename_tmp); DeleteFile(waysx->nfilename_tmp); nfd=OpenFileBufferedNew(waysx->nfilename_tmp); /* Update the ways and de-duplicate the names */ for(i=0;i<waysx->number;i++) { WayX *wayx; index_t index; FILESORT_VARINT size; ReadFileBuffered(waysx->nfd,&size,FILESORT_VARSIZE); if(namelen[nnames%2]<size) names[nnames%2]=(char*)realloc((void*)names[nnames%2],namelen[nnames%2]=size); ReadFileBuffered(waysx->nfd,&index,sizeof(index_t)); ReadFileBuffered(waysx->nfd,names[nnames%2],size-sizeof(index_t)); if(nnames==0 || strcmp(names[0],names[1])) { WriteFileBuffered(nfd,names[nnames%2],size-sizeof(index_t)); lastlength=waysx->nlength; waysx->nlength+=size-sizeof(index_t); nnames++; } wayx=LookupWayX(waysx,index,1); wayx->way.name=lastlength; PutBackWayX(waysx,wayx); if(!((i+1)%1000)) printf_middle("Updating Ways with Names: Ways=%"Pindex_t" Names=%"Pindex_t,i+1,nnames); } if(names[0]) free(names[0]); if(names[1]) free(names[1]); /* Close the files */ waysx->nfd=CloseFileBuffered(waysx->nfd); CloseFileBuffered(nfd); /* Unmap from memory / close the files */ #if !SLIM waysx->data=UnmapFile(waysx->data); #else waysx->fd=SlimUnmapFile(waysx->fd); #endif /* Print the final message */ printf_last("Updated Ways with Names: Ways=%"Pindex_t" Names=%"Pindex_t,waysx->number,nnames); }