[ABSL] Use flat_hash_set instead of unordered_set. (#1442)

master
Alexander Belyaev 2018-10-08 12:43:17 +02:00 committed by GitHub
parent bdb6f2db4a
commit 5e11365749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 39 additions and 37 deletions

View File

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

View File

@ -42,7 +42,7 @@ FixedRatioSamplingPointsProcessor::FixedRatioSamplingPointsProcessor(
void FixedRatioSamplingPointsProcessor::Process(
std::unique_ptr<PointsBatch> batch) {
std::unordered_set<int> to_remove;
absl::flat_hash_set<int> to_remove;
for (size_t i = 0; i < batch->points.size(); ++i) {
if (!sampler_->Pulse()) {
to_remove.insert(i);

View File

@ -37,14 +37,14 @@ FrameIdFilteringPointsProcessor::FromDictionary(
dictionary->GetDictionary("drop_frames")->GetArrayValuesAsStrings();
}
return absl::make_unique<FrameIdFilteringPointsProcessor>(
std::unordered_set<std::string>(keep_frames.begin(), keep_frames.end()),
std::unordered_set<std::string>(drop_frames.begin(), drop_frames.end()),
absl::flat_hash_set<std::string>(keep_frames.begin(), keep_frames.end()),
absl::flat_hash_set<std::string>(drop_frames.begin(), drop_frames.end()),
next);
}
FrameIdFilteringPointsProcessor::FrameIdFilteringPointsProcessor(
const std::unordered_set<std::string>& keep_frame_ids,
const std::unordered_set<std::string>& drop_frame_ids,
const absl::flat_hash_set<std::string>& keep_frame_ids,
const absl::flat_hash_set<std::string>& drop_frame_ids,
PointsProcessor* next)
: keep_frame_ids_(keep_frame_ids),
drop_frame_ids_(drop_frame_ids),

View File

@ -17,8 +17,7 @@
#ifndef CARTOGRAPHER_IO_FRAME_ID_FILTERING_POINTS_PROCESSOR_H_
#define CARTOGRAPHER_IO_FRAME_ID_FILTERING_POINTS_PROCESSOR_H_
#include <unordered_set>
#include "absl/container/flat_hash_set.h"
#include "cartographer/common/lua_parameter_dictionary.h"
#include "cartographer/io/points_processor.h"
@ -32,8 +31,8 @@ class FrameIdFilteringPointsProcessor : public PointsProcessor {
public:
constexpr static const char* kConfigurationFileActionName = "frame_id_filter";
FrameIdFilteringPointsProcessor(
const std::unordered_set<std::string>& keep_frame_ids,
const std::unordered_set<std::string>& drop_frame_ids,
const absl::flat_hash_set<std::string>& keep_frame_ids,
const absl::flat_hash_set<std::string>& drop_frame_ids,
PointsProcessor* next);
static std::unique_ptr<FrameIdFilteringPointsProcessor> FromDictionary(
common::LuaParameterDictionary* dictionary, PointsProcessor* next);
@ -48,8 +47,8 @@ class FrameIdFilteringPointsProcessor : public PointsProcessor {
FlushResult Flush() override;
private:
const std::unordered_set<std::string> keep_frame_ids_;
const std::unordered_set<std::string> drop_frame_ids_;
const absl::flat_hash_set<std::string> keep_frame_ids_;
const absl::flat_hash_set<std::string> drop_frame_ids_;
PointsProcessor* const next_;
};

View File

@ -38,7 +38,7 @@ MinMaxRangeFiteringPointsProcessor::MinMaxRangeFiteringPointsProcessor(
void MinMaxRangeFiteringPointsProcessor::Process(
std::unique_ptr<PointsBatch> batch) {
std::unordered_set<int> to_remove;
absl::flat_hash_set<int> to_remove;
for (size_t i = 0; i < batch->points.size(); ++i) {
const float range = (batch->points[i].position - batch->origin).norm();
if (!(min_range_ <= range && range <= max_range_)) {

View File

@ -107,7 +107,7 @@ void OutlierRemovingPointsProcessor::ProcessInPhaseTwo(
void OutlierRemovingPointsProcessor::ProcessInPhaseThree(
std::unique_ptr<PointsBatch> batch) {
constexpr double kMissPerHitLimit = 3;
std::unordered_set<int> to_remove;
absl::flat_hash_set<int> to_remove;
for (size_t i = 0; i < batch->points.size(); ++i) {
const VoxelData voxel =
voxels_.value(voxels_.GetCellIndex(batch->points[i].position));

View File

@ -15,8 +15,8 @@
*/
#include <functional>
#include <unordered_set>
#include "absl/container/flat_hash_set.h"
#include "cartographer/io/internal/pbstream_info.h"
#include "cartographer/io/internal/pbstream_migrate.h"
#include "gflags/gflags.h"

View File

@ -19,7 +19,7 @@
namespace cartographer {
namespace io {
void RemovePoints(std::unordered_set<int> to_remove, PointsBatch* batch) {
void RemovePoints(absl::flat_hash_set<int> to_remove, PointsBatch* batch) {
const int new_num_points = batch->points.size() - to_remove.size();
sensor::PointCloud points;
points.reserve(new_num_points);

View File

@ -19,10 +19,10 @@
#include <array>
#include <cstdint>
#include <unordered_set>
#include <vector>
#include "Eigen/Core"
#include "absl/container/flat_hash_set.h"
#include "cartographer/common/time.h"
#include "cartographer/io/color.h"
#include "cartographer/sensor/point_cloud.h"
@ -67,7 +67,7 @@ struct PointsBatch {
};
// Removes the indices in 'to_remove' from 'batch'.
void RemovePoints(std::unordered_set<int> to_remove, PointsBatch* batch);
void RemovePoints(absl::flat_hash_set<int> to_remove, PointsBatch* batch);
} // namespace io
} // namespace cartographer

View File

@ -39,7 +39,7 @@ CollatedTrajectoryBuilder::CollatedTrajectoryBuilder(
trajectory_id_(trajectory_id),
wrapped_trajectory_builder_(std::move(wrapped_trajectory_builder)),
last_logging_time_(std::chrono::steady_clock::now()) {
std::unordered_set<std::string> expected_sensor_id_strings;
absl::flat_hash_set<std::string> expected_sensor_id_strings;
for (const auto& sensor_id : expected_sensor_ids) {
if (sensor_id.type == SensorId::SensorType::LANDMARK &&
!collate_landmarks_) {

View File

@ -17,8 +17,8 @@
#include "cartographer/mapping/internal/connected_components.h"
#include <algorithm>
#include <unordered_set>
#include "absl/container/flat_hash_set.h"
#include "cartographer/mapping/proto/connected_components.pb.h"
#include "glog/logging.h"

View File

@ -19,9 +19,9 @@
#include <functional>
#include <memory>
#include <unordered_set>
#include <vector>
#include "absl/container/flat_hash_set.h"
#include "absl/types/optional.h"
#include "cartographer/sensor/data.h"
@ -42,7 +42,7 @@ class CollatorInterface {
// for each collated sensor data.
virtual void AddTrajectory(
int trajectory_id,
const std::unordered_set<std::string>& expected_sensor_ids,
const absl::flat_hash_set<std::string>& expected_sensor_ids,
const Callback& callback) = 0;
// Marks 'trajectory_id' as finished.

View File

@ -21,7 +21,7 @@ namespace sensor {
void Collator::AddTrajectory(
const int trajectory_id,
const std::unordered_set<std::string>& expected_sensor_ids,
const absl::flat_hash_set<std::string>& expected_sensor_ids,
const Callback& callback) {
for (const auto& sensor_id : expected_sensor_ids) {
const auto queue_key = QueueKey{trajectory_id, sensor_id};

View File

@ -19,10 +19,10 @@
#include <functional>
#include <memory>
#include <unordered_set>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "cartographer/sensor/collator_interface.h"
#include "cartographer/sensor/data.h"
#include "cartographer/sensor/internal/ordered_multi_queue.h"
@ -37,8 +37,9 @@ class Collator : public CollatorInterface {
Collator(const Collator&) = delete;
Collator& operator=(const Collator&) = delete;
void AddTrajectory(int trajectory_id,
const std::unordered_set<std::string>& expected_sensor_ids,
void AddTrajectory(
int trajectory_id,
const absl::flat_hash_set<std::string>& expected_sensor_ids,
const Callback& callback) override;
void FinishTrajectory(int trajectory_id) override;

View File

@ -67,7 +67,7 @@ TEST(Collator, Ordering) {
Collator collator;
collator.AddTrajectory(
kTrajectoryId,
std::unordered_set<std::string>(kSensorId.begin(), kSensorId.end()),
absl::flat_hash_set<std::string>(kSensorId.begin(), kSensorId.end()),
[&received, kTrajectoryId](const std::string& sensor_id,
std::unique_ptr<Data> data) {
received.push_back(CollatorOutput(kTrajectoryId, data->GetSensorId(),
@ -134,7 +134,7 @@ TEST(Collator, OrderingMultipleTrajectories) {
Collator collator;
collator.AddTrajectory(
kTrajectoryId[0],
std::unordered_set<std::string>(kSensorId.begin(), kSensorId.end()),
absl::flat_hash_set<std::string>(kSensorId.begin(), kSensorId.end()),
[&received, kTrajectoryId](const std::string& sensor_id,
std::unique_ptr<Data> data) {
received.push_back(CollatorOutput(kTrajectoryId[0], data->GetSensorId(),
@ -142,7 +142,7 @@ TEST(Collator, OrderingMultipleTrajectories) {
});
collator.AddTrajectory(
kTrajectoryId[1],
std::unordered_set<std::string>(kSensorId.begin(), kSensorId.end()),
absl::flat_hash_set<std::string>(kSensorId.begin(), kSensorId.end()),
[&received, kTrajectoryId](const std::string& sensor_id,
std::unique_ptr<Data> data) {
received.push_back(CollatorOutput(kTrajectoryId[1], data->GetSensorId(),

View File

@ -25,7 +25,7 @@ metrics::Family<metrics::Counter>*
void TrajectoryCollator::AddTrajectory(
const int trajectory_id,
const std::unordered_set<std::string>& expected_sensor_ids,
const absl::flat_hash_set<std::string>& expected_sensor_ids,
const Callback& callback) {
CHECK_EQ(trajectory_to_queue_.count(trajectory_id), 0);
for (const auto& sensor_id : expected_sensor_ids) {

View File

@ -42,8 +42,9 @@ class TrajectoryCollator : public CollatorInterface {
TrajectoryCollator(const TrajectoryCollator&) = delete;
TrajectoryCollator& operator=(const TrajectoryCollator&) = delete;
void AddTrajectory(int trajectory_id,
const std::unordered_set<std::string>& expected_sensor_ids,
void AddTrajectory(
int trajectory_id,
const absl::flat_hash_set<std::string>& expected_sensor_ids,
const Callback& callback) override;
void FinishTrajectory(int trajectory_id) override;

View File

@ -63,7 +63,7 @@ TEST(TrajectoryCollator, OrderingMultipleTrajectories) {
TrajectoryCollator collator;
collator.AddTrajectory(
kTrajectoryId[0],
std::unordered_set<std::string>(kSensorId.begin(), kSensorId.end()),
absl::flat_hash_set<std::string>(kSensorId.begin(), kSensorId.end()),
[&received, kTrajectoryId](const std::string& sensor_id,
std::unique_ptr<Data> data) {
received.push_back(CollatorOutput(kTrajectoryId[0], data->GetSensorId(),
@ -71,7 +71,7 @@ TEST(TrajectoryCollator, OrderingMultipleTrajectories) {
});
collator.AddTrajectory(
kTrajectoryId[1],
std::unordered_set<std::string>(kSensorId.begin(), kSensorId.end()),
absl::flat_hash_set<std::string>(kSensorId.begin(), kSensorId.end()),
[&received, kTrajectoryId](const std::string& sensor_id,
std::unique_ptr<Data> data) {
received.push_back(CollatorOutput(kTrajectoryId[1], data->GetSensorId(),

View File

@ -18,8 +18,8 @@
#define CARTOGRAPHER_SENSOR_INTERNAL_VOXEL_FILTER_H_
#include <bitset>
#include <unordered_set>
#include "absl/container/flat_hash_set.h"
#include "cartographer/common/lua_parameter_dictionary.h"
#include "cartographer/sensor/point_cloud.h"
#include "cartographer/sensor/proto/adaptive_voxel_filter_options.pb.h"
@ -58,7 +58,7 @@ class VoxelFilter {
Eigen::Array3i GetCellIndex(const Eigen::Vector3f& point) const;
float resolution_;
std::unordered_set<KeyType> voxel_set_;
absl::flat_hash_set<KeyType> voxel_set_;
};
proto::AdaptiveVoxelFilterOptions CreateAdaptiveVoxelFilterOptions(