refactoring SegmentInformation to fit into a cache line

This commit is contained in:
Dennis Luxen 2013-12-08 18:33:53 +01:00
parent ee6c15b997
commit 2edf4906a4
5 changed files with 77 additions and 47 deletions

View File

@ -35,9 +35,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <vector> #include <vector>
struct _PathData { struct _PathData {
_PathData(NodeID no, unsigned na, unsigned tu, unsigned dur) : node(no), nameID(na), durationOfSegment(dur), turnInstruction(tu) { } _PathData(NodeID no, unsigned na, unsigned tu, unsigned dur) : node(no), name_id(na), durationOfSegment(dur), turnInstruction(tu) { }
NodeID node; NodeID node;
unsigned nameID; unsigned name_id;
unsigned durationOfSegment; unsigned durationOfSegment;
short turnInstruction; short turnInstruction;
}; };

View File

@ -30,22 +30,51 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Coordinate.h" #include "Coordinate.h"
#include "TurnInstructions.h" #include "TurnInstructions.h"
#include "../typedefs.h" #include "../typedefs.h"
#include <climits> // Struct fits everything in one cache line
struct SegmentInformation { struct SegmentInformation {
FixedPointCoordinate location; FixedPointCoordinate location;
NodeID nameID; NodeID name_id;
double length;
unsigned duration; unsigned duration;
double bearing; double length;
TurnInstruction turnInstruction; short bearing; //more than enough [0..3600] fits into 12 bits
TurnInstruction turn_instruction;
bool necessary; bool necessary;
SegmentInformation(const FixedPointCoordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr, const bool nec) :
location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(nec) {} explicit SegmentInformation(
SegmentInformation(const FixedPointCoordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr) : const FixedPointCoordinate & location,
location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(tInstr != 0) {} const NodeID name_id,
const unsigned duration,
const double length,
const TurnInstruction turn_instruction,
const bool necessary
) :
location(location),
name_id(name_id),
duration(duration),
length(length),
bearing(0),
turn_instruction(turn_instruction),
necessary(necessary)
{ }
explicit SegmentInformation(
const FixedPointCoordinate & location,
const NodeID name_id,
const unsigned duration,
const double length,
const TurnInstruction turn_instruction
) :
location(location),
name_id(name_id),
duration(duration),
length(length),
bearing(0),
turn_instruction(turn_instruction),
necessary(turn_instruction != 0)
{ }
}; };
#endif /* SEGMENTINFORMATION_H_ */ #endif /* SEGMENTINFORMATION_H_ */

View File

@ -87,9 +87,9 @@ void DescriptionFactory::AppendSegment(
const _PathData & data const _PathData & data
) { ) {
if(1 == pathDescription.size() && pathDescription.back().location == coordinate) { if(1 == pathDescription.size() && pathDescription.back().location == coordinate) {
pathDescription.back().nameID = data.nameID; pathDescription.back().name_id = data.name_id;
} else { } else {
pathDescription.push_back(SegmentInformation(coordinate, data.nameID, 0, data.durationOfSegment, data.turnInstruction) ); pathDescription.push_back(SegmentInformation(coordinate, data.name_id, 0, data.durationOfSegment, data.turnInstruction) );
} }
} }
@ -138,7 +138,7 @@ void DescriptionFactory::AppendUnencodedPolylineString(
// unsigned durationOfSegment = 0; // unsigned durationOfSegment = 0;
// unsigned indexOfSegmentBegin = 0; // unsigned indexOfSegmentBegin = 0;
// std::string string0 = sEngine.GetEscapedNameForNameID(pathDescription[0].nameID); // std::string string0 = sEngine.GetEscapedNameForNameID(pathDescription[0].name_id);
// std::string string1; // std::string string1;
@ -156,7 +156,7 @@ void DescriptionFactory::AppendUnencodedPolylineString(
// // unsigned lastTurn = 0; // // unsigned lastTurn = 0;
// // for(unsigned i = 1; i < pathDescription.size(); ++i) { // // for(unsigned i = 1; i < pathDescription.size(); ++i) {
// // string1 = sEngine.GetEscapedNameForNameID(pathDescription[i].nameID); // // string1 = sEngine.GetEscapedNameForNameID(pathDescription[i].name_id);
// // if(TurnInstructionsClass::GoStraight == pathDescription[i].turnInstruction) { // // if(TurnInstructionsClass::GoStraight == pathDescription[i].turnInstruction) {
// // if(std::string::npos != string0.find(string1+";") // // if(std::string::npos != string0.find(string1+";")
// // || std::string::npos != string0.find(";"+string1) // // || std::string::npos != string0.find(";"+string1)
@ -165,7 +165,7 @@ void DescriptionFactory::AppendUnencodedPolylineString(
// // ){ // // ){
// // SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1; // // SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1;
// // for(; lastTurn != i; ++lastTurn) // // for(; lastTurn != i; ++lastTurn)
// // pathDescription[lastTurn].nameID = pathDescription[i].nameID; // // pathDescription[lastTurn].name_id = pathDescription[i].name_id;
// // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; // // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn;
// // } else if(std::string::npos != string1.find(string0+";") // // } else if(std::string::npos != string1.find(string0+";")
// // || std::string::npos != string1.find(";"+string0) // // || std::string::npos != string1.find(";"+string0)
@ -173,7 +173,7 @@ void DescriptionFactory::AppendUnencodedPolylineString(
// // || std::string::npos != string1.find("; "+string0) // // || std::string::npos != string1.find("; "+string0)
// // ){ // // ){
// // SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0; // // SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0;
// // pathDescription[i].nameID = pathDescription[i-1].nameID; // // pathDescription[i].name_id = pathDescription[i-1].name_id;
// // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; // // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn;
// // } // // }
// // } // // }
@ -193,7 +193,7 @@ void DescriptionFactory::AppendUnencodedPolylineString(
// if(TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { // if(TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) {
// //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << segment.nameID; // //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << segment.name_id;
// assert(pathDescription[i].necessary); // assert(pathDescription[i].necessary);
// lengthOfSegment = 0; // lengthOfSegment = 0;
// durationOfSegment = 0; // durationOfSegment = 0;
@ -209,7 +209,7 @@ void DescriptionFactory::AppendUnencodedPolylineString(
// pathDescription.pop_back(); // pathDescription.pop_back();
// pathDescription.back().necessary = true; // pathDescription.back().necessary = true;
// pathDescription.back().turnInstruction = TurnInstructions.NoTurn; // pathDescription.back().turnInstruction = TurnInstructions.NoTurn;
// target_phantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->nameID; // target_phantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->name_id;
// // SimpleLogger().Write() << "Deleting last turn instruction"; // // SimpleLogger().Write() << "Deleting last turn instruction";
// } // }
// } else { // } else {
@ -221,7 +221,7 @@ void DescriptionFactory::AppendUnencodedPolylineString(
// pathDescription.erase(pathDescription.begin()); // pathDescription.erase(pathDescription.begin());
// pathDescription[0].turnInstruction = TurnInstructions.HeadOn; // pathDescription[0].turnInstruction = TurnInstructions.HeadOn;
// pathDescription[0].necessary = true; // pathDescription[0].necessary = true;
// start_phantom.nodeBasedEdgeNameID = pathDescription[0].nameID; // start_phantom.nodeBasedEdgeNameID = pathDescription[0].name_id;
// // SimpleLogger().Write() << "Deleting first turn instruction, ratio: " << start_phantom.ratio << ", length: " << pathDescription[0].length; // // SimpleLogger().Write() << "Deleting first turn instruction, ratio: " << start_phantom.ratio << ", length: " << pathDescription[0].length;
// } // }
// } else { // } else {

View File

@ -111,7 +111,7 @@ public:
unsigned durationOfSegment = 0; unsigned durationOfSegment = 0;
unsigned indexOfSegmentBegin = 0; unsigned indexOfSegmentBegin = 0;
// std::string string0 = facade->GetEscapedNameForNameID(pathDescription[0].nameID); // std::string string0 = facade->GetEscapedNameForNameID(pathDescription[0].name_id);
// std::string string1; // std::string string1;
@ -129,8 +129,8 @@ public:
// unsigned lastTurn = 0; // unsigned lastTurn = 0;
// for(unsigned i = 1; i < pathDescription.size(); ++i) { // for(unsigned i = 1; i < pathDescription.size(); ++i) {
// string1 = sEngine.GetEscapedNameForNameID(pathDescription[i].nameID); // string1 = sEngine.GetEscapedNameForNameID(pathDescription[i].name_id);
// if(TurnInstructionsClass::GoStraight == pathDescription[i].turnInstruction) { // if(TurnInstructionsClass::GoStraight == pathDescription[i].turn_instruction) {
// if(std::string::npos != string0.find(string1+";") // if(std::string::npos != string0.find(string1+";")
// || std::string::npos != string0.find(";"+string1) // || std::string::npos != string0.find(";"+string1)
// || std::string::npos != string0.find(string1+" ;") // || std::string::npos != string0.find(string1+" ;")
@ -138,19 +138,19 @@ public:
// ){ // ){
// SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1; // SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1;
// for(; lastTurn != i; ++lastTurn) // for(; lastTurn != i; ++lastTurn)
// pathDescription[lastTurn].nameID = pathDescription[i].nameID; // pathDescription[lastTurn].name_id = pathDescription[i].name_id;
// pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; // pathDescription[i].turn_instruction = TurnInstructionsClass::NoTurn;
// } else if(std::string::npos != string1.find(string0+";") // } else if(std::string::npos != string1.find(string0+";")
// || std::string::npos != string1.find(";"+string0) // || std::string::npos != string1.find(";"+string0)
// || std::string::npos != string1.find(string0+" ;") // || std::string::npos != string1.find(string0+" ;")
// || std::string::npos != string1.find("; "+string0) // || std::string::npos != string1.find("; "+string0)
// ){ // ){
// SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0; // SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0;
// pathDescription[i].nameID = pathDescription[i-1].nameID; // pathDescription[i].name_id = pathDescription[i-1].name_id;
// pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; // pathDescription[i].turn_instruction = TurnInstructionsClass::NoTurn;
// } // }
// } // }
// if (TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { // if (TurnInstructionsClass::NoTurn != pathDescription[i].turn_instruction) {
// lastTurn = i; // lastTurn = i;
// } // }
// string0 = string1; // string0 = string1;
@ -165,8 +165,8 @@ public:
pathDescription[indexOfSegmentBegin].duration = durationOfSegment; pathDescription[indexOfSegmentBegin].duration = durationOfSegment;
if(TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { if(TurnInstructionsClass::NoTurn != pathDescription[i].turn_instruction) {
//SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << pathDescription[i].nameID; //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << pathDescription[i].name_id;
assert(pathDescription[i].necessary); assert(pathDescription[i].necessary);
lengthOfSegment = 0; lengthOfSegment = 0;
durationOfSegment = 0; durationOfSegment = 0;
@ -181,8 +181,8 @@ public:
if(pathDescription.size() > 2){ if(pathDescription.size() > 2){
pathDescription.pop_back(); pathDescription.pop_back();
pathDescription.back().necessary = true; pathDescription.back().necessary = true;
pathDescription.back().turnInstruction = TurnInstructions.NoTurn; pathDescription.back().turn_instruction = TurnInstructions.NoTurn;
target_phantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->nameID; target_phantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->name_id;
// SimpleLogger().Write() << "Deleting last turn instruction"; // SimpleLogger().Write() << "Deleting last turn instruction";
} }
} else { } else {
@ -192,9 +192,9 @@ public:
//TODO: this is never called actually? //TODO: this is never called actually?
if(pathDescription.size() > 2) { if(pathDescription.size() > 2) {
pathDescription.erase(pathDescription.begin()); pathDescription.erase(pathDescription.begin());
pathDescription[0].turnInstruction = TurnInstructions.HeadOn; pathDescription[0].turn_instruction = TurnInstructions.HeadOn;
pathDescription[0].necessary = true; pathDescription[0].necessary = true;
start_phantom.nodeBasedEdgeNameID = pathDescription[0].nameID; start_phantom.nodeBasedEdgeNameID = pathDescription[0].name_id;
// SimpleLogger().Write() << "Deleting first turn instruction, ratio: " << start_phantom.ratio << ", length: " << pathDescription[0].length; // SimpleLogger().Write() << "Deleting first turn instruction, ratio: " << start_phantom.ratio << ", length: " << pathDescription[0].length;
} }
} else { } else {
@ -208,7 +208,7 @@ public:
for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){ for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){
if(pathDescription[i].necessary) { if(pathDescription[i].necessary) {
double angle = GetBearing(pathDescription[i].location, pathDescription[i+1].location); double angle = GetBearing(pathDescription[i].location, pathDescription[i+1].location);
pathDescription[i].bearing = angle; pathDescription[i].bearing = angle*10;
} }
} }

View File

@ -134,8 +134,8 @@ public:
const SegmentInformation & segment, const SegmentInformation & segment,
description_factory.pathDescription description_factory.pathDescription
) { ) {
TurnInstruction current_instruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; TurnInstruction current_instruction = segment.turn_instruction & TurnInstructions.InverseAccessRestrictionFlag;
entered_restricted_area_count += (current_instruction != segment.turnInstruction); entered_restricted_area_count += (current_instruction != segment.turn_instruction);
} }
} }
reply.content.push_back("],"); reply.content.push_back("],");
@ -203,8 +203,8 @@ public:
); );
} else { } else {
BOOST_FOREACH(const SegmentInformation & segment, alternateDescriptionFactory.pathDescription) { BOOST_FOREACH(const SegmentInformation & segment, alternateDescriptionFactory.pathDescription) {
TurnInstruction current_instruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; TurnInstruction current_instruction = segment.turn_instruction & TurnInstructions.InverseAccessRestrictionFlag;
entered_restricted_area_count += (current_instruction != segment.turnInstruction); entered_restricted_area_count += (current_instruction != segment.turn_instruction);
} }
} }
reply.content.push_back("]"); reply.content.push_back("]");
@ -383,11 +383,11 @@ public:
std::string tmpDist, tmpLength, tmpDuration, tmpBearing, tmpInstruction; std::string tmpDist, tmpLength, tmpDuration, tmpBearing, tmpInstruction;
//Fetch data from Factory and generate a string from it. //Fetch data from Factory and generate a string from it.
BOOST_FOREACH(const SegmentInformation & segment, description_factory.pathDescription) { BOOST_FOREACH(const SegmentInformation & segment, description_factory.pathDescription) {
TurnInstruction current_instruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; TurnInstruction current_instruction = segment.turn_instruction & TurnInstructions.InverseAccessRestrictionFlag;
entered_restricted_area_count += (current_instruction != segment.turnInstruction); entered_restricted_area_count += (current_instruction != segment.turn_instruction);
if(TurnInstructions.TurnIsNecessary( current_instruction) ) { if(TurnInstructions.TurnIsNecessary( current_instruction) ) {
if(TurnInstructions.EnterRoundAbout == current_instruction) { if(TurnInstructions.EnterRoundAbout == current_instruction) {
roundAbout.name_id = segment.nameID; roundAbout.name_id = segment.name_id;
roundAbout.start_index = prefixSumOfNecessarySegments; roundAbout.start_index = prefixSumOfNecessarySegments;
} else { } else {
if(0 != prefixSumOfNecessarySegments){ if(0 != prefixSumOfNecessarySegments){
@ -407,7 +407,7 @@ public:
} }
reply.content.push_back("\",\""); reply.content.push_back("\",\"");
reply.content.push_back(facade->GetEscapedNameForNameID(segment.nameID)); reply.content.push_back(facade->GetEscapedNameForNameID(segment.name_id));
reply.content.push_back("\","); reply.content.push_back("\",");
intToString(segment.length, tmpDist); intToString(segment.length, tmpDist);
reply.content.push_back(tmpDist); reply.content.push_back(tmpDist);
@ -421,15 +421,16 @@ public:
intToString(segment.length, tmpLength); intToString(segment.length, tmpLength);
reply.content.push_back(tmpLength); reply.content.push_back(tmpLength);
reply.content.push_back("m\",\""); reply.content.push_back("m\",\"");
reply.content.push_back(Azimuth::Get(segment.bearing)); double bearing_value = round(segment.bearing/10.);
reply.content.push_back(Azimuth::Get(bearing_value));
reply.content.push_back("\","); reply.content.push_back("\",");
intToString(round(segment.bearing), tmpBearing); intToString(bearing_value, tmpBearing);
reply.content.push_back(tmpBearing); reply.content.push_back(tmpBearing);
reply.content.push_back("]"); reply.content.push_back("]");
route_segments_list.push_back( route_segments_list.push_back(
Segment( Segment(
segment.nameID, segment.name_id,
segment.length, segment.length,
route_segments_list.size() route_segments_list.size()
) )