[ABSL] Use flat_hash_set instead of unordered_set. (#1442)
parent
bdb6f2db4a
commit
5e11365749
|
@ -98,6 +98,7 @@ cc_library(
|
||||||
"@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/container:flat_hash_map",
|
||||||
|
"@com_google_absl//absl/container:flat_hash_set",
|
||||||
"@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",
|
||||||
|
|
|
@ -42,7 +42,7 @@ FixedRatioSamplingPointsProcessor::FixedRatioSamplingPointsProcessor(
|
||||||
|
|
||||||
void FixedRatioSamplingPointsProcessor::Process(
|
void FixedRatioSamplingPointsProcessor::Process(
|
||||||
std::unique_ptr<PointsBatch> batch) {
|
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) {
|
for (size_t i = 0; i < batch->points.size(); ++i) {
|
||||||
if (!sampler_->Pulse()) {
|
if (!sampler_->Pulse()) {
|
||||||
to_remove.insert(i);
|
to_remove.insert(i);
|
||||||
|
|
|
@ -37,14 +37,14 @@ FrameIdFilteringPointsProcessor::FromDictionary(
|
||||||
dictionary->GetDictionary("drop_frames")->GetArrayValuesAsStrings();
|
dictionary->GetDictionary("drop_frames")->GetArrayValuesAsStrings();
|
||||||
}
|
}
|
||||||
return absl::make_unique<FrameIdFilteringPointsProcessor>(
|
return absl::make_unique<FrameIdFilteringPointsProcessor>(
|
||||||
std::unordered_set<std::string>(keep_frames.begin(), keep_frames.end()),
|
absl::flat_hash_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>(drop_frames.begin(), drop_frames.end()),
|
||||||
next);
|
next);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameIdFilteringPointsProcessor::FrameIdFilteringPointsProcessor(
|
FrameIdFilteringPointsProcessor::FrameIdFilteringPointsProcessor(
|
||||||
const std::unordered_set<std::string>& keep_frame_ids,
|
const absl::flat_hash_set<std::string>& keep_frame_ids,
|
||||||
const std::unordered_set<std::string>& drop_frame_ids,
|
const absl::flat_hash_set<std::string>& drop_frame_ids,
|
||||||
PointsProcessor* next)
|
PointsProcessor* next)
|
||||||
: keep_frame_ids_(keep_frame_ids),
|
: keep_frame_ids_(keep_frame_ids),
|
||||||
drop_frame_ids_(drop_frame_ids),
|
drop_frame_ids_(drop_frame_ids),
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
#ifndef CARTOGRAPHER_IO_FRAME_ID_FILTERING_POINTS_PROCESSOR_H_
|
#ifndef CARTOGRAPHER_IO_FRAME_ID_FILTERING_POINTS_PROCESSOR_H_
|
||||||
#define 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/common/lua_parameter_dictionary.h"
|
||||||
#include "cartographer/io/points_processor.h"
|
#include "cartographer/io/points_processor.h"
|
||||||
|
|
||||||
|
@ -32,8 +31,8 @@ class FrameIdFilteringPointsProcessor : public PointsProcessor {
|
||||||
public:
|
public:
|
||||||
constexpr static const char* kConfigurationFileActionName = "frame_id_filter";
|
constexpr static const char* kConfigurationFileActionName = "frame_id_filter";
|
||||||
FrameIdFilteringPointsProcessor(
|
FrameIdFilteringPointsProcessor(
|
||||||
const std::unordered_set<std::string>& keep_frame_ids,
|
const absl::flat_hash_set<std::string>& keep_frame_ids,
|
||||||
const std::unordered_set<std::string>& drop_frame_ids,
|
const absl::flat_hash_set<std::string>& drop_frame_ids,
|
||||||
PointsProcessor* next);
|
PointsProcessor* next);
|
||||||
static std::unique_ptr<FrameIdFilteringPointsProcessor> FromDictionary(
|
static std::unique_ptr<FrameIdFilteringPointsProcessor> FromDictionary(
|
||||||
common::LuaParameterDictionary* dictionary, PointsProcessor* next);
|
common::LuaParameterDictionary* dictionary, PointsProcessor* next);
|
||||||
|
@ -48,8 +47,8 @@ class FrameIdFilteringPointsProcessor : public PointsProcessor {
|
||||||
FlushResult Flush() override;
|
FlushResult Flush() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::unordered_set<std::string> keep_frame_ids_;
|
const absl::flat_hash_set<std::string> keep_frame_ids_;
|
||||||
const std::unordered_set<std::string> drop_frame_ids_;
|
const absl::flat_hash_set<std::string> drop_frame_ids_;
|
||||||
PointsProcessor* const next_;
|
PointsProcessor* const next_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ MinMaxRangeFiteringPointsProcessor::MinMaxRangeFiteringPointsProcessor(
|
||||||
|
|
||||||
void MinMaxRangeFiteringPointsProcessor::Process(
|
void MinMaxRangeFiteringPointsProcessor::Process(
|
||||||
std::unique_ptr<PointsBatch> batch) {
|
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) {
|
for (size_t i = 0; i < batch->points.size(); ++i) {
|
||||||
const float range = (batch->points[i].position - batch->origin).norm();
|
const float range = (batch->points[i].position - batch->origin).norm();
|
||||||
if (!(min_range_ <= range && range <= max_range_)) {
|
if (!(min_range_ <= range && range <= max_range_)) {
|
||||||
|
|
|
@ -107,7 +107,7 @@ void OutlierRemovingPointsProcessor::ProcessInPhaseTwo(
|
||||||
void OutlierRemovingPointsProcessor::ProcessInPhaseThree(
|
void OutlierRemovingPointsProcessor::ProcessInPhaseThree(
|
||||||
std::unique_ptr<PointsBatch> batch) {
|
std::unique_ptr<PointsBatch> batch) {
|
||||||
constexpr double kMissPerHitLimit = 3;
|
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) {
|
for (size_t i = 0; i < batch->points.size(); ++i) {
|
||||||
const VoxelData voxel =
|
const VoxelData voxel =
|
||||||
voxels_.value(voxels_.GetCellIndex(batch->points[i].position));
|
voxels_.value(voxels_.GetCellIndex(batch->points[i].position));
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
|
#include "absl/container/flat_hash_set.h"
|
||||||
#include "cartographer/io/internal/pbstream_info.h"
|
#include "cartographer/io/internal/pbstream_info.h"
|
||||||
#include "cartographer/io/internal/pbstream_migrate.h"
|
#include "cartographer/io/internal/pbstream_migrate.h"
|
||||||
#include "gflags/gflags.h"
|
#include "gflags/gflags.h"
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
namespace cartographer {
|
namespace cartographer {
|
||||||
namespace io {
|
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();
|
const int new_num_points = batch->points.size() - to_remove.size();
|
||||||
sensor::PointCloud points;
|
sensor::PointCloud points;
|
||||||
points.reserve(new_num_points);
|
points.reserve(new_num_points);
|
||||||
|
|
|
@ -19,10 +19,10 @@
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <unordered_set>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Eigen/Core"
|
#include "Eigen/Core"
|
||||||
|
#include "absl/container/flat_hash_set.h"
|
||||||
#include "cartographer/common/time.h"
|
#include "cartographer/common/time.h"
|
||||||
#include "cartographer/io/color.h"
|
#include "cartographer/io/color.h"
|
||||||
#include "cartographer/sensor/point_cloud.h"
|
#include "cartographer/sensor/point_cloud.h"
|
||||||
|
@ -67,7 +67,7 @@ struct PointsBatch {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Removes the indices in 'to_remove' from 'batch'.
|
// 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 io
|
||||||
} // namespace cartographer
|
} // namespace cartographer
|
||||||
|
|
|
@ -39,7 +39,7 @@ CollatedTrajectoryBuilder::CollatedTrajectoryBuilder(
|
||||||
trajectory_id_(trajectory_id),
|
trajectory_id_(trajectory_id),
|
||||||
wrapped_trajectory_builder_(std::move(wrapped_trajectory_builder)),
|
wrapped_trajectory_builder_(std::move(wrapped_trajectory_builder)),
|
||||||
last_logging_time_(std::chrono::steady_clock::now()) {
|
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) {
|
for (const auto& sensor_id : expected_sensor_ids) {
|
||||||
if (sensor_id.type == SensorId::SensorType::LANDMARK &&
|
if (sensor_id.type == SensorId::SensorType::LANDMARK &&
|
||||||
!collate_landmarks_) {
|
!collate_landmarks_) {
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#include "cartographer/mapping/internal/connected_components.h"
|
#include "cartographer/mapping/internal/connected_components.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
|
#include "absl/container/flat_hash_set.h"
|
||||||
#include "cartographer/mapping/proto/connected_components.pb.h"
|
#include "cartographer/mapping/proto/connected_components.pb.h"
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_set>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/container/flat_hash_set.h"
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "cartographer/sensor/data.h"
|
#include "cartographer/sensor/data.h"
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class CollatorInterface {
|
||||||
// for each collated sensor data.
|
// for each collated sensor data.
|
||||||
virtual void AddTrajectory(
|
virtual void AddTrajectory(
|
||||||
int trajectory_id,
|
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;
|
const Callback& callback) = 0;
|
||||||
|
|
||||||
// Marks 'trajectory_id' as finished.
|
// Marks 'trajectory_id' as finished.
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace sensor {
|
||||||
|
|
||||||
void Collator::AddTrajectory(
|
void Collator::AddTrajectory(
|
||||||
const int trajectory_id,
|
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) {
|
const Callback& callback) {
|
||||||
for (const auto& sensor_id : expected_sensor_ids) {
|
for (const auto& sensor_id : expected_sensor_ids) {
|
||||||
const auto queue_key = QueueKey{trajectory_id, sensor_id};
|
const auto queue_key = QueueKey{trajectory_id, sensor_id};
|
||||||
|
|
|
@ -19,10 +19,10 @@
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_set>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/container/flat_hash_map.h"
|
#include "absl/container/flat_hash_map.h"
|
||||||
|
#include "absl/container/flat_hash_set.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"
|
||||||
|
@ -37,8 +37,9 @@ class Collator : public CollatorInterface {
|
||||||
Collator(const Collator&) = delete;
|
Collator(const Collator&) = delete;
|
||||||
Collator& operator=(const Collator&) = delete;
|
Collator& operator=(const Collator&) = delete;
|
||||||
|
|
||||||
void AddTrajectory(int trajectory_id,
|
void AddTrajectory(
|
||||||
const std::unordered_set<std::string>& expected_sensor_ids,
|
int trajectory_id,
|
||||||
|
const absl::flat_hash_set<std::string>& expected_sensor_ids,
|
||||||
const Callback& callback) override;
|
const Callback& callback) override;
|
||||||
|
|
||||||
void FinishTrajectory(int trajectory_id) override;
|
void FinishTrajectory(int trajectory_id) override;
|
||||||
|
|
|
@ -67,7 +67,7 @@ TEST(Collator, Ordering) {
|
||||||
Collator collator;
|
Collator collator;
|
||||||
collator.AddTrajectory(
|
collator.AddTrajectory(
|
||||||
kTrajectoryId,
|
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,
|
[&received, kTrajectoryId](const std::string& sensor_id,
|
||||||
std::unique_ptr<Data> data) {
|
std::unique_ptr<Data> data) {
|
||||||
received.push_back(CollatorOutput(kTrajectoryId, data->GetSensorId(),
|
received.push_back(CollatorOutput(kTrajectoryId, data->GetSensorId(),
|
||||||
|
@ -134,7 +134,7 @@ TEST(Collator, OrderingMultipleTrajectories) {
|
||||||
Collator collator;
|
Collator collator;
|
||||||
collator.AddTrajectory(
|
collator.AddTrajectory(
|
||||||
kTrajectoryId[0],
|
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,
|
[&received, kTrajectoryId](const std::string& sensor_id,
|
||||||
std::unique_ptr<Data> data) {
|
std::unique_ptr<Data> data) {
|
||||||
received.push_back(CollatorOutput(kTrajectoryId[0], data->GetSensorId(),
|
received.push_back(CollatorOutput(kTrajectoryId[0], data->GetSensorId(),
|
||||||
|
@ -142,7 +142,7 @@ TEST(Collator, OrderingMultipleTrajectories) {
|
||||||
});
|
});
|
||||||
collator.AddTrajectory(
|
collator.AddTrajectory(
|
||||||
kTrajectoryId[1],
|
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,
|
[&received, kTrajectoryId](const std::string& sensor_id,
|
||||||
std::unique_ptr<Data> data) {
|
std::unique_ptr<Data> data) {
|
||||||
received.push_back(CollatorOutput(kTrajectoryId[1], data->GetSensorId(),
|
received.push_back(CollatorOutput(kTrajectoryId[1], data->GetSensorId(),
|
||||||
|
|
|
@ -25,7 +25,7 @@ metrics::Family<metrics::Counter>*
|
||||||
|
|
||||||
void TrajectoryCollator::AddTrajectory(
|
void TrajectoryCollator::AddTrajectory(
|
||||||
const int trajectory_id,
|
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) {
|
const Callback& callback) {
|
||||||
CHECK_EQ(trajectory_to_queue_.count(trajectory_id), 0);
|
CHECK_EQ(trajectory_to_queue_.count(trajectory_id), 0);
|
||||||
for (const auto& sensor_id : expected_sensor_ids) {
|
for (const auto& sensor_id : expected_sensor_ids) {
|
||||||
|
|
|
@ -42,8 +42,9 @@ class TrajectoryCollator : public CollatorInterface {
|
||||||
TrajectoryCollator(const TrajectoryCollator&) = delete;
|
TrajectoryCollator(const TrajectoryCollator&) = delete;
|
||||||
TrajectoryCollator& operator=(const TrajectoryCollator&) = delete;
|
TrajectoryCollator& operator=(const TrajectoryCollator&) = delete;
|
||||||
|
|
||||||
void AddTrajectory(int trajectory_id,
|
void AddTrajectory(
|
||||||
const std::unordered_set<std::string>& expected_sensor_ids,
|
int trajectory_id,
|
||||||
|
const absl::flat_hash_set<std::string>& expected_sensor_ids,
|
||||||
const Callback& callback) override;
|
const Callback& callback) override;
|
||||||
|
|
||||||
void FinishTrajectory(int trajectory_id) override;
|
void FinishTrajectory(int trajectory_id) override;
|
||||||
|
|
|
@ -63,7 +63,7 @@ TEST(TrajectoryCollator, OrderingMultipleTrajectories) {
|
||||||
TrajectoryCollator collator;
|
TrajectoryCollator collator;
|
||||||
collator.AddTrajectory(
|
collator.AddTrajectory(
|
||||||
kTrajectoryId[0],
|
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,
|
[&received, kTrajectoryId](const std::string& sensor_id,
|
||||||
std::unique_ptr<Data> data) {
|
std::unique_ptr<Data> data) {
|
||||||
received.push_back(CollatorOutput(kTrajectoryId[0], data->GetSensorId(),
|
received.push_back(CollatorOutput(kTrajectoryId[0], data->GetSensorId(),
|
||||||
|
@ -71,7 +71,7 @@ TEST(TrajectoryCollator, OrderingMultipleTrajectories) {
|
||||||
});
|
});
|
||||||
collator.AddTrajectory(
|
collator.AddTrajectory(
|
||||||
kTrajectoryId[1],
|
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,
|
[&received, kTrajectoryId](const std::string& sensor_id,
|
||||||
std::unique_ptr<Data> data) {
|
std::unique_ptr<Data> data) {
|
||||||
received.push_back(CollatorOutput(kTrajectoryId[1], data->GetSensorId(),
|
received.push_back(CollatorOutput(kTrajectoryId[1], data->GetSensorId(),
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
#define CARTOGRAPHER_SENSOR_INTERNAL_VOXEL_FILTER_H_
|
#define CARTOGRAPHER_SENSOR_INTERNAL_VOXEL_FILTER_H_
|
||||||
|
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
|
#include "absl/container/flat_hash_set.h"
|
||||||
#include "cartographer/common/lua_parameter_dictionary.h"
|
#include "cartographer/common/lua_parameter_dictionary.h"
|
||||||
#include "cartographer/sensor/point_cloud.h"
|
#include "cartographer/sensor/point_cloud.h"
|
||||||
#include "cartographer/sensor/proto/adaptive_voxel_filter_options.pb.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;
|
Eigen::Array3i GetCellIndex(const Eigen::Vector3f& point) const;
|
||||||
|
|
||||||
float resolution_;
|
float resolution_;
|
||||||
std::unordered_set<KeyType> voxel_set_;
|
absl::flat_hash_set<KeyType> voxel_set_;
|
||||||
};
|
};
|
||||||
|
|
||||||
proto::AdaptiveVoxelFilterOptions CreateAdaptiveVoxelFilterOptions(
|
proto::AdaptiveVoxelFilterOptions CreateAdaptiveVoxelFilterOptions(
|
||||||
|
|
Loading…
Reference in New Issue