24 namespace perception {
27 static void string_split(
const std::string& str,
char c,
28 std::vector<std::string>* strs) {
31 for (
auto& cur_char : str) {
38 strs->push_back(term);
43 strs->push_back(term);
47 static bool string_compare_by_length(
const std::string& lhs,
48 const std::string& rhs) {
49 if (lhs.length() < rhs.length()) {
51 }
else if (lhs.length() == rhs.length()) {
58 static void sort_strings_by_split_length(
59 const std::vector<std::string>& strs,
60 std::vector<std::size_t>* sorted_indices) {
63 std::vector<std::string> splits;
66 std::vector<StringHelper> helper(strs.size());
67 for (std::size_t i = 0; i < strs.size(); ++i) {
68 helper[i].str = strs.at(i);
69 string_split(helper[i].str,
'/', &helper[i].splits);
72 std::sort(helper.begin(), helper.end(),
73 [](
const StringHelper& lhs,
const StringHelper& rhs) {
74 if (lhs.splits.size() < rhs.splits.size()) {
76 }
else if (lhs.splits.size() > rhs.splits.size()) {
79 for (std::size_t i = 0; i < lhs.splits.size(); ++i) {
80 if (lhs.splits[i] == rhs.splits[i]) {
83 return string_compare_by_length(lhs.splits[i], rhs.splits[i]);
88 sorted_indices->resize(strs.size());
89 for (std::size_t i = 0; i < strs.size(); ++i) {
90 sorted_indices->at(i) = helper[i].id;
96 const std::vector<std::size_t>& indices) {
97 if (src->size() != indices.size()) {
101 dst.reserve(indices.size());
102 for (
auto&
id : indices) {
103 dst.push_back(std::move(src->at(
id)));
106 for (
auto& data : dst) {
107 src->push_back(std::move(data));
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
void shuffle_by_indices(std::vector< T > *src, const std::vector< std::size_t > &indices)
Definition: string_compare.h:95