[ABSL] Use flat_hash_map instead of unordered_map. (#1439)

master
Alexander Belyaev 2018-10-08 10:47:28 +02:00 committed by GitHub
parent 8285673abb
commit bdb6f2db4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 33 additions and 29 deletions

View File

@ -256,9 +256,9 @@ def cartographer_repositories():
_maybe(native.http_archive, _maybe(native.http_archive,
name = "com_google_absl", name = "com_google_absl",
sha256 = "387cf016ab1ab8530d1cea8975276ce8d8bff355133776129bdc400d05519eb6", sha256 = "c8ba586a9ab12bc4a67bb419fc0d2146200942b072bac95f50490f977b7fb04f",
strip_prefix = "abseil-cpp-44aa275286baf97fc13529aca547a88b180beb08", strip_prefix = "abseil-cpp-5441bbe1db5d0f2ca24b5b60166367b0966790af",
urls = ["https://github.com/abseil/abseil-cpp/archive/44aa275286baf97fc13529aca547a88b180beb08.tar.gz"], urls = ["https://github.com/abseil/abseil-cpp/archive/5441bbe1db5d0f2ca24b5b60166367b0966790af.tar.gz"],
) )
# TODO(rodrigoq): remove these binds once grpc#14140 has been merged, as well # TODO(rodrigoq): remove these binds once grpc#14140 has been merged, as well

View File

@ -97,6 +97,7 @@ cc_library(
"@boost//:iostreams", "@boost//:iostreams",
"@com_google_absl//absl/base", "@com_google_absl//absl/base",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/synchronization", "@com_google_absl//absl/synchronization",
"@com_google_absl//absl/types:optional", "@com_google_absl//absl/types:optional",
"@com_google_glog//:glog", "@com_google_glog//:glog",

View File

@ -20,6 +20,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "absl/container/flat_hash_map.h"
#include "async_grpc/rpc_handler.h" #include "async_grpc/rpc_handler.h"
#include "cartographer/cloud/proto/map_builder_service.pb.h" #include "cartographer/cloud/proto/map_builder_service.pb.h"
#include "cartographer/metrics/counter.h" #include "cartographer/metrics/counter.h"
@ -59,7 +60,7 @@ class AddSensorDataBatchHandler
counter_metrics_family_; counter_metrics_family_;
// Holds individual metrics for each client. // Holds individual metrics for each client.
std::unordered_map<std::string, std::unique_ptr<ClientMetrics>> absl::flat_hash_map<std::string, std::unique_ptr<ClientMetrics>>
client_metric_map_; client_metric_map_;
}; };

View File

@ -14,10 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
#include <unordered_map>
#include "cartographer/cloud/metrics/prometheus/family_factory.h" #include "cartographer/cloud/metrics/prometheus/family_factory.h"
#include "absl/container/flat_hash_map.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "prometheus/counter.h" #include "prometheus/counter.h"
#include "prometheus/family.h" #include "prometheus/family.h"
@ -76,7 +75,7 @@ class CounterFamily
private: private:
::prometheus::Family<::prometheus::Counter>* prometheus_; ::prometheus::Family<::prometheus::Counter>* prometheus_;
std::mutex wrappers_mutex_; std::mutex wrappers_mutex_;
std::unordered_map<::prometheus::Counter*, std::unique_ptr<Counter>> absl::flat_hash_map<::prometheus::Counter*, std::unique_ptr<Counter>>
wrappers_; wrappers_;
}; };
@ -108,7 +107,7 @@ class GaugeFamily
private: private:
::prometheus::Family<::prometheus::Gauge>* prometheus_; ::prometheus::Family<::prometheus::Gauge>* prometheus_;
std::mutex wrappers_mutex_; std::mutex wrappers_mutex_;
std::unordered_map<::prometheus::Gauge*, std::unique_ptr<Gauge>> wrappers_; absl::flat_hash_map<::prometheus::Gauge*, std::unique_ptr<Gauge>> wrappers_;
}; };
class Histogram : public ::cartographer::metrics::Histogram { class Histogram : public ::cartographer::metrics::Histogram {
@ -137,7 +136,7 @@ class HistogramFamily : public ::cartographer::metrics::Family<
private: private:
::prometheus::Family<::prometheus::Histogram>* prometheus_; ::prometheus::Family<::prometheus::Histogram>* prometheus_;
std::mutex wrappers_mutex_; std::mutex wrappers_mutex_;
std::unordered_map<::prometheus::Histogram*, std::unique_ptr<Histogram>> absl::flat_hash_map<::prometheus::Histogram*, std::unique_ptr<Histogram>>
wrappers_; wrappers_;
const BucketBoundaries boundaries_; const BucketBoundaries boundaries_;
}; };

View File

@ -21,9 +21,9 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <thread> #include <thread>
#include <unordered_map>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/synchronization/mutex.h" #include "absl/synchronization/mutex.h"
#include "cartographer/common/task.h" #include "cartographer/common/task.h"
@ -76,7 +76,7 @@ class ThreadPool : public ThreadPoolInterface {
bool running_ GUARDED_BY(mutex_) = true; bool running_ GUARDED_BY(mutex_) = true;
std::vector<std::thread> pool_ GUARDED_BY(mutex_); std::vector<std::thread> pool_ GUARDED_BY(mutex_);
std::deque<std::shared_ptr<Task>> task_queue_ GUARDED_BY(mutex_); std::deque<std::shared_ptr<Task>> task_queue_ GUARDED_BY(mutex_);
std::unordered_map<Task*, std::shared_ptr<Task>> tasks_not_ready_ absl::flat_hash_map<Task*, std::shared_ptr<Task>> tasks_not_ready_
GUARDED_BY(mutex_); GUARDED_BY(mutex_);
}; };

View File

@ -18,9 +18,9 @@
#define CARTOGRAPHER_IO_POINTS_PROCESSOR_PIPELINE_BUILDER_H_ #define CARTOGRAPHER_IO_POINTS_PROCESSOR_PIPELINE_BUILDER_H_
#include <string> #include <string>
#include <unordered_map>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "cartographer/common/lua_parameter_dictionary.h" #include "cartographer/common/lua_parameter_dictionary.h"
#include "cartographer/io/file_writer.h" #include "cartographer/io/file_writer.h"
#include "cartographer/io/points_processor.h" #include "cartographer/io/points_processor.h"
@ -55,7 +55,7 @@ class PointsProcessorPipelineBuilder {
common::LuaParameterDictionary* dictionary) const; common::LuaParameterDictionary* dictionary) const;
private: private:
std::unordered_map<std::string, FactoryFunction> factories_; absl::flat_hash_map<std::string, FactoryFunction> factories_;
}; };
// Register all 'PointsProcessor' that ship with Cartographer with this // Register all 'PointsProcessor' that ship with Cartographer with this

View File

@ -16,9 +16,9 @@
#include "cartographer/io/serialization_format_migration.h" #include "cartographer/io/serialization_format_migration.h"
#include <unordered_map>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "cartographer/mapping/3d/submap_3d.h" #include "cartographer/mapping/3d/submap_3d.h"
#include "cartographer/mapping/internal/3d/scan_matching/rotational_scan_matcher.h" #include "cartographer/mapping/internal/3d/scan_matching/rotational_scan_matcher.h"
#include "cartographer/mapping/probability_values.h" #include "cartographer/mapping/probability_values.h"
@ -32,7 +32,7 @@ namespace io {
namespace { namespace {
using mapping::proto::SerializedData; using mapping::proto::SerializedData;
using ProtoMap = std::unordered_map<int, std::vector<SerializedData>>; using ProtoMap = absl::flat_hash_map<int, std::vector<SerializedData>>;
bool ReadPoseGraph(cartographer::io::ProtoStreamReaderInterface* const input, bool ReadPoseGraph(cartographer::io::ProtoStreamReaderInterface* const input,
ProtoMap* proto_map) { ProtoMap* proto_map) {

View File

@ -23,11 +23,11 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <set> #include <set>
#include <unordered_map>
#include <vector> #include <vector>
#include "Eigen/Core" #include "Eigen/Core"
#include "Eigen/Geometry" #include "Eigen/Geometry"
#include "absl/container/flat_hash_map.h"
#include "absl/synchronization/mutex.h" #include "absl/synchronization/mutex.h"
#include "cartographer/common/fixed_ratio_sampler.h" #include "cartographer/common/fixed_ratio_sampler.h"
#include "cartographer/common/thread_pool.h" #include "cartographer/common/thread_pool.h"
@ -246,7 +246,7 @@ class PoseGraph2D : public PoseGraph {
std::unique_ptr<WorkQueue> work_queue_ GUARDED_BY(work_queue_mutex_); std::unique_ptr<WorkQueue> work_queue_ GUARDED_BY(work_queue_mutex_);
// We globally localize a fraction of the nodes from each trajectory. // We globally localize a fraction of the nodes from each trajectory.
std::unordered_map<int, std::unique_ptr<common::FixedRatioSampler>> absl::flat_hash_map<int, std::unique_ptr<common::FixedRatioSampler>>
global_localization_samplers_ GUARDED_BY(mutex_); global_localization_samplers_ GUARDED_BY(mutex_);
// Number of nodes added since last loop closure. // Number of nodes added since last loop closure.

View File

@ -23,11 +23,11 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <set> #include <set>
#include <unordered_map>
#include <vector> #include <vector>
#include "Eigen/Core" #include "Eigen/Core"
#include "Eigen/Geometry" #include "Eigen/Geometry"
#include "absl/container/flat_hash_map.h"
#include "absl/synchronization/mutex.h" #include "absl/synchronization/mutex.h"
#include "cartographer/common/fixed_ratio_sampler.h" #include "cartographer/common/fixed_ratio_sampler.h"
#include "cartographer/common/thread_pool.h" #include "cartographer/common/thread_pool.h"
@ -248,7 +248,7 @@ class PoseGraph3D : public PoseGraph {
std::unique_ptr<WorkQueue> work_queue_ GUARDED_BY(work_queue_mutex_); std::unique_ptr<WorkQueue> work_queue_ GUARDED_BY(work_queue_mutex_);
// We globally localize a fraction of the nodes from each trajectory. // We globally localize a fraction of the nodes from each trajectory.
std::unordered_map<int, std::unique_ptr<common::FixedRatioSampler>> absl::flat_hash_map<int, std::unique_ptr<common::FixedRatioSampler>>
global_localization_samplers_ GUARDED_BY(mutex_); global_localization_samplers_ GUARDED_BY(mutex_);
// Number of nodes added since last loop closure. // Number of nodes added since last loop closure.

View File

@ -77,7 +77,7 @@ bool ConnectedComponents::TransitivelyConnected(const int trajectory_id_a,
std::vector<std::vector<int>> ConnectedComponents::Components() { std::vector<std::vector<int>> ConnectedComponents::Components() {
// Map from cluster exemplar -> growing cluster. // Map from cluster exemplar -> growing cluster.
std::unordered_map<int, std::vector<int>> map; absl::flat_hash_map<int, std::vector<int>> map;
absl::MutexLock locker(&lock_); absl::MutexLock locker(&lock_);
for (const auto& trajectory_id_entry : forest_) { for (const auto& trajectory_id_entry : forest_) {
map[FindSet(trajectory_id_entry.first)].push_back( map[FindSet(trajectory_id_entry.first)].push_back(

View File

@ -18,8 +18,8 @@
#define CARTOGRAPHER_MAPPING_INTERNAL_CONNECTED_COMPONENTS_H_ #define CARTOGRAPHER_MAPPING_INTERNAL_CONNECTED_COMPONENTS_H_
#include <map> #include <map>
#include <unordered_map>
#include "absl/container/flat_hash_map.h"
#include "absl/synchronization/mutex.h" #include "absl/synchronization/mutex.h"
#include "cartographer/mapping/proto/connected_components.pb.h" #include "cartographer/mapping/proto/connected_components.pb.h"
#include "cartographer/mapping/submaps.h" #include "cartographer/mapping/submaps.h"

View File

@ -19,10 +19,10 @@
#include <memory> #include <memory>
#include <set> #include <set>
#include <unordered_map>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "cartographer/common/lua_parameter_dictionary.h" #include "cartographer/common/lua_parameter_dictionary.h"
#include "cartographer/mapping/id.h" #include "cartographer/mapping/id.h"
#include "cartographer/mapping/pose_graph_interface.h" #include "cartographer/mapping/pose_graph_interface.h"

View File

@ -19,10 +19,10 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "cartographer/sensor/collator_interface.h" #include "cartographer/sensor/collator_interface.h"
#include "cartographer/sensor/data.h" #include "cartographer/sensor/data.h"
#include "cartographer/sensor/internal/ordered_multi_queue.h" #include "cartographer/sensor/internal/ordered_multi_queue.h"
@ -54,7 +54,7 @@ class Collator : public CollatorInterface {
OrderedMultiQueue queue_; OrderedMultiQueue queue_;
// Map of trajectory ID to all associated QueueKeys. // Map of trajectory ID to all associated QueueKeys.
std::unordered_map<int, std::vector<QueueKey>> queue_keys_; absl::flat_hash_map<int, std::vector<QueueKey>> queue_keys_;
}; };
} // namespace sensor } // namespace sensor

View File

@ -51,6 +51,8 @@ class OrderedMultiQueue {
using Callback = std::function<void(std::unique_ptr<Data>)>; using Callback = std::function<void(std::unique_ptr<Data>)>;
OrderedMultiQueue(); OrderedMultiQueue();
OrderedMultiQueue(OrderedMultiQueue&& queue) = default;
~OrderedMultiQueue(); ~OrderedMultiQueue();
// Adds a new queue with key 'queue_key' which must not already exist. // Adds a new queue with key 'queue_key' which must not already exist.

View File

@ -18,9 +18,9 @@
#define CARTOGRAPHER_SENSOR_INTERNAL_TRAJECTORY_COLLATOR_H_ #define CARTOGRAPHER_SENSOR_INTERNAL_TRAJECTORY_COLLATOR_H_
#include <memory> #include <memory>
#include <unordered_map>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "cartographer/metrics/counter.h" #include "cartographer/metrics/counter.h"
#include "cartographer/metrics/family_factory.h" #include "cartographer/metrics/family_factory.h"
#include "cartographer/sensor/collator_interface.h" #include "cartographer/sensor/collator_interface.h"
@ -64,12 +64,12 @@ class TrajectoryCollator : public CollatorInterface {
collator_metrics_family_; collator_metrics_family_;
// Holds individual counters for each trajectory/sensor pair. // Holds individual counters for each trajectory/sensor pair.
std::unordered_map<std::string, metrics::Counter*> metrics_map_; absl::flat_hash_map<std::string, metrics::Counter*> metrics_map_;
std::unordered_map<int, OrderedMultiQueue> trajectory_to_queue_; absl::flat_hash_map<int, OrderedMultiQueue> trajectory_to_queue_;
// Map of trajectory ID to all associated QueueKeys. // Map of trajectory ID to all associated QueueKeys.
std::unordered_map<int, std::vector<QueueKey>> trajectory_to_queue_keys_; absl::flat_hash_map<int, std::vector<QueueKey>> trajectory_to_queue_keys_;
}; };
} // namespace sensor } // namespace sensor

View File

@ -33,6 +33,7 @@ if(NOT TARGET standalone_absl)
"${ABSEIL_PROJECT_BUILD_DIR}/absl/strings/${prefix}str_format_internal${suffix}" "${ABSEIL_PROJECT_BUILD_DIR}/absl/strings/${prefix}str_format_internal${suffix}"
"${ABSEIL_PROJECT_BUILD_DIR}/absl/strings/${prefix}str_format_extension_internal${suffix}" "${ABSEIL_PROJECT_BUILD_DIR}/absl/strings/${prefix}str_format_extension_internal${suffix}"
"${ABSEIL_PROJECT_BUILD_DIR}/absl/strings/${prefix}absl_str_format${suffix}" "${ABSEIL_PROJECT_BUILD_DIR}/absl/strings/${prefix}absl_str_format${suffix}"
"${ABSEIL_PROJECT_BUILD_DIR}/absl/hash/${prefix}absl_hash${suffix}"
"${ABSEIL_PROJECT_BUILD_DIR}/absl/algorithm/${prefix}absl_algorithm${suffix}" "${ABSEIL_PROJECT_BUILD_DIR}/absl/algorithm/${prefix}absl_algorithm${suffix}"
"${ABSEIL_PROJECT_BUILD_DIR}/absl/base/${prefix}absl_base${suffix}" "${ABSEIL_PROJECT_BUILD_DIR}/absl/base/${prefix}absl_base${suffix}"
"${ABSEIL_PROJECT_BUILD_DIR}/absl/base/${prefix}absl_dynamic_annotations${suffix}" "${ABSEIL_PROJECT_BUILD_DIR}/absl/base/${prefix}absl_dynamic_annotations${suffix}"
@ -63,7 +64,7 @@ if(NOT TARGET standalone_absl)
ExternalProject_Add(${ABSEIL_PROJECT_NAME} ExternalProject_Add(${ABSEIL_PROJECT_NAME}
PREFIX ${ABSEIL_PROJECT_NAME} PREFIX ${ABSEIL_PROJECT_NAME}
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
GIT_TAG 44aa275286baf97fc13529aca547a88b180beb08 GIT_TAG 5441bbe1db5d0f2ca24b5b60166367b0966790af
INSTALL_COMMAND "" INSTALL_COMMAND ""
BUILD_COMMAND ${CMAKE_COMMAND} --build "${ABSEIL_PROJECT_BUILD_DIR}" BUILD_COMMAND ${CMAKE_COMMAND} --build "${ABSEIL_PROJECT_BUILD_DIR}"
CMAKE_CACHE_ARGS "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON;-DBUILD_TESTING:BOOL=OFF;-DCMAKE_BUILD_TYPE:STRING=Release" CMAKE_CACHE_ARGS "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON;-DBUILD_TESTING:BOOL=OFF;-DCMAKE_BUILD_TYPE:STRING=Release"