Windows support, thanks sivetic
This commit is contained in:
@@ -32,7 +32,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <google/sparse_hash_map>
|
||||
#include <google/sparsetable>
|
||||
|
||||
template< typename NodeID, typename Key, bool initialize = false >
|
||||
template< typename NodeID, typename Key, bool initialize = true >
|
||||
class ArrayStorage {
|
||||
public:
|
||||
|
||||
@@ -144,7 +144,7 @@ public:
|
||||
void Clear() {
|
||||
heap.resize( 1 );
|
||||
insertedNodes.clear();
|
||||
heap[0].weight = std::numeric_limits< Weight >::min();
|
||||
heap[0].weight = (std::numeric_limits< Weight >::min)();
|
||||
nodeIndex.Clear();
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ public:
|
||||
for ( typename std::vector< HeapElement >::iterator i = heap.begin() + 1, iend = heap.end(); i != iend; ++i )
|
||||
insertedNodes[i->index].key = 0;
|
||||
heap.resize( 1 );
|
||||
heap[0].weight = std::numeric_limits< Weight >::min();
|
||||
heap[0].weight = (std::numeric_limits< Weight >::min)();
|
||||
}
|
||||
|
||||
void DecreaseKey( NodeID node, Weight weight ) {
|
||||
|
||||
@@ -200,12 +200,12 @@ class DynamicGraph {
|
||||
|
||||
bool isDummy( EdgeIterator edge ) const
|
||||
{
|
||||
return m_edges[edge].target == std::numeric_limits< NodeIterator >::max();
|
||||
return m_edges[edge].target == (std::numeric_limits< NodeIterator >::max)();
|
||||
}
|
||||
|
||||
void makeDummy( EdgeIterator edge )
|
||||
{
|
||||
m_edges[edge].target = std::numeric_limits< NodeIterator >::max();
|
||||
m_edges[edge].target = (std::numeric_limits< NodeIterator >::max)();
|
||||
}
|
||||
|
||||
struct Node {
|
||||
|
||||
@@ -61,7 +61,7 @@ struct _Node : NodeInfo{
|
||||
return _Node(0,0,0);
|
||||
}
|
||||
static _Node max_value() {
|
||||
return _Node(numeric_limits<int>::max(), numeric_limits<int>::max(), numeric_limits<unsigned int>::max());
|
||||
return _Node((numeric_limits<int>::max)(), (numeric_limits<int>::max)(), (numeric_limits<unsigned int>::max)());
|
||||
}
|
||||
NodeID key() const {
|
||||
return id;
|
||||
@@ -157,7 +157,7 @@ struct _Edge {
|
||||
return _Edge(0,0);
|
||||
}
|
||||
static _Edge max_value() {
|
||||
return _Edge(numeric_limits<unsigned>::max(), numeric_limits<unsigned>::max());
|
||||
return _Edge((numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)());
|
||||
}
|
||||
|
||||
};
|
||||
@@ -194,10 +194,10 @@ struct _RawRestrictionContainer {
|
||||
_RawRestrictionContainer(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaWay(UINT_MAX) { restriction.flags.isOnly = isOnly;}
|
||||
|
||||
static _RawRestrictionContainer min_value() {
|
||||
return _RawRestrictionContainer(numeric_limits<unsigned>::min(), numeric_limits<unsigned>::min(), numeric_limits<unsigned>::min(), numeric_limits<unsigned>::min());
|
||||
return _RawRestrictionContainer((numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)());
|
||||
}
|
||||
static _RawRestrictionContainer max_value() {
|
||||
return _RawRestrictionContainer(numeric_limits<unsigned>::max(), numeric_limits<unsigned>::max(), numeric_limits<unsigned>::max(), numeric_limits<unsigned>::max());
|
||||
return _RawRestrictionContainer((numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -238,10 +238,10 @@ struct _WayIDStartAndEndEdge {
|
||||
_WayIDStartAndEndEdge(unsigned w, NodeID fs, NodeID ft, NodeID ls, NodeID lt) : wayID(w), firstStart(fs), firstTarget(ft), lastStart(ls), lastTarget(lt) {}
|
||||
|
||||
static _WayIDStartAndEndEdge min_value() {
|
||||
return _WayIDStartAndEndEdge(numeric_limits<unsigned>::min(), numeric_limits<unsigned>::min(), numeric_limits<unsigned>::min(), numeric_limits<unsigned>::min(), numeric_limits<unsigned>::min());
|
||||
return _WayIDStartAndEndEdge((numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)());
|
||||
}
|
||||
static _WayIDStartAndEndEdge max_value() {
|
||||
return _WayIDStartAndEndEdge(numeric_limits<unsigned>::max(), numeric_limits<unsigned>::max(), numeric_limits<unsigned>::max(), numeric_limits<unsigned>::max(), numeric_limits<unsigned>::max());
|
||||
return _WayIDStartAndEndEdge((numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)(), (numeric_limits<unsigned>::max)());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+14
-9
@@ -28,6 +28,11 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
#include <stxxl.h>
|
||||
#include <omp.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <google/dense_hash_map>
|
||||
@@ -160,7 +165,7 @@ public:
|
||||
}
|
||||
|
||||
NNGrid(const char* rif, const char* _i, unsigned numberOfThreads = omp_get_num_procs()): cellCache(500), fileCache(500) {
|
||||
iif = _i;
|
||||
iif = std::string(_i);
|
||||
ramIndexTable.resize((1024*1024), UINT_MAX);
|
||||
ramInFile.open(rif, std::ios::in | std::ios::binary);
|
||||
}
|
||||
@@ -271,7 +276,7 @@ public:
|
||||
}
|
||||
}
|
||||
_Coordinate tmp;
|
||||
double dist = numeric_limits<double>::max();
|
||||
double dist = (numeric_limits<double>::max)();
|
||||
timestamp = get_timestamp();
|
||||
for(std::vector<_Edge>::iterator it = candidates.begin(); it != candidates.end(); it++) {
|
||||
double r = 0.;
|
||||
@@ -286,7 +291,7 @@ public:
|
||||
nodesOfEdge.projectedPoint.lon = tmp.lon;
|
||||
}
|
||||
}
|
||||
if(dist != numeric_limits<double>::max()) {
|
||||
if(dist != (numeric_limits<double>::max)()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -307,7 +312,7 @@ public:
|
||||
}
|
||||
|
||||
_Coordinate tmp;
|
||||
double dist = numeric_limits<double>::max();
|
||||
double dist = (numeric_limits<double>::max)();
|
||||
// timestamp = get_timestamp();
|
||||
for(std::vector<_Edge>::iterator it = candidates.begin(); it != candidates.end(); it++) {
|
||||
double r = 0.;
|
||||
@@ -342,7 +347,7 @@ public:
|
||||
}
|
||||
}
|
||||
_Coordinate tmp;
|
||||
double dist = numeric_limits<double>::max();
|
||||
double dist = (numeric_limits<double>::max)();
|
||||
timestamp = get_timestamp();
|
||||
for(std::vector<_Edge>::iterator it = candidates.begin(); it != candidates.end(); it++) {
|
||||
double r = 0.;
|
||||
@@ -366,7 +371,7 @@ public:
|
||||
}
|
||||
}
|
||||
_Coordinate tmp;
|
||||
double dist = numeric_limits<double>::max();
|
||||
double dist = (numeric_limits<double>::max)();
|
||||
for(std::vector<_Edge>::iterator it = candidates.begin(); it != candidates.end(); it++) {
|
||||
double r = 0.;
|
||||
double tmpDist = ComputeDistance(startCoord, it->startCoord, it->targetCoord, tmp, &r);
|
||||
@@ -561,7 +566,7 @@ private:
|
||||
// if(cellCache.exists(startIndexInFile)) {
|
||||
// cellCache.fetch(startIndexInFile, cellIndex);
|
||||
// } else {
|
||||
std::ifstream localStream(iif, std::ios::in | std::ios::binary);
|
||||
std::ifstream localStream(iif.c_str(), std::ios::in | std::ios::binary);
|
||||
localStream.seekg(startIndexInFile);
|
||||
localStream.read((char*) &cellIndex[0], 32*32*sizeof(unsigned));
|
||||
localStream.close();
|
||||
@@ -579,7 +584,7 @@ private:
|
||||
// if(fileCache.exists(position)) {
|
||||
// fileCache.fetch(position, result);
|
||||
// } else {
|
||||
std::ifstream localStream(iif, std::ios::in | std::ios::binary);
|
||||
std::ifstream localStream(iif.c_str(), std::ios::in | std::ios::binary);
|
||||
localStream.seekg(position);
|
||||
DiskEdge diskEdge;
|
||||
do {
|
||||
@@ -655,7 +660,7 @@ private:
|
||||
ifstream ramInFile;
|
||||
stxxl::vector<GridEntry> * entries;
|
||||
std::vector<unsigned> ramIndexTable; //4 MB for first level index in RAM
|
||||
const char * iif;
|
||||
std::string iif;
|
||||
LRUCache<int,std::vector<unsigned> > cellCache;
|
||||
LRUCache<int,std::vector<_Edge> > fileCache;
|
||||
};
|
||||
|
||||
@@ -373,18 +373,20 @@ private:
|
||||
if ( size > MAX_BLOB_HEADER_SIZE || size < 0 ) {
|
||||
return false;
|
||||
}
|
||||
char data[size];
|
||||
char *data = (char*)malloc(size);
|
||||
stream.read(data, size*sizeof(data[0]));
|
||||
|
||||
if ( !(threadData->PBFBlobHeader).ParseFromArray( data, size ) ){
|
||||
free(data);
|
||||
return false;
|
||||
}
|
||||
free(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool unpackZLIB(std::fstream & stream, _ThreadData * threadData) {
|
||||
unsigned rawSize = threadData->PBFBlob.raw_size();
|
||||
char unpackedDataArray[rawSize];
|
||||
char* unpackedDataArray = (char*)malloc(rawSize);
|
||||
z_stream compressedDataStream;
|
||||
compressedDataStream.next_in = ( unsigned char* ) threadData->PBFBlob.zlib_data().data();
|
||||
compressedDataStream.avail_in = threadData->PBFBlob.zlib_data().size();
|
||||
@@ -396,6 +398,7 @@ private:
|
||||
int ret = inflateInit( &compressedDataStream );
|
||||
if ( ret != Z_OK ) {
|
||||
std::cerr << "[error] failed to init zlib stream" << std::endl;
|
||||
free(unpackedDataArray);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -403,12 +406,14 @@ private:
|
||||
if ( ret != Z_STREAM_END ) {
|
||||
std::cerr << "[error] failed to inflate zlib stream" << std::endl;
|
||||
std::cerr << "[error] Error type: " << ret << std::endl;
|
||||
free(unpackedDataArray);
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = inflateEnd( &compressedDataStream );
|
||||
if ( ret != Z_OK ) {
|
||||
std::cerr << "[error] failed to deinit zlib stream" << std::endl;
|
||||
free(unpackedDataArray);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -416,6 +421,7 @@ private:
|
||||
for(unsigned i = 0; i < rawSize; i++) {
|
||||
threadData->charBuffer[i] = unpackedDataArray[i];
|
||||
}
|
||||
free(unpackedDataArray);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -433,11 +439,12 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
char data[size];
|
||||
char* data = (char*)malloc(size);
|
||||
stream.read(data, sizeof(data[0])*size);
|
||||
|
||||
if ( !threadData->PBFBlob.ParseFromArray( data, size ) ) {
|
||||
std::cerr << "[error] failed to parse blob" << std::endl;
|
||||
free(data);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -451,16 +458,20 @@ private:
|
||||
} else if ( threadData->PBFBlob.has_zlib_data() ) {
|
||||
if ( !unpackZLIB(stream, threadData) ) {
|
||||
std::cerr << "[error] zlib data encountered that could not be unpacked" << std::endl;
|
||||
free(data);
|
||||
return false;
|
||||
}
|
||||
} else if ( threadData->PBFBlob.has_lzma_data() ) {
|
||||
if ( !unpackLZMA(stream, threadData) )
|
||||
std::cerr << "[error] lzma data encountered that could not be unpacked" << std::endl;
|
||||
free(data);
|
||||
return false;
|
||||
} else {
|
||||
std::cerr << "[error] Blob contains no data" << std::endl;
|
||||
free(data);
|
||||
return false;
|
||||
}
|
||||
free(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+24
-2
@@ -24,8 +24,30 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <climits>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <sys/time.h>
|
||||
#include <tr1/functional_hash.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/types.h>
|
||||
#include <winsock.h>
|
||||
void gettimeofday(struct timeval* t,void* timezone)
|
||||
{ struct _timeb timebuffer;
|
||||
_ftime( &timebuffer );
|
||||
t->tv_sec=timebuffer.time;
|
||||
t->tv_usec=1000*timebuffer.millitm;
|
||||
}
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <boost/functional/hash.hpp>
|
||||
#else
|
||||
#include <tr1/functional_hash.h>
|
||||
#endif
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
/** Returns a timestamp (now) in seconds (incl. a fractional part). */
|
||||
|
||||
Reference in New Issue
Block a user