Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to std::map for TopicTypeMap #546

Merged
merged 6 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: uncrustify
run: /ros_entrypoint.sh ament_uncrustify rmw_zenoh_cpp/ --exclude rmw_zenoh_cpp/src/detail/ordered_hash.hpp rmw_zenoh_cpp/src/detail/ordered_map.hpp
run: /ros_entrypoint.sh ament_uncrustify rmw_zenoh_cpp/
- name: cpplint
run: /ros_entrypoint.sh ament_cpplint rmw_zenoh_cpp/ --exclude rmw_zenoh_cpp/src/detail/ordered_hash.hpp rmw_zenoh_cpp/src/detail/ordered_map.hpp
run: /ros_entrypoint.sh ament_cpplint rmw_zenoh_cpp/
6 changes: 2 additions & 4 deletions rmw_zenoh_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ if(BUILD_TESTING)
find_package(ament_cmake_uncrustify REQUIRED)
find_package(ament_cmake_xmllint REQUIRED)

set(_linter_excludes src/detail/ordered_hash.hpp src/detail/ordered_map.hpp)

ament_copyright(EXCLUDE src/detail/simplified_xxhash3.cpp src/detail/simplified_xxhash3.hpp)
ament_cpplint(EXCLUDE ${_linter_excludes})
ament_cpplint()
ament_lint_cmake()
ament_uncrustify(EXCLUDE ${_linter_excludes})
ament_uncrustify()
ament_xmllint()
endif()

Expand Down
1 change: 0 additions & 1 deletion rmw_zenoh_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<maintainer email="[email protected]">Yadunund</maintainer>

<license>Apache License 2.0</license>
<license>MIT</license> <!-- for ordered_{map,hash}.hpp -->
<license>BSD</license> <!-- for simplified_xxhash3.{cpp,hpp} -->

<author email="[email protected]">Chris Lalancette</author>
Expand Down
10 changes: 5 additions & 5 deletions rmw_zenoh_cpp/src/detail/graph_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ void GraphCache::update_topic_map_for_put(
return;
}
// The topic exists in the topic_map so we check if the type also exists.
GraphNode::TopicTypeMap::iterator topic_type_map_it = topic_map_it.value().find(
GraphNode::TopicTypeMap::iterator topic_type_map_it = topic_map_it->second.find(
graph_topic_data->info_.type_);
if (topic_type_map_it == topic_map_it->second.end()) {
// First time this topic type is added.
topic_map_it.value().insert(
topic_map_it->second.insert(
std::make_pair(
graph_topic_data->info_.type_,
std::move(topic_qos_map)));
Expand Down Expand Up @@ -445,7 +445,7 @@ void GraphCache::update_topic_map_for_del(
}

GraphNode::TopicTypeMap::iterator cache_topic_type_it =
cache_topic_it.value().find(topic_info.type_);
cache_topic_it->second.find(topic_info.type_);
if (cache_topic_type_it == cache_topic_it->second.end()) {
// If an entity is short-lived, it is possible to receive the liveliness token
// for its deletion before the one for its creation given that Zenoh does not
Expand Down Expand Up @@ -490,7 +490,7 @@ void GraphCache::update_topic_map_for_del(
}
// If the type does not have any qos entries, erase it from the type map.
if (cache_topic_type_it->second.empty()) {
cache_topic_it.value().erase(cache_topic_type_it);
cache_topic_it->second.erase(cache_topic_type_it);
}
// If the topic does not have any TopicData entries, erase the topic from the map.
if (cache_topic_it->second.empty()) {
Expand Down Expand Up @@ -770,7 +770,7 @@ rmw_ret_t fill_names_and_types(
});
// Fill topic names and types.
std::size_t index = 0;
for (const std::pair<std::string, GraphNode::TopicTypeMap> & item : entity_map) {
for (const std::pair<const std::string, GraphNode::TopicTypeMap> & item : entity_map) {
names_and_types->names.data[index] = rcutils_strdup(item.first.c_str(), *allocator);
if (!names_and_types->names.data[index]) {
return RMW_RET_BAD_ALLOC;
Expand Down
7 changes: 3 additions & 4 deletions rmw_zenoh_cpp/src/detail/graph_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include "event.hpp"
#include "liveliness_utils.hpp"
#include "ordered_map.hpp"

#include "rcutils/allocator.h"
#include "rcutils/types.h"
Expand Down Expand Up @@ -83,9 +82,9 @@ struct GraphNode
// Map topic type to QoSMap
using TopicTypeMap = std::unordered_map<std::string, TopicQoSMap>;
// Map topic name to TopicTypeMap
// This uses a map that remembers insertion order because some parts of the client libraries
// expect that these are returned in the order that they were created.
using TopicMap = tsl::ordered_map<std::string, TopicTypeMap>;
// This uses a map that sort element by name because some parts of the client libraries
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

Suggested change
// This uses a map that sort element by name because some parts of the client libraries
// This uses a map that sorts keys alphabetically because some parts of the client libraries

// expect that these are returned in alphabetical order.
using TopicMap = std::map<std::string, TopicTypeMap>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update documentation above.


// Entries for pub/sub.
TopicMap pubs_ = {};
Expand Down
Loading