Skip to content

Commit a394973

Browse files
author
DennisOSRM
committed
Merging 4f73b47 into master
1 parent 71b90ab commit a394973

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

DataStructures/NNGrid.h

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,20 @@ class NNGrid {
158158
}
159159

160160
bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode) {
161+
// double time1 = get_timestamp();
161162
bool foundNode = false;
162163
_Coordinate startCoord(100000*(lat2y(static_cast<double>(location.lat)/100000.)), location.lon);
163164
/** search for point on edge close to source */
164165
unsigned fileIndex = GetFileIndexForLatLon(startCoord.lat, startCoord.lon);
165166
std::vector<_GridEdge> candidates;
166-
boost::unordered_map< unsigned, unsigned, IdenticalHashFunction > cellMap;
167+
// boost::unordered_map< unsigned, unsigned, IdenticalHashFunction > cellMap;
167168
for(int j = -32768; (j < (32768+1)) && (fileIndex != UINT_MAX); j+=32768) {
168169
for(int i = -1; i < 2; ++i){
169-
GetContentsOfFileBucket(fileIndex+i+j, candidates, cellMap);
170+
GetContentsOfFileBucketEnumerated(fileIndex+i+j, candidates/*, cellMap*/);
170171
}
171172
}
173+
// double time2 = get_timestamp();
174+
// INFO("NN-Lookup in " << 1000*(time2-time1) << "ms");
172175
_GridEdge smallestEdge;
173176
_Coordinate tmp;
174177
double dist = numeric_limits<double>::max();
@@ -222,6 +225,7 @@ class NNGrid {
222225
resultNode.ratio = ratio;
223226
// INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2 << ", ratio: " << ratio);
224227
// INFO("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--");
228+
// INFO("NN-Lookup in " << 1000*(time2-time1) << "ms");
225229
return foundNode;
226230
}
227231

@@ -282,6 +286,24 @@ class NNGrid {
282286

283287

284288
private:
289+
inline unsigned GetCellIndexFromRAMAndFileIndex(const unsigned ramIndex, const unsigned fileIndex) const {
290+
unsigned lineBase = ramIndex/1024;
291+
lineBase = lineBase*32*32768;
292+
unsigned columnBase = ramIndex%1024;
293+
columnBase=columnBase*32;
294+
for (int i = 0;i < 32;++i) {
295+
for (int j = 0;j < 32;++j) {
296+
const unsigned localFileIndex = lineBase + i * 32768 + columnBase + j;
297+
if(localFileIndex == fileIndex) {
298+
unsigned cellIndex = i * 32 + j;
299+
return cellIndex;
300+
}
301+
}
302+
}
303+
return UINT_MAX;
304+
}
305+
306+
285307
inline void BuildCellIndexToFileIndexMap(const unsigned ramIndex, boost::unordered_map<unsigned, unsigned, IdenticalHashFunction >& cellMap){
286308
unsigned lineBase = ramIndex/1024;
287309
lineBase = lineBase*32*32768;
@@ -389,6 +411,44 @@ class NNGrid {
389411
return counter;
390412
}
391413

414+
inline void GetContentsOfFileBucketEnumerated(const unsigned fileIndex, std::vector<_GridEdge>& result) const {
415+
unsigned ramIndex = GetRAMIndexFromFileIndex(fileIndex);
416+
unsigned long startIndexInFile = ramIndexTable[ramIndex];
417+
if(startIndexInFile == ULONG_MAX) {
418+
return;
419+
}
420+
unsigned enumeratedIndex = GetCellIndexFromRAMAndFileIndex(ramIndex, fileIndex);
421+
422+
423+
//todo: move to thread specific pointer
424+
unsigned long cellIndex[32*32];
425+
426+
if(!localStream.get() || !localStream->is_open()) {
427+
localStream.reset(new std::ifstream(iif.c_str(), std::ios::in | std::ios::binary));
428+
}
429+
if(!localStream->good()) {
430+
localStream->clear(std::ios::goodbit);
431+
DEBUG("Resetting stale filestream");
432+
}
433+
434+
localStream->seekg(startIndexInFile);
435+
//todo: only read the single necessary cell index
436+
localStream->read((char*) cellIndex, 32*32*sizeof(unsigned long));
437+
438+
if(cellIndex[enumeratedIndex] == ULONG_MAX) {
439+
return;
440+
}
441+
const unsigned long position = cellIndex[enumeratedIndex] + 32*32*sizeof(unsigned long) ;
442+
443+
unsigned lengthOfBucket;
444+
unsigned currentSizeOfResult = result.size();
445+
localStream->seekg(position);
446+
localStream->read((char *)&(lengthOfBucket), sizeof(unsigned));
447+
result.resize(currentSizeOfResult+lengthOfBucket);
448+
localStream->read((char *)&result[currentSizeOfResult], lengthOfBucket*sizeof(_GridEdge));
449+
}
450+
451+
392452
inline void GetContentsOfFileBucket(const unsigned fileIndex, std::vector<_GridEdge>& result, boost::unordered_map< unsigned, unsigned, IdenticalHashFunction > & cellMap) {
393453
unsigned ramIndex = GetRAMIndexFromFileIndex(fileIndex);
394454
unsigned long startIndexInFile = ramIndexTable[ramIndex];
@@ -415,6 +475,7 @@ class NNGrid {
415475
return;
416476
}
417477
const unsigned long position = cellIndex[cellMap[fileIndex]] + 32*32*sizeof(unsigned long) ;
478+
418479
unsigned lengthOfBucket;
419480
unsigned currentSizeOfResult = result.size();
420481
localStream->seekg(position);
@@ -514,7 +575,7 @@ class NNGrid {
514575
return fileIndex;
515576
}
516577

517-
inline unsigned GetRAMIndexFromFileIndex(const int fileIndex) {
578+
inline unsigned GetRAMIndexFromFileIndex(const int fileIndex) const {
518579
unsigned fileLine = fileIndex / 32768;
519580
fileLine = fileLine / 32;
520581
fileLine = fileLine * 1024;

0 commit comments

Comments
 (0)