From f031513470aede4a0bb6a24c977bb6b2d6d34cd2 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 9 Jul 2023 21:31:58 -0700 Subject: [PATCH] [ntcore] NetworkTable::GetSubTables(): Remove duplicates (#5076) In Java, a set is used. Use a two-stage approach in C++ to achieve the same result. --- ntcore/src/main/native/cpp/networktables/NetworkTable.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp b/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp index 1f6a7608d5..77b726ad52 100644 --- a/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp +++ b/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp @@ -231,8 +231,14 @@ std::vector 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; }