[ntcore] NetworkTable::GetSubTables(): Remove duplicates (#5076)

In Java, a set is used. Use a two-stage approach in C++ to achieve the
same result.
This commit is contained in:
Peter Johnson
2023-07-09 21:31:58 -07:00
committed by GitHub
parent f8e74e2f7c
commit f031513470

View File

@@ -231,8 +231,14 @@ std::vector<std::string> NetworkTable::GetSubTables() const {
if (end_subtable == std::string_view::npos) {
continue;
}
keys.emplace_back(wpi::substr(relative_key, 0, end_subtable));
auto subTable = wpi::substr(relative_key, 0, end_subtable);
if (keys.empty() || keys.back() != subTable) {
keys.emplace_back(subTable);
}
}
// remove duplicates
std::sort(keys.begin(), keys.end());
keys.erase(std::unique(keys.begin(), keys.end()), keys.end());
return keys;
}