From e5de23f9abefaf97374564b6739dd66b5d9aa570 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Tue, 18 Feb 2025 12:57:44 +0100 Subject: BackMap: Implement GetReferences --- src/utils/cpp/back_map.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/utils/cpp/back_map.hpp') diff --git a/src/utils/cpp/back_map.hpp b/src/utils/cpp/back_map.hpp index debe5bac..ab41346e 100644 --- a/src/utils/cpp/back_map.hpp +++ b/src/utils/cpp/back_map.hpp @@ -143,6 +143,20 @@ class BackMap final { return result; } + /// \brief Obtain the set of values corresponding to given keys. If a key + /// isn't known to the container, it is ignored. Copy free. + [[nodiscard]] auto GetReferences(std::unordered_set const& keys) + const noexcept -> std::unordered_set> { + std::unordered_set> result; + result.reserve(keys.size()); + for (auto const& key : keys) { + if (auto value = GetReference(key)) { + result.emplace(*std::move(value)); + } + } + return result; + } + using Iterable = std::unordered_map, gsl::not_null>; -- cgit v1.2.3