The SwappyItems Key-Values Store
ReadPbfData.cpp

One of the main focus in SwappyItems is: processing big data like pbf or osm files from open streetmaps.

// we need it for PRId32 in snprintf
#define __STDC_FORMAT_MACROS
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <utility> // pair
#include <chrono>
#include <inttypes.h>
#include <vector>
#include <thread> // just for printing the number of cores
#include <atomic>
// catch ctrl+c
#include <csignal>
#include <unistd.h>
#include "SwappyItems.hpp"
#include "osmpbfreader.hpp"
using namespace CanalTP;
using namespace std;
#define FILE_ITEMS ( 7*1024) // 2*1024 // 64*1024
#define FILE_MULTI 6 // 4 // 16
#define RAM_MULTI 9 // 8
#define BBITS 5 // 5
#define BMASK ((BBITS+4)* FILE_ITEMS) // +4
typedef uint64_t Key; // for the key-value tuple, 8 byte
struct NodeData {
uint8_t _used;
double _lon;
double _lat;
};
struct WayData {
uint8_t _type;
char _name[256];
};
struct PlaceData {
uint8_t _type;
double _lon;
double _lat;
char _name[256];
};
// ---------------------------------------------------------------------
std::chrono::time_point<std::chrono::system_clock> start;
double mseconds;
atomic<bool> isPrinted = false;
#include "tools.hpp"
#include "Routing.hpp"
int main(int argc, char** argv) {
if(argc != 2) {
printf("Usage: %s file_to_read.osm.pbf\n", argv[0]);
return 1;
}
ways = new SwappyItemsWAYS(23);
Routing routing;
start = std::chrono::high_resolution_clock::now();
read_osm_pbf(argv[1], routing, true); // read way only
auto now = std::chrono::high_resolution_clock::now();
mseconds = std::chrono::duration<double, std::milli>(now-start).count();
printf("# end ways: %.f ms\n", mseconds);
read_osm_pbf(argv[1], routing, false); // read nodes and relations
now = std::chrono::high_resolution_clock::now();
mseconds = std::chrono::duration<double, std::milli>(now-start).count();
printf("# end nodes: %.f ms\n", mseconds);
delete places;
delete nodes;
delete ways;
return 0;
}
uint64_t Key
Definition: ReadPbfData.cpp:31
SwappyItemsPLACES * places
Definition: ReadPbfData.cpp:56
int main(int argc, char **argv)
Definition: ReadPbfData.cpp:71
atomic< bool > isPrinted
Definition: ReadPbfData.cpp:62
double mseconds
Definition: ReadPbfData.cpp:61
SwappyItemsNODES * nodes
Definition: ReadPbfData.cpp:55
SwappyItems< Key, WayData, FILE_ITEMS, FILE_MULTI, RAM_MULTI, BBITS, BMASK > SwappyItemsWAYS
Definition: ReadPbfData.cpp:51
SwappyItems< Key, NodeData, FILE_ITEMS, FILE_MULTI, RAM_MULTI, BBITS, BMASK > SwappyItemsNODES
Definition: ReadPbfData.cpp:52
SwappyItems< Key, PlaceData, FILE_ITEMS, FILE_MULTI, RAM_MULTI, BBITS, BMASK > SwappyItemsPLACES
Definition: ReadPbfData.cpp:53
std::chrono::time_point< std::chrono::system_clock > start
Definition: ReadPbfData.cpp:60
SwappyItemsWAYS * ways
Definition: ReadPbfData.cpp:54
Definition: SwappyItems.hpp:49
Definition: osmpbfreader.hpp:48
void read_osm_pbf(const std::string &filename, Visitor &visitor, bool wayOnly)
Definition: osmpbfreader.hpp:359
Definition: osm2graph.cpp:53
Definition: ReadPbfData.cpp:44
Definition: osm2graph.cpp:120
Definition: osm2graph.cpp:60
void logHead()
Definition: tools.hpp:71
void catchSig()
Definition: tools.hpp:62