Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2018-03-26 15:15:26 +0300
committerTatiana Yan <tatiana.kondakova@gmail.com>2018-03-27 12:53:15 +0300
commit48cdf4405762fd43a7c478025fd5e6840830abea (patch)
tree9e89610688d731436a112827bf99713e9028b23c /routing
parentc6cb6e0065a4c170d4f080b51f0a0596817dbe45 (diff)
Reducing RoutingWeight size from 24 bytes to 16 bytes.
Diffstat (limited to 'routing')
-rw-r--r--routing/cross_mwm_connector.hpp1
-rw-r--r--routing/index_graph_starter.cpp2
-rw-r--r--routing/route_weight.cpp13
-rw-r--r--routing/route_weight.hpp35
4 files changed, 25 insertions, 26 deletions
diff --git a/routing/cross_mwm_connector.hpp b/routing/cross_mwm_connector.hpp
index 876d08bcf3..cec680a002 100644
--- a/routing/cross_mwm_connector.hpp
+++ b/routing/cross_mwm_connector.hpp
@@ -264,6 +264,7 @@ private:
void AddEdge(Segment const & segment, connector::Weight weight,
std::vector<SegmentEdge> & edges) const
{
+ // @TODO Double and uint32_t are compared below. This comparison should be fixed.
if (weight != connector::kNoRoute)
edges.emplace_back(segment, RouteWeight::FromCrossMwmWeight(weight));
}
diff --git a/routing/index_graph_starter.cpp b/routing/index_graph_starter.cpp
index fc42001cb8..4a58e7787c 100644
--- a/routing/index_graph_starter.cpp
+++ b/routing/index_graph_starter.cpp
@@ -150,7 +150,7 @@ bool IndexGraphStarter::CheckLength(RouteWeight const & weight)
{
// We allow 1 pass-through/non-pass-through zone changes per ending located in
// non-pass-through zone to allow user to leave this zone.
- int32_t const numPassThroughChangesAllowed =
+ int8_t const numPassThroughChangesAllowed =
(StartPassThroughAllowed() ? 0 : 1) + (FinishPassThroughAllowed() ? 0 : 1);
return weight.GetNumPassThroughChanges() <= numPassThroughChangesAllowed &&
diff --git a/routing/route_weight.cpp b/routing/route_weight.cpp
index 0e6e50f2c2..e1a53adb0d 100644
--- a/routing/route_weight.cpp
+++ b/routing/route_weight.cpp
@@ -41,11 +41,11 @@ RouteWeight RouteWeight::operator+(RouteWeight const & rhs) const
RouteWeight RouteWeight::operator-(RouteWeight const & rhs) const
{
- ASSERT_NOT_EQUAL(m_numPassThroughChanges, std::numeric_limits<int32_t>::min(), ());
- ASSERT_NOT_EQUAL(m_numAccessChanges, std::numeric_limits<int32_t>::min(), ());
- ASSERT(!SumWillOverflow(m_numPassThroughChanges, -rhs.m_numPassThroughChanges),
+ ASSERT_NOT_EQUAL(m_numPassThroughChanges, numeric_limits<int8_t>::min(), ());
+ ASSERT_NOT_EQUAL(m_numAccessChanges, numeric_limits<int8_t>::min(), ());
+ ASSERT(!SumWillOverflow(m_numPassThroughChanges, static_cast<int8_t>(-rhs.m_numPassThroughChanges)),
(m_numPassThroughChanges, -rhs.m_numPassThroughChanges));
- ASSERT(!SumWillOverflow(m_numAccessChanges, -rhs.m_numAccessChanges),
+ ASSERT(!SumWillOverflow(m_numAccessChanges, static_cast<int8_t>(-rhs.m_numAccessChanges)),
(m_numAccessChanges, -rhs.m_numAccessChanges));
return RouteWeight(m_weight - rhs.m_weight, m_numPassThroughChanges - rhs.m_numPassThroughChanges,
m_numAccessChanges - rhs.m_numAccessChanges,
@@ -67,8 +67,9 @@ RouteWeight & RouteWeight::operator+=(RouteWeight const & rhs)
ostream & operator<<(ostream & os, RouteWeight const & routeWeight)
{
- os << "(" << routeWeight.GetNumPassThroughChanges() << ", " << routeWeight.GetNumAccessChanges()
- << ", " << routeWeight.GetWeight() << ", " << routeWeight.GetTransitTime() << ")";
+ os << "(" << static_cast<int32_t>(routeWeight.GetNumPassThroughChanges()) << ", "
+ << static_cast<int32_t>(routeWeight.GetNumAccessChanges()) << ", " << routeWeight.GetWeight()
+ << ", " << routeWeight.GetTransitTime() << ")";
return os;
}
diff --git a/routing/route_weight.hpp b/routing/route_weight.hpp
index 1d057cc269..b5a83ac1d4 100644
--- a/routing/route_weight.hpp
+++ b/routing/route_weight.hpp
@@ -20,9 +20,9 @@ public:
constexpr RouteWeight(double weight, int32_t numPassThroughChanges, int32_t numAccessChanges,
double transitTime)
: m_weight(weight)
- , m_numPassThroughChanges(numPassThroughChanges)
- , m_numAccessChanges(numAccessChanges)
- , m_transitTime(transitTime)
+ , m_numPassThroughChanges(static_cast<int8_t>(numPassThroughChanges))
+ , m_numAccessChanges(static_cast<int8_t>(numAccessChanges))
+ , m_transitTime(static_cast<float>(transitTime))
{
}
@@ -30,9 +30,9 @@ public:
double ToCrossMwmWeight() const;
double GetWeight() const { return m_weight; }
- int32_t GetNumPassThroughChanges() const { return m_numPassThroughChanges; }
- int32_t GetNumAccessChanges() const { return m_numAccessChanges; }
- double GetTransitTime() const { return m_transitTime; }
+ int8_t GetNumPassThroughChanges() const { return m_numPassThroughChanges; }
+ int8_t GetNumAccessChanges() const { return m_numAccessChanges; }
+ double GetTransitTime() const { return static_cast<double>(m_transitTime); }
bool operator<(RouteWeight const & rhs) const
{
@@ -70,8 +70,8 @@ public:
RouteWeight operator-() const
{
- ASSERT_NOT_EQUAL(m_numPassThroughChanges, std::numeric_limits<int32_t>::min(), ());
- ASSERT_NOT_EQUAL(m_numAccessChanges, std::numeric_limits<int32_t>::min(), ());
+ ASSERT_NOT_EQUAL(m_numPassThroughChanges, std::numeric_limits<int8_t>::min(), ());
+ ASSERT_NOT_EQUAL(m_numAccessChanges, std::numeric_limits<int8_t>::min(), ());
return RouteWeight(-m_weight, -m_numPassThroughChanges, -m_numAccessChanges, -m_transitTime);
}
@@ -80,21 +80,18 @@ public:
return m_numPassThroughChanges == rhs.m_numPassThroughChanges &&
m_numAccessChanges == rhs.m_numAccessChanges &&
my::AlmostEqualAbs(m_weight, rhs.m_weight, epsilon) &&
- my::AlmostEqualAbs(m_transitTime, rhs.m_transitTime, epsilon);
+ my::AlmostEqualAbs(m_transitTime, rhs.m_transitTime, static_cast<float>(epsilon));
}
private:
- // Note: consider smaller types for m_numPassThroughChanges and m_numAccessChanges
- // in case of adding new fields to RouteWeight to reduce RouteWeight size.
-
// Regular weight (seconds).
double m_weight = 0.0;
// Number of pass-through/non-pass-through zone changes.
- int32_t m_numPassThroughChanges = 0;
+ int8_t m_numPassThroughChanges = 0;
// Number of access=yes/access={private,destination} zone changes.
- int32_t m_numAccessChanges = 0;
+ int8_t m_numAccessChanges = 0;
// Transit time. It's already included in |m_weight| (m_transitTime <= m_weight).
- double m_transitTime = 0.0;
+ float m_transitTime = 0.0F;
};
std::ostream & operator<<(std::ostream & os, RouteWeight const & routeWeight);
@@ -104,10 +101,10 @@ RouteWeight operator*(double lhs, RouteWeight const & rhs);
template <>
constexpr RouteWeight GetAStarWeightMax<RouteWeight>()
{
- return RouteWeight(std::numeric_limits<double>::max() /* weight */,
- std::numeric_limits<int32_t>::max() /* numPassThroughChanges */,
- std::numeric_limits<int32_t>::max() /* numAccessChanges */,
- 0 /* transitTime */); // operator< prefers bigger transit time
+ return RouteWeight(std::numeric_limits<float>::max() /* weight */,
+ std::numeric_limits<int8_t>::max() /* numPassThroughChanges */,
+ std::numeric_limits<int8_t>::max() /* numAccessChanges */,
+ 0.0 /* transitTime */); // operator< prefers bigger transit time
}
template <>