[ABSL] Use flat_hash_map instead of unordered_map. (#1439)
							parent
							
								
									8285673abb
								
							
						
					
					
						commit
						bdb6f2db4a
					
				| 
						 | 
				
			
			@ -256,9 +256,9 @@ def cartographer_repositories():
 | 
			
		|||
 | 
			
		||||
    _maybe(native.http_archive,
 | 
			
		||||
        name = "com_google_absl",
 | 
			
		||||
        sha256 = "387cf016ab1ab8530d1cea8975276ce8d8bff355133776129bdc400d05519eb6",
 | 
			
		||||
        strip_prefix = "abseil-cpp-44aa275286baf97fc13529aca547a88b180beb08",
 | 
			
		||||
        urls = ["https://github.com/abseil/abseil-cpp/archive/44aa275286baf97fc13529aca547a88b180beb08.tar.gz"],
 | 
			
		||||
        sha256 = "c8ba586a9ab12bc4a67bb419fc0d2146200942b072bac95f50490f977b7fb04f",
 | 
			
		||||
        strip_prefix = "abseil-cpp-5441bbe1db5d0f2ca24b5b60166367b0966790af",
 | 
			
		||||
        urls = ["https://github.com/abseil/abseil-cpp/archive/5441bbe1db5d0f2ca24b5b60166367b0966790af.tar.gz"],
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    # TODO(rodrigoq): remove these binds once grpc#14140 has been merged, as well
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -97,6 +97,7 @@ cc_library(
 | 
			
		|||
        "@boost//:iostreams",
 | 
			
		||||
        "@com_google_absl//absl/base",
 | 
			
		||||
        "@com_google_absl//absl/strings",
 | 
			
		||||
        "@com_google_absl//absl/container:flat_hash_map",
 | 
			
		||||
        "@com_google_absl//absl/synchronization",
 | 
			
		||||
        "@com_google_absl//absl/types:optional",
 | 
			
		||||
        "@com_google_glog//:glog",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,6 +20,7 @@
 | 
			
		|||
#include <memory>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
#include "absl/container/flat_hash_map.h"
 | 
			
		||||
#include "async_grpc/rpc_handler.h"
 | 
			
		||||
#include "cartographer/cloud/proto/map_builder_service.pb.h"
 | 
			
		||||
#include "cartographer/metrics/counter.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -59,7 +60,7 @@ class AddSensorDataBatchHandler
 | 
			
		|||
      counter_metrics_family_;
 | 
			
		||||
 | 
			
		||||
  // 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_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,10 +14,9 @@
 | 
			
		|||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
 | 
			
		||||
#include "cartographer/cloud/metrics/prometheus/family_factory.h"
 | 
			
		||||
 | 
			
		||||
#include "absl/container/flat_hash_map.h"
 | 
			
		||||
#include "absl/memory/memory.h"
 | 
			
		||||
#include "prometheus/counter.h"
 | 
			
		||||
#include "prometheus/family.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +75,7 @@ class CounterFamily
 | 
			
		|||
 private:
 | 
			
		||||
  ::prometheus::Family<::prometheus::Counter>* prometheus_;
 | 
			
		||||
  std::mutex wrappers_mutex_;
 | 
			
		||||
  std::unordered_map<::prometheus::Counter*, std::unique_ptr<Counter>>
 | 
			
		||||
  absl::flat_hash_map<::prometheus::Counter*, std::unique_ptr<Counter>>
 | 
			
		||||
      wrappers_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -108,7 +107,7 @@ class GaugeFamily
 | 
			
		|||
 private:
 | 
			
		||||
  ::prometheus::Family<::prometheus::Gauge>* prometheus_;
 | 
			
		||||
  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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -137,7 +136,7 @@ class HistogramFamily : public ::cartographer::metrics::Family<
 | 
			
		|||
 private:
 | 
			
		||||
  ::prometheus::Family<::prometheus::Histogram>* prometheus_;
 | 
			
		||||
  std::mutex wrappers_mutex_;
 | 
			
		||||
  std::unordered_map<::prometheus::Histogram*, std::unique_ptr<Histogram>>
 | 
			
		||||
  absl::flat_hash_map<::prometheus::Histogram*, std::unique_ptr<Histogram>>
 | 
			
		||||
      wrappers_;
 | 
			
		||||
  const BucketBoundaries boundaries_;
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,9 +21,9 @@
 | 
			
		|||
#include <functional>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <thread>
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "absl/container/flat_hash_map.h"
 | 
			
		||||
#include "absl/synchronization/mutex.h"
 | 
			
		||||
#include "cartographer/common/task.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +76,7 @@ class ThreadPool : public ThreadPoolInterface {
 | 
			
		|||
  bool running_ GUARDED_BY(mutex_) = true;
 | 
			
		||||
  std::vector<std::thread> pool_ 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_);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,9 +18,9 @@
 | 
			
		|||
#define CARTOGRAPHER_IO_POINTS_PROCESSOR_PIPELINE_BUILDER_H_
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "absl/container/flat_hash_map.h"
 | 
			
		||||
#include "cartographer/common/lua_parameter_dictionary.h"
 | 
			
		||||
#include "cartographer/io/file_writer.h"
 | 
			
		||||
#include "cartographer/io/points_processor.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -55,7 +55,7 @@ class PointsProcessorPipelineBuilder {
 | 
			
		|||
      common::LuaParameterDictionary* dictionary) const;
 | 
			
		||||
 | 
			
		||||
 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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,9 +16,9 @@
 | 
			
		|||
 | 
			
		||||
#include "cartographer/io/serialization_format_migration.h"
 | 
			
		||||
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "absl/container/flat_hash_map.h"
 | 
			
		||||
#include "cartographer/mapping/3d/submap_3d.h"
 | 
			
		||||
#include "cartographer/mapping/internal/3d/scan_matching/rotational_scan_matcher.h"
 | 
			
		||||
#include "cartographer/mapping/probability_values.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +32,7 @@ namespace io {
 | 
			
		|||
namespace {
 | 
			
		||||
 | 
			
		||||
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,
 | 
			
		||||
                   ProtoMap* proto_map) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,11 +23,11 @@
 | 
			
		|||
#include <map>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <set>
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "Eigen/Core"
 | 
			
		||||
#include "Eigen/Geometry"
 | 
			
		||||
#include "absl/container/flat_hash_map.h"
 | 
			
		||||
#include "absl/synchronization/mutex.h"
 | 
			
		||||
#include "cartographer/common/fixed_ratio_sampler.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_);
 | 
			
		||||
 | 
			
		||||
  // 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_);
 | 
			
		||||
 | 
			
		||||
  // Number of nodes added since last loop closure.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,11 +23,11 @@
 | 
			
		|||
#include <map>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <set>
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "Eigen/Core"
 | 
			
		||||
#include "Eigen/Geometry"
 | 
			
		||||
#include "absl/container/flat_hash_map.h"
 | 
			
		||||
#include "absl/synchronization/mutex.h"
 | 
			
		||||
#include "cartographer/common/fixed_ratio_sampler.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_);
 | 
			
		||||
 | 
			
		||||
  // 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_);
 | 
			
		||||
 | 
			
		||||
  // Number of nodes added since last loop closure.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -77,7 +77,7 @@ bool ConnectedComponents::TransitivelyConnected(const int trajectory_id_a,
 | 
			
		|||
 | 
			
		||||
std::vector<std::vector<int>> ConnectedComponents::Components() {
 | 
			
		||||
  // 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_);
 | 
			
		||||
  for (const auto& trajectory_id_entry : forest_) {
 | 
			
		||||
    map[FindSet(trajectory_id_entry.first)].push_back(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,8 +18,8 @@
 | 
			
		|||
#define CARTOGRAPHER_MAPPING_INTERNAL_CONNECTED_COMPONENTS_H_
 | 
			
		||||
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
 | 
			
		||||
#include "absl/container/flat_hash_map.h"
 | 
			
		||||
#include "absl/synchronization/mutex.h"
 | 
			
		||||
#include "cartographer/mapping/proto/connected_components.pb.h"
 | 
			
		||||
#include "cartographer/mapping/submaps.h"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,10 +19,10 @@
 | 
			
		|||
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <set>
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
#include <utility>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "absl/container/flat_hash_map.h"
 | 
			
		||||
#include "cartographer/common/lua_parameter_dictionary.h"
 | 
			
		||||
#include "cartographer/mapping/id.h"
 | 
			
		||||
#include "cartographer/mapping/pose_graph_interface.h"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,10 +19,10 @@
 | 
			
		|||
 | 
			
		||||
#include <functional>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
#include <unordered_set>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "absl/container/flat_hash_map.h"
 | 
			
		||||
#include "cartographer/sensor/collator_interface.h"
 | 
			
		||||
#include "cartographer/sensor/data.h"
 | 
			
		||||
#include "cartographer/sensor/internal/ordered_multi_queue.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -54,7 +54,7 @@ class Collator : public CollatorInterface {
 | 
			
		|||
  OrderedMultiQueue queue_;
 | 
			
		||||
 | 
			
		||||
  // 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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,6 +51,8 @@ class OrderedMultiQueue {
 | 
			
		|||
  using Callback = std::function<void(std::unique_ptr<Data>)>;
 | 
			
		||||
 | 
			
		||||
  OrderedMultiQueue();
 | 
			
		||||
  OrderedMultiQueue(OrderedMultiQueue&& queue) = default;
 | 
			
		||||
 | 
			
		||||
  ~OrderedMultiQueue();
 | 
			
		||||
 | 
			
		||||
  // Adds a new queue with key 'queue_key' which must not already exist.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,9 +18,9 @@
 | 
			
		|||
#define CARTOGRAPHER_SENSOR_INTERNAL_TRAJECTORY_COLLATOR_H_
 | 
			
		||||
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "absl/container/flat_hash_map.h"
 | 
			
		||||
#include "cartographer/metrics/counter.h"
 | 
			
		||||
#include "cartographer/metrics/family_factory.h"
 | 
			
		||||
#include "cartographer/sensor/collator_interface.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -64,12 +64,12 @@ class TrajectoryCollator : public CollatorInterface {
 | 
			
		|||
      collator_metrics_family_;
 | 
			
		||||
 | 
			
		||||
  // 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.
 | 
			
		||||
  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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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_extension_internal${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/base/${prefix}absl_base${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}
 | 
			
		||||
    PREFIX ${ABSEIL_PROJECT_NAME}
 | 
			
		||||
    GIT_REPOSITORY   https://github.com/abseil/abseil-cpp.git
 | 
			
		||||
    GIT_TAG          44aa275286baf97fc13529aca547a88b180beb08
 | 
			
		||||
    GIT_TAG          5441bbe1db5d0f2ca24b5b60166367b0966790af
 | 
			
		||||
    INSTALL_COMMAND  ""
 | 
			
		||||
    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"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue