Repository navigation
Closed
Labels
Description
to increase performance for
and increase merging performance for existing flat_maps
- https://github.com/OpenMS/OpenMS/blob/develop/src/openms/include/OpenMS/METADATA/MetaInfo.h (for operator+=), i.e. merging of two instances
- replace current instances of '.getKeys()' (very inefficient) where possible (by exposing .begin()/end() or a higher level operation like merging).
flat_maps have .merge(), but with non-const RHS...
Alternative: Effective merging draft (more efficient than flat_map1.insert(flat_map2.begin(), flat_map2.end()):
#include <boost/container/flat_map.hpp>
#include <vector>
#include <iostream>
#include <iterator> // for std::make_move_iterator
int main() {
using namespace boost::container;
using pair_type = std::pair<int, std::string>;
flat_map<int, std::string> a = {
{1, "one"},
{2, "two"}
};
flat_map<int, std::string> b = {
{2, "zwei"},
{3, "three"}
};
std::vector<pair_type> merged;
merged.reserve(a.size() + b.size());
auto ita = a.begin(), enda = a.end();
auto itb = b.begin(), endb = b.end();
// Merge with deduplication: keep values from `a`
while (ita != enda && itb != endb) {
if (ita->first < itb->first) {
merged.push_back(*ita++);
} else if (itb->first < ita->first) {
merged.push_back(*itb++);
} else {
merged.push_back(*ita++); // prefer a
++itb;
}
}
merged.insert(merged.end(), ita, enda);
merged.insert(merged.end(), itb, endb);
// Move elements into the new flat_map
flat_map<int, std::string> result(
std::make_move_iterator(merged.begin()),
std::make_move_iterator(merged.end())
);
// Print result
for (const auto& [k, v] : result) {
std::cout << k << ": " << v << '\n';
}
return 0;
}
Activity
timosachsenberg commentedon Jul 2, 2025
boost 1.80 did quite a lot of rewrites to its hash maps (especially unordered ones with open addressing)
github-actions commentedon Jan 9, 2026
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
timosachsenberg commentedon Jan 9, 2026
I will assign this to Claude. Let's see if something useful comes out.
Add iterator support and optimize MetaInfo merge operations (#8076)
Add iterator support and optimize MetaInfo merge operations (#8076)
Add iterator support and optimize MetaInfo merge operations (#8076) (#…