From dae9c9a7ed9699580bab9138b6d7f79571aea1c8 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Mon, 11 Aug 2014 14:07:00 +0200 Subject: [PATCH] use 4 bits for travel mode --- DataStructures/EdgeBasedNode.h | 6 +++--- DataStructures/ImportEdge.h | 2 +- DataStructures/NodeBasedGraph.h | 2 +- DataStructures/PhantomNodes.h | 4 ++-- DataStructures/RawRouteData.h | 2 +- DataStructures/SegmentInformation.h | 2 +- Extractor/ExtractionContainers.cpp | 6 +++++- Extractor/ExtractionWay.h | 10 ++++++++-- Extractor/InternalExtractorEdge.h | 2 +- Extractor/ScriptingEnvironment.cpp | 4 ++-- Server/DataStructures/InternalDataFacade.h | 1 - Util/GraphLoader.h | 3 --- 12 files changed, 25 insertions(+), 19 deletions(-) diff --git a/DataStructures/EdgeBasedNode.h b/DataStructures/EdgeBasedNode.h index ae1ca579e..f433ddbca 100644 --- a/DataStructures/EdgeBasedNode.h +++ b/DataStructures/EdgeBasedNode.h @@ -43,7 +43,7 @@ struct EdgeBasedNode unsigned packed_geometry_id, unsigned short fwd_segment_position, bool belongs_to_tiny_component, - TravelMode travel_mode, + TravelMode travel_mode , TravelMode backward_travel_mode ) : forward_edge_based_node_id(forward_edge_based_node_id), @@ -91,8 +91,8 @@ struct EdgeBasedNode unsigned packed_geometry_id; // if set, then the edge represents a packed geometry unsigned short fwd_segment_position; // segment id in a compressed geometry bool is_in_tiny_cc; - TravelMode travel_mode; - TravelMode backward_travel_mode; + TravelMode travel_mode : 4; + TravelMode backward_travel_mode : 4; }; #endif //EDGE_BASED_NODE_H diff --git a/DataStructures/ImportEdge.h b/DataStructures/ImportEdge.h index 761cf386e..20c277318 100644 --- a/DataStructures/ImportEdge.h +++ b/DataStructures/ImportEdge.h @@ -58,7 +58,7 @@ struct NodeBasedEdge bool in_tiny_cc : 1; bool access_restricted : 1; bool is_split : 1; - TravelMode travel_mode; + TravelMode travel_mode : 4; NodeBasedEdge() = delete; }; diff --git a/DataStructures/NodeBasedGraph.h b/DataStructures/NodeBasedGraph.h index 77c5251e5..376c8ffae 100644 --- a/DataStructures/NodeBasedGraph.h +++ b/DataStructures/NodeBasedGraph.h @@ -29,7 +29,7 @@ struct NodeBasedEdgeData bool backward : 1; bool roundabout : 1; bool ignore_in_grid : 1; - TravelMode travel_mode; + TravelMode travel_mode : 4; void SwapDirectionFlags() { diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 66e97d61a..c1598df9b 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -79,8 +79,8 @@ struct PhantomNode unsigned packed_geometry_id; FixedPointCoordinate location; unsigned short fwd_segment_position; - TravelMode travel_mode; - TravelMode backward_travel_mode; + TravelMode travel_mode : 4; + TravelMode backward_travel_mode : 4; int GetForwardWeightPlusOffset() const { diff --git a/DataStructures/RawRouteData.h b/DataStructures/RawRouteData.h index 3a7d1e871..b48b62f3c 100644 --- a/DataStructures/RawRouteData.h +++ b/DataStructures/RawRouteData.h @@ -59,7 +59,7 @@ struct PathData unsigned name_id; EdgeWeight segment_duration; TurnInstruction turn_instruction; - TravelMode travel_mode; + TravelMode travel_mode : 4; }; struct RawRouteData diff --git a/DataStructures/SegmentInformation.h b/DataStructures/SegmentInformation.h index df3bfbaed..fe1704a92 100644 --- a/DataStructures/SegmentInformation.h +++ b/DataStructures/SegmentInformation.h @@ -45,7 +45,7 @@ struct SegmentInformation TurnInstruction turn_instruction; bool necessary:1; bool is_via_location:1; - TravelMode travel_mode; + TravelMode travel_mode : 4; explicit SegmentInformation(const FixedPointCoordinate &location, const NodeID name_id, diff --git a/Extractor/ExtractionContainers.cpp b/Extractor/ExtractionContainers.cpp index 23ef88af6..9a88a56ac 100644 --- a/Extractor/ExtractionContainers.cpp +++ b/Extractor/ExtractionContainers.cpp @@ -376,7 +376,11 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, file_out_stream.write((char *)&edge_iterator->is_roundabout, sizeof(bool)); file_out_stream.write((char *)&edge_iterator->is_in_tiny_cc, sizeof(bool)); file_out_stream.write((char *)&edge_iterator->is_access_restricted, sizeof(bool)); - file_out_stream.write((char *)&edge_iterator->travel_mode, sizeof(TravelMode)); + + // cannot take adress of bit field, so use local + const TravelMode travel_mode = edge_iterator->travel_mode; + file_out_stream.write((char *)&travel_mode, sizeof(TravelMode)); + file_out_stream.write((char *)&edge_iterator->is_split, sizeof(bool)); ++number_of_used_edges; } diff --git a/Extractor/ExtractionWay.h b/Extractor/ExtractionWay.h index b5698849f..158aef6d4 100644 --- a/Extractor/ExtractionWay.h +++ b/Extractor/ExtractionWay.h @@ -63,6 +63,7 @@ struct ExtractionWay bidirectional, opposite }; + inline bool HasDuration() { return duration>0; } inline bool IsBidirectional() { return travel_mode!=0 && backward_travel_mode!=0; } inline bool IsOneway() { return travel_mode!=0 && backward_travel_mode==0; } inline bool IsOpposite() { return travel_mode==0 && backward_travel_mode!=0; } @@ -78,6 +79,11 @@ struct ExtractionWay return ExtractionWay::bidirectional; } + inline void set_mode(const TravelMode m) { travel_mode = m; } + inline const TravelMode get_mode() { return travel_mode; } + inline void set_backward_mode(const TravelMode m) { backward_travel_mode = m; } + inline const TravelMode get_backward_mode() { return backward_travel_mode; } + unsigned id; unsigned nameID; double speed; @@ -92,8 +98,8 @@ struct ExtractionWay bool ignoreInGrid; std::vector path; HashTable keyVals; - TravelMode travel_mode; - TravelMode backward_travel_mode; + TravelMode travel_mode : 4; + TravelMode backward_travel_mode : 4; }; #endif // EXTRACTION_WAY_H diff --git a/Extractor/InternalExtractorEdge.h b/Extractor/InternalExtractorEdge.h index 492367f28..104d23c05 100644 --- a/Extractor/InternalExtractorEdge.h +++ b/Extractor/InternalExtractorEdge.h @@ -83,7 +83,7 @@ struct InternalExtractorEdge bool is_in_tiny_cc; bool is_duration_set; bool is_access_restricted; - TravelMode travel_mode; + TravelMode travel_mode : 4; bool is_split; FixedPointCoordinate source_coordinate; diff --git a/Extractor/ScriptingEnvironment.cpp b/Extractor/ScriptingEnvironment.cpp index 084d22ffd..d56b7b45f 100644 --- a/Extractor/ScriptingEnvironment.cpp +++ b/Extractor/ScriptingEnvironment.cpp @@ -86,8 +86,8 @@ void ScriptingEnvironment::initLuaState(lua_State* lua_state) .def_readwrite("ignore_in_grid", &ExtractionWay::ignoreInGrid) .def_readwrite("tags", &ExtractionWay::keyVals) .def_readwrite("direction", &ExtractionWay::direction) - .def_readwrite("mode", &ExtractionWay::travel_mode) - .def_readwrite("backward_mode", &ExtractionWay::backward_travel_mode) + .property("mode", &ExtractionWay::get_mode, &ExtractionWay::set_mode) + .property("backward_mode", &ExtractionWay::get_backward_mode, &ExtractionWay::set_backward_mode) .enum_("constants")[ luabind::value("notSure", 0), luabind::value("oneway", 1), diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 33a8caa5b..5f0a2517b 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -155,7 +155,6 @@ template class InternalDataFacade : public BaseDataFacade 0, "loaded null length edge"); BOOST_ASSERT_MSG(weight > 0, "loaded null weight"); BOOST_ASSERT_MSG(0 <= dir && dir <= 2, "loaded bogus direction");