@@ -386,6 +386,40 @@ class IntraProcessManager
386386 std::vector<uint64_t > take_ownership_subscriptions;
387387 };
388388
389+ // / Hash function for rmw_gid_t to enable use in unordered_map
390+ struct rmw_gid_hash
391+ {
392+ std::size_t operator ()(const rmw_gid_t & gid) const noexcept
393+ {
394+ // Using the FNV-1a hash algorithm on the gid data
395+ constexpr std::size_t FNV_prime = 1099511628211u ;
396+ std::size_t result = 14695981039346656037u ;
397+
398+ for (std::size_t i = 0 ; i < RMW_GID_STORAGE_SIZE; ++i) {
399+ result ^= gid.data [i];
400+ result *= FNV_prime;
401+ }
402+ return result;
403+ }
404+ };
405+
406+ // / Equality comparison for rmw_gid_t to enable use in unordered_map
407+ struct rmw_gid_equal
408+ {
409+ bool operator ()(const rmw_gid_t & lhs, const rmw_gid_t & rhs) const noexcept
410+ {
411+ // Compare implementation identifier first for fast rejection
412+ if (lhs.implementation_identifier != rhs.implementation_identifier ) {
413+ return false ;
414+ }
415+ // Compare the data bytes
416+ return std::equal (
417+ std::begin (lhs.data ),
418+ std::end (lhs.data ),
419+ std::begin (rhs.data ));
420+ }
421+ };
422+
389423 using SubscriptionMap =
390424 std::unordered_map<uint64_t , rclcpp::experimental::SubscriptionIntraProcessBase::WeakPtr>;
391425
@@ -398,6 +432,16 @@ class IntraProcessManager
398432 using PublisherToSubscriptionIdsMap =
399433 std::unordered_map<uint64_t , SplittedSubscriptions>;
400434
435+ // / Structure to store publisher information in GID lookup map
436+ struct PublisherInfo
437+ {
438+ uint64_t pub_id;
439+ rclcpp::PublisherBase::WeakPtr publisher;
440+ };
441+
442+ using GidToPublisherInfoMap =
443+ std::unordered_map<rmw_gid_t , PublisherInfo, rmw_gid_hash, rmw_gid_equal>;
444+
401445 RCLCPP_PUBLIC
402446 static
403447 uint64_t
@@ -640,6 +684,7 @@ class IntraProcessManager
640684 SubscriptionMap subscriptions_;
641685 PublisherMap publishers_;
642686 PublisherBufferMap publisher_buffers_;
687+ GidToPublisherInfoMap gid_to_publisher_info_;
643688
644689 mutable std::shared_timed_mutex mutex_;
645690};
0 commit comments