[core] Switch to ankerl::unordered_dense

Signed-off-by: x7z4w <x7z4w@noreply.codeberg.org>
This commit is contained in:
x7z4w
2025-11-24 17:34:56 +00:00
parent 046fe903d1
commit b4e9bbb8d2
303 changed files with 4506 additions and 1577 deletions

View File

@@ -20,9 +20,10 @@
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
@@ -46,8 +47,8 @@ struct CrossBorderSegment
double m_weight = 0.0;
};
using CrossBorderSegments = std::unordered_map<RegionSegmentId, CrossBorderSegment>;
using MwmIdToSegmentIds = std::unordered_map<NumMwmId, std::vector<RegionSegmentId>>;
using CrossBorderSegments = ankerl::unordered_dense::map<RegionSegmentId, CrossBorderSegment>;
using MwmIdToSegmentIds = ankerl::unordered_dense::map<NumMwmId, std::vector<RegionSegmentId>>;
struct CrossBorderGraph
{

View File

@@ -12,9 +12,10 @@
#include "base/buffer_vector.hpp"
#include <string>
#include <unordered_map>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
namespace connector
@@ -280,7 +281,7 @@ private:
};
std::vector<KeyTransitionT> m_transitions;
using MwmID2FeatureIDMapT = std::unordered_map<CrossMwmId, uint32_t, connector::HashKey>;
using MwmID2FeatureIDMapT = ankerl::unordered_dense::map<CrossMwmId, uint32_t, connector::HashKey>;
MwmID2FeatureIDMapT m_crossMwmIdToFeatureId;
// Weight is the time required for the route to pass edge, measured in seconds rounded upwards.

View File

@@ -8,7 +8,8 @@
#include "base/lru_cache.hpp"
#include <map>
#include <unordered_map>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
@@ -19,7 +20,7 @@ class MwmDataSource
{
DataSource & m_dataSource;
std::shared_ptr<NumMwmIds> m_numMwmIDs;
std::unordered_map<NumMwmId, MwmSet::MwmHandle> m_handles;
ankerl::unordered_dense::map<NumMwmId, MwmSet::MwmHandle> m_handles;
// Used for FeaturesRoadGraph in openlr only.
std::map<MwmSet::MwmId, MwmSet::MwmHandle> m_handles2;

View File

@@ -10,7 +10,8 @@
#include "geometry/point_with_altitude.hpp"
#include <memory>
#include <unordered_map>
#include "3party/ankerl/unordered_dense.h"
class DataSource;
@@ -64,7 +65,7 @@ public:
protected:
VehicleType const m_vehicleType;
double m_defaultPenalty = 0.0;
std::unordered_map<int, double> m_turnPenaltyMap;
ankerl::unordered_dense::map<int, double> m_turnPenaltyMap;
private:
double const m_maxWeightSpeedMpS;
@@ -72,7 +73,7 @@ private:
// DataSource * m_dataSourcePtr;
// std::shared_ptr<NumMwmIds> m_numMwmIds;
// std::unordered_map<NumMwmId, double> m_leapWeightSpeedMpS;
// ankerl::unordered_dense::map<NumMwmId, double> m_leapWeightSpeedMpS;
double ComputeDefaultLeapWeightSpeed() const;
double GetLeapWeightSpeed(NumMwmId mwmId);

View File

@@ -22,9 +22,10 @@
#include <memory>
#include <optional>
#include <unordered_map>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
bool IsUTurn(Segment const & u, Segment const & v);
@@ -42,7 +43,7 @@ public:
template <typename VertexType>
using Parents = typename AStarGraph<VertexType, void, void>::Parents;
using Restrictions = std::unordered_map<uint32_t, std::vector<std::vector<uint32_t>>>;
using Restrictions = ankerl::unordered_dense::map<uint32_t, std::vector<std::vector<uint32_t>>>;
using SegmentEdgeListT = SmallList<SegmentEdge>;
using JointEdgeListT = SmallList<JointEdge>;
@@ -203,7 +204,7 @@ private:
//
// If m_noUTurnRestrictions.count(featureId) == 0, that means, that there are no any
// no_u_turn restriction at the feature with id = featureId.
std::unordered_map<uint32_t, UTurnEnding> m_noUTurnRestrictions;
ankerl::unordered_dense::map<uint32_t, UTurnEnding> m_noUTurnRestrictions;
RoadAccess m_roadAccess;
RoadPenalty m_roadPenalty;
RoutingOptions m_avoidRoutingOptions;

View File

@@ -17,7 +17,8 @@
#include <algorithm>
#include <map>
#include <unordered_map>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
@@ -70,9 +71,9 @@ private:
// May be nullptr, because it has "lazy" loading.
GraphPtrT m_graph;
};
unordered_map<NumMwmId, GraphAttrs> m_graphs;
ankerl::unordered_dense::map<NumMwmId, GraphAttrs> m_graphs;
unordered_map<NumMwmId, SpeedCamerasMapT> m_cachedCameras;
ankerl::unordered_dense::map<NumMwmId, SpeedCamerasMapT> m_cachedCameras;
SpeedCamerasMapT const & ReceiveSpeedCamsFromMwm(NumMwmId numMwmId);
RoutingOptions m_avoidRoutingOptions;
@@ -189,7 +190,8 @@ bool ReadSpeedCamsFromMwm(MwmValue const & mwmValue, SpeedCamerasMapT & camerasM
}
catch (Reader::Exception const & e)
{
LOG(LERROR, ("Error while reading", CAMERAS_INFO_FILE_TAG, "section in", mwmValue.GetCountryFileName(), ":", e.Msg()));
LOG(LERROR,
("Error while reading", CAMERAS_INFO_FILE_TAG, "section in", mwmValue.GetCountryFileName(), ":", e.Msg()));
}
return false;
}
@@ -209,7 +211,8 @@ bool ReadRoadAccessFromMwm(MwmValue const & mwmValue, VehicleType vehicleType, R
}
catch (Reader::Exception const & e)
{
LOG(LERROR, ("Error while reading", ROAD_ACCESS_FILE_TAG, "section in", mwmValue.GetCountryFileName(), ":", e.Msg()));
LOG(LERROR,
("Error while reading", ROAD_ACCESS_FILE_TAG, "section in", mwmValue.GetCountryFileName(), ":", e.Msg()));
}
return false;
}
@@ -239,11 +242,13 @@ bool ReadRoadPenaltyFromMwm(MwmValue const & mwmValue, VehicleType vehicleType,
catch (Reader::OpenException const &)
{
// This is expected for older mwm files - not an error
LOG(LINFO, (ROAD_PENALTY_FILE_TAG, "section not found in", mwmValue.GetCountryFileName(), "- using legacy penalty system"));
LOG(LINFO, (ROAD_PENALTY_FILE_TAG, "section not found in", mwmValue.GetCountryFileName(),
"- using legacy penalty system"));
}
catch (Reader::Exception const & e)
{
LOG(LERROR, ("Error while reading", ROAD_PENALTY_FILE_TAG, "section in", mwmValue.GetCountryFileName(), ":", e.Msg()));
LOG(LERROR,
("Error while reading", ROAD_PENALTY_FILE_TAG, "section in", mwmValue.GetCountryFileName(), ":", e.Msg()));
}
return false;
}

View File

@@ -8,9 +8,9 @@ uint32_t constexpr IndexGraphSerializer::JointsFilter::kEmptyEntry;
uint32_t constexpr IndexGraphSerializer::JointsFilter::kPushedEntry;
// IndexGraphSerializer::SectionSerializer ---------------------------------------------------------
void IndexGraphSerializer::SectionSerializer::PreSerialize(IndexGraph const & graph,
std::unordered_map<uint32_t, VehicleMask> const & masks,
JointIdEncoder & jointEncoder)
void IndexGraphSerializer::SectionSerializer::PreSerialize(
IndexGraph const & graph, ankerl::unordered_dense::map<uint32_t, VehicleMask> const & masks,
JointIdEncoder & jointEncoder)
{
m_buffer.clear();
MemWriter<std::vector<uint8_t>> memWriter(m_buffer);
@@ -65,7 +65,7 @@ void IndexGraphSerializer::JointsFilter::Push(Joint::Id jointIdInFile, RoadPoint
// IndexGraphSerializer ----------------------------------------------------------------------------
// static
VehicleMask IndexGraphSerializer::GetRoadMask(std::unordered_map<uint32_t, VehicleMask> const & masks,
VehicleMask IndexGraphSerializer::GetRoadMask(ankerl::unordered_dense::map<uint32_t, VehicleMask> const & masks,
uint32_t featureId)
{
auto const & it = masks.find(featureId);
@@ -90,7 +90,7 @@ uint32_t IndexGraphSerializer::ConvertJointsNumber(uint32_t jointsNumber)
// static
void IndexGraphSerializer::PrepareSectionSerializers(IndexGraph const & graph,
std::unordered_map<uint32_t, VehicleMask> const & masks,
ankerl::unordered_dense::map<uint32_t, VehicleMask> const & masks,
std::vector<SectionSerializer> & serializers)
{
size_t maskToIndex[kNumVehicleMasks] = {};

View File

@@ -14,9 +14,10 @@
#include <limits>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
class IndexGraphSerializer final
@@ -25,7 +26,8 @@ public:
IndexGraphSerializer() = delete;
template <class Sink>
static void Serialize(IndexGraph const & graph, std::unordered_map<uint32_t, VehicleMask> const & masks, Sink & sink)
static void Serialize(IndexGraph const & graph, ankerl::unordered_dense::map<uint32_t, VehicleMask> const & masks,
Sink & sink)
{
Header header(graph);
JointIdEncoder jointEncoder;
@@ -278,7 +280,7 @@ private:
private:
Joint::Id m_count = 0;
std::unordered_map<Joint::Id, Joint::Id> m_convertedIds;
ankerl::unordered_dense::map<Joint::Id, Joint::Id> m_convertedIds;
};
class JointIdDecoder final
@@ -364,7 +366,7 @@ private:
void AddRoad(uint32_t featureId) { m_featureIds.push_back(featureId); }
void SortRoads() { sort(m_featureIds.begin(), m_featureIds.end()); }
void PreSerialize(IndexGraph const & graph, std::unordered_map<uint32_t, VehicleMask> const & masks,
void PreSerialize(IndexGraph const & graph, ankerl::unordered_dense::map<uint32_t, VehicleMask> const & masks,
JointIdEncoder & jointEncoder);
template <class Sink>
@@ -380,10 +382,10 @@ private:
std::vector<uint8_t> m_buffer;
};
static VehicleMask GetRoadMask(std::unordered_map<uint32_t, VehicleMask> const & masks, uint32_t featureId);
static VehicleMask GetRoadMask(ankerl::unordered_dense::map<uint32_t, VehicleMask> const & masks, uint32_t featureId);
static uint32_t ConvertJointsNumber(uint32_t jointsNumber);
static void PrepareSectionSerializers(IndexGraph const & graph,
std::unordered_map<uint32_t, VehicleMask> const & masks,
ankerl::unordered_dense::map<uint32_t, VehicleMask> const & masks,
std::vector<SectionSerializer> & sections);
};
} // namespace routing

View File

@@ -10,14 +10,14 @@
#include "base/assert.hpp"
#include "3party/skarupke/bytell_hash_map.hpp" // needed despite of IDE warning
#include <algorithm>
#include <map>
#include <optional>
#include <queue>
#include <vector>
#include "3party/skarupke/bytell_hash_map.hpp" // needed despite of IDE warning
namespace routing
{
enum class WorldGraphMode;

View File

@@ -10,9 +10,9 @@
#include "coding/simple_dense_coding.hpp"
#include <memory>
#include <unordered_map>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
#include "3party/succinct/elias_fano.hpp"
namespace routing
@@ -50,7 +50,7 @@ private:
static int constexpr DEFAULT_SPEEDS_COUNT = 2;
// Default speeds (KmPerH) for MWM, 0 - outside a city, 1 - inside a city.
std::unordered_map<HighwayType, MaxspeedType> m_defaultSpeeds[DEFAULT_SPEEDS_COUNT];
ankerl::unordered_dense::map<HighwayType, MaxspeedType> m_defaultSpeeds[DEFAULT_SPEEDS_COUNT];
};
std::unique_ptr<Maxspeeds> LoadMaxspeeds(MwmSet::MwmHandle const & handle);

View File

@@ -1,6 +1,6 @@
#include "routing/mwm_hierarchy_handler.hpp"
#include <unordered_set>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
@@ -11,7 +11,7 @@ namespace
// passport and other types of border control at their mutual borders.
inline size_t constexpr kCrossCountryPenaltyS = 60 * 60 * 2;
using CountrySetT = std::unordered_set<std::string_view>;
using CountrySetT = ankerl::unordered_dense::set<std::string_view>;
// The Eurasian Economic Union (EAEU) list of countries.
CountrySetT kEAEU = {"Armenia", "Belarus", "Kazakhstan", "Kyrgyzstan", "Russian Federation"};

View File

@@ -7,7 +7,8 @@
#include <memory>
#include <string>
#include <unordered_map>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
@@ -33,7 +34,7 @@ private:
std::shared_ptr<NumMwmIds> m_numMwmIds;
CountryParentNameGetterFn m_countryParentNameGetterFn;
using MwmToCountry = std::unordered_map<NumMwmId, std::string>;
using MwmToCountry = ankerl::unordered_dense::map<NumMwmId, std::string>;
MwmToCountry m_mwmCountriesCache;
};
} // namespace routing

View File

@@ -134,7 +134,7 @@ void RegionsRouter::Do()
}
}
std::unordered_set<std::string> const & RegionsRouter::GetMwmNames() const
ankerl::unordered_dense::set<std::string> const & RegionsRouter::GetMwmNames() const
{
return m_mwmNames;
}

View File

@@ -7,10 +7,11 @@
#include "base/thread.hpp"
#include <unordered_set>
#include <utility>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
class IndexGraphStarter;
@@ -25,7 +26,7 @@ public:
void Do() override;
std::unordered_set<std::string> const & GetMwmNames() const;
ankerl::unordered_dense::set<std::string> const & GetMwmNames() const;
private:
template <typename Vertex, typename Edge, typename Weight>
@@ -42,7 +43,7 @@ private:
std::shared_ptr<NumMwmIds> m_numMwmIds;
DataSource & m_dataSource;
Checkpoints const m_checkpoints;
std::unordered_set<std::string> m_mwmNames;
ankerl::unordered_dense::set<std::string> m_mwmNames;
RouterDelegate const & m_delegate;
};

View File

@@ -14,10 +14,11 @@
#include <algorithm>
#include <cstdint>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
/// \brief Restriction to modify road graph.
@@ -123,7 +124,7 @@ struct RestrictionHeader
uint16_t m_version;
uint16_t m_reserved;
std::unordered_map<Restriction::Type, uint32_t> m_restrictionCount;
ankerl::unordered_dense::map<Restriction::Type, uint32_t> m_restrictionCount;
};
class RestrictionSerializer

View File

@@ -7,10 +7,11 @@
#include <algorithm>
#include <cstdint>
#include <unordered_map>
#include <utility>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
class RoadJointIds final
@@ -158,6 +159,6 @@ public:
private:
// Map from feature id to RoadJointIds.
std::unordered_map<uint32_t, RoadJointIds> m_roads;
ankerl::unordered_dense::map<uint32_t, RoadJointIds> m_roads;
};
} // namespace routing

View File

@@ -29,9 +29,10 @@
#include <algorithm>
#include <cstdint>
#include <memory>
#include <unordered_map>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
namespace index_graph_test
{
using namespace routing;
@@ -516,7 +517,7 @@ UNIT_TEST(SerializeSimpleGraph)
MakeJoint({{1, 1}, {2, 0}}),
};
graph.Import(joints);
unordered_map<uint32_t, VehicleMask> masks;
ankerl::unordered_dense::map<uint32_t, VehicleMask> masks;
masks[0] = kPedestrianMask;
masks[1] = kCarMask;
masks[2] = kCarMask;

View File

@@ -12,7 +12,7 @@
#include "base/assert.hpp"
#include "base/math.hpp"
#include <unordered_map>
#include "3party/ankerl/unordered_dense.h"
namespace routing_test
{
@@ -21,7 +21,7 @@ using namespace std;
double constexpr kEpsilon = 1e-6;
template <typename Graph>
Graph & GetGraph(unordered_map<NumMwmId, unique_ptr<Graph>> const & graphs, NumMwmId mwmId)
Graph & GetGraph(ankerl::unordered_dense::map<NumMwmId, unique_ptr<Graph>> const & graphs, NumMwmId mwmId)
{
auto it = graphs.find(mwmId);
CHECK(it != graphs.end(), ("Not found graph for mwm", mwmId));
@@ -29,7 +29,8 @@ Graph & GetGraph(unordered_map<NumMwmId, unique_ptr<Graph>> const & graphs, NumM
}
template <typename Graph>
void AddGraph(unordered_map<NumMwmId, unique_ptr<Graph>> & graphs, NumMwmId mwmId, unique_ptr<Graph> graph)
void AddGraph(ankerl::unordered_dense::map<NumMwmId, unique_ptr<Graph>> & graphs, NumMwmId mwmId,
unique_ptr<Graph> graph)
{
auto it = graphs.find(mwmId);
CHECK(it == graphs.end(), ("Already contains graph for mwm", mwmId));

View File

@@ -23,9 +23,10 @@
#include <map>
#include <memory>
#include <unordered_map>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
namespace routing_test
{
using namespace routing;
@@ -124,7 +125,7 @@ public:
void AddGraph(NumMwmId mwmId, std::unique_ptr<IndexGraph> graph);
private:
std::unordered_map<NumMwmId, std::unique_ptr<IndexGraph>> m_graphs;
ankerl::unordered_dense::map<NumMwmId, std::unique_ptr<IndexGraph>> m_graphs;
};
class TestTransitGraphLoader : public TransitGraphLoader
@@ -139,7 +140,7 @@ public:
void AddGraph(NumMwmId mwmId, std::unique_ptr<TransitGraph> graph);
private:
std::unordered_map<NumMwmId, std::unique_ptr<TransitGraph>> m_graphs;
ankerl::unordered_dense::map<NumMwmId, std::unique_ptr<TransitGraph>> m_graphs;
};
// An estimator that uses the information from the supported |segmentWeights| map

View File

@@ -7,15 +7,11 @@
namespace
{
using CountrySetT = std::unordered_set<std::string_view>;
using CountrySetT = ankerl::unordered_dense::set<std::string_view>;
// List of country names where mwm should be generated without speed cameras.
CountrySetT kSpeedCamerasProhibitedCountries = {
"Germany",
"Macedonia",
"Switzerland",
"Turkey",
"Bosnia and Herzegovina",
"Germany", "Macedonia", "Switzerland", "Turkey", "Bosnia and Herzegovina",
};
// List of country names where an end user should be warned about speed cameras.

View File

@@ -12,9 +12,10 @@
#include "base/assert.hpp"
#include <memory>
#include <unordered_map>
#include <utility>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
class TrafficStash final
@@ -52,6 +53,6 @@ private:
traffic::TrafficCache const & m_source;
std::shared_ptr<NumMwmIds> m_numMwmIds;
std::unordered_map<NumMwmId, std::shared_ptr<traffic::TrafficInfo::Coloring const>> m_mwmToTraffic;
ankerl::unordered_dense::map<NumMwmId, std::shared_ptr<traffic::TrafficInfo::Coloring const>> m_mwmToTraffic;
};
} // namespace routing

View File

@@ -17,9 +17,10 @@
#include "base/timer.hpp"
#include <memory>
#include <unordered_map>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
namespace routing
{
class TransitGraphLoaderImpl : public TransitGraphLoader
@@ -106,7 +107,7 @@ private:
MwmDataSource & m_dataSource;
std::shared_ptr<EdgeEstimator> m_estimator;
std::unordered_map<NumMwmId, std::unique_ptr<TransitGraph>> m_graphs;
ankerl::unordered_dense::map<NumMwmId, std::unique_ptr<TransitGraph>> m_graphs;
};
// static

View File

@@ -14,7 +14,8 @@ using namespace ftypes;
bool IsHighway(HighwayClass hwClass, bool isLink)
{
return (hwClass == HighwayClass::Motorway || hwClass == HighwayClass::Trunk || hwClass == HighwayClass::Primary) && !isLink;
return (hwClass == HighwayClass::Motorway || hwClass == HighwayClass::Trunk || hwClass == HighwayClass::Primary) &&
!isLink;
}
bool IsSmallRoad(HighwayClass hwClass)