Repository navigation
Add iterator support and optimize MetaInfo merge operations - #8621
Conversation
📝 WalkthroughWalkthroughExposes MetaInfo's internal flat_map via public type aliases and iterator/size accessors, adds a two-way merge operator (operator+=) for MetaInfo, updates MetaInfoInterface to expose iterator access and use the new merge, and adds tests covering iteration, size, and merge semantics. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/openms/source/METADATA/MetaInfoInterface.cpp (1)
254-264: Consider thread-safety implications of static local MetaInfo.The
static const MetaInfo emptyis thread-safe for initialization (C++11 guarantees), and since it's const and never modified, concurrent reads are safe. However, you could add a brief comment clarifying this design choice for future maintainers.📝 Optional: Add explanatory comment
MetaInfoInterface::MetaInfoConstIterator MetaInfoInterface::metaBegin() const { + // Thread-safe: static const initialization is guaranteed safe, and empty is never modified static const MetaInfo empty; return meta_ ? meta_->begin() : empty.begin(); }src/openms/include/OpenMS/METADATA/MetaInfoInterface.h (1)
140-160: Verify order-independence claim for hash implementation.The hash uses additive accumulation (
hash += pair_hash) which is order-independent (commutative). However, there's a subtle issue: whileMetaInfousesflat_mapwhich maintains sorted order by key, the comment claims order-independence. This is fine for correctness, but the Doxygen comment on lines 143-144 states "regardless of internal storage order" - sinceflat_mapis always sorted by key, this comment could be misleading.Consider clarifying that the order-independence is a defensive design choice, not a current necessity.
📝 Optional: Clarify comment
/** * @brief Hash function for MetaInfoInterface. * * Hashes based on all meta info key-value pairs using order-independent * accumulation. Uses direct iterator access for O(n) complexity without * allocating intermediate vectors. * - * @note Uses additive accumulation (commutative) so equal MetaInfoInterface - * objects produce equal hashes regardless of internal storage order. + * @note Uses additive accumulation (commutative) for robustness, though + * the underlying flat_map is always sorted by key. */
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/openms/include/OpenMS/METADATA/MetaInfo.hsrc/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/source/METADATA/MetaInfoInterface.cppsrc/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
🧰 Additional context used
📓 Path-based instructions (13)
src/tests/class_tests/openms/**/*.cpp
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Write unit tests for new functionality
Files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
**/*.{cpp,cc,cxx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{cpp,cc,cxx}: Never usestd::coutorstd::cerrdirectly; use OpenMS logging macros instead
Always use braces for control structures, even for single-line blocks (trivial one-liners may stay single-line)
Braces for control structures must align with opening/closing braces on their own lines
Files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/openms/source/METADATA/MetaInfoInterface.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
**/*.{cpp,cc,cxx,h,hpp,hxx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{cpp,cc,cxx,h,hpp,hxx}: Never usestd::endl; use\nfor performance
Use 2-space indentation for C++/headers; no tabs; Unix line endings
Use classes/types/namespaces in PascalCase
Use lowerCamelCase for method names
Use snake_case for variable names
Use trailing underscore for private/protected member variable names
Use UPPER_SNAKE_CASE for enums and macros
Include space after keywords (if,for,while) and around binary operators
Avoid the C++ preprocessor; preferenum classover macro constants
Files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/source/METADATA/MetaInfoInterface.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cppsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/tests/class_tests/openms/source/**/*_test.cpp
📄 CodeRabbit inference engine (AGENTS.md)
src/tests/class_tests/openms/source/**/*_test.cpp: UseSTART_SECTIONandEND_SECTIONmacros in C++ unit tests; wrap template methods with 2+ arguments in parentheses
UseNEW_TMP_FILEmacro for each output file in tests to avoid side effects
Wrap template methods with 2+ arguments in parentheses when used withSTART_SECTIONmacro
Files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
src/openms/**/*.{cpp,h,hpp,cc,cxx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
src/openms/**/*.{cpp,h,hpp,cc,cxx}: Follow the existing C++ coding conventions in the codebase
Use the established naming patterns for classes, methods, and variables
Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Follow the established error handling patterns
Utilize OpenMS logging mechanisms
Be mindful of memory usage when processing large datasets
Consider algorithmic complexity for data processing operations
Use appropriate OpenMS containers and algorithms
Files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/source/METADATA/MetaInfoInterface.cppsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/openms/include/OpenMS/**/*.h
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Add Doxygen comments for new public methods and classes
Files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
**/*.{h,hpp,hxx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{h,hpp,hxx}: Never addusing namespaceorusing std::...in header files; allowed in.cppfiles only
Follow the Rule-of-0 or Rule-of-6 for class definitions; no user-defined destructors unless necessary
Files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/openms/include/**/*.{h,hpp,hxx}
📄 CodeRabbit inference engine (AGENTS.md)
src/openms/include/**/*.{h,hpp,hxx}: AddOPENMS_DLLAPImacro on all non-template exported classes, structs, functions, and variables; include in friend operator declarations
Use getter/setter pairs (get/set methods) for protected/private members; no reference getters for primitive types
Use Doxygen documentation with/** */block comments and@tags (not\backslash);@briefis required
Include@param[in],@param[out], or@param[in,out]direction tags for all method parameters in Doxygen documentation
Prefer forward declarations in headers; include only base class headers, non-pointer members, and templates
Always implement and include$Maintainer:marker in file headers, along with$Authors:and copyright notice
Files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/openms/**/*.{cpp,cc,cxx,h,hpp,hxx}
📄 CodeRabbit inference engine (AGENTS.md)
src/openms/**/*.{cpp,cc,cxx,h,hpp,hxx}: PreferOpenMS::Stringfor numeric formatting and parsing instead of standard stream operators
UseSize/SignedSizetypes for STL.size()values instead of raw integers
Use OpenMS primitive types fromOpenMS/CONCEPT/Types.h
Derive custom exceptions fromException::Base; throw with file/line/OPENMS_PRETTY_FUNCTION; catch by reference
Avoid pointers; prefer references in C++ code
UseOpenMS/CONCEPT/Types.hprimitive types instead of standard C++ types for consistency
Use lower_case_with_underscores for method/function parameters and document ranges/units
Files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/source/METADATA/MetaInfoInterface.cppsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/openms/**/*.{h,hpp,hxx,cpp,cc,cxx}
📄 CodeRabbit inference engine (AGENTS.md)
Include
$Maintainer:$marker in file preamble of every header and source file
Files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/source/METADATA/MetaInfoInterface.cppsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/openms/include/**/*.h
📄 CodeRabbit inference engine (AGENTS.md)
Use templates with
_impl.honly when needed;.hfiles must not include_impl.h
Files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/openms/source/**/*.{cpp,cc,cxx}
📄 CodeRabbit inference engine (AGENTS.md)
Include at least ~5% of code as comments in C++ using
//style, plain English describing the next few lines
Files:
src/openms/source/METADATA/MetaInfoInterface.cpp
src/openms/**/*.{cpp,cc,cxx}
📄 CodeRabbit inference engine (AGENTS.md)
Use
OPENMS_LOG_WARN,OPENMS_LOG_INFO, and other OpenMS logging macros instead ofstd::coutorstd::cerr
Files:
src/openms/source/METADATA/MetaInfoInterface.cpp
🧠 Learnings (17)
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality
Applied to files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/tests/class_tests/openms/source/**/*_test.cpp : Use `START_SECTION` and `END_SECTION` macros in C++ unit tests; wrap template methods with 2+ arguments in parentheses
Applied to files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2026-01-07T06:33:27.217Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.217Z
Learning: Add unit tests in `src/tests/class_tests/openms/source/ClassName_test.cpp` and register in `executables.cmake` for all new classes
Applied to files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/tests/class_tests/openms/source/**/*_test.cpp : Wrap template methods with 2+ arguments in parentheses when used with `START_SECTION` macro
Applied to files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/*Test.cpp : Follow naming convention: `ClassNameTest.cpp` for `ClassName`
Applied to files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/tests/class_tests/openms/source/**/*_test.cpp : Use `NEW_TMP_FILE` macro for each output file in tests to avoid side effects
Applied to files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/tests/class_tests/openms_gui/source/**/*_test.cpp : GUI tests must be located in `src/tests/class_tests/openms_gui/source/` and use Qt TestLib framework
Applied to files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2025-09-03T12:58:20.032Z
Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8177
File: src/tests/topp/CMakeLists.txt:1857-1865
Timestamp: 2025-09-03T12:58:20.032Z
Learning: OpenMS tests: When adding new TOPP tests in src/tests/topp/CMakeLists.txt that compare outputs via FuzzyDiff, always add set_tests_properties("<tool>_<n>_out<m>" PROPERTIES DEPENDS "<tool>_<n>") to avoid flakiness under parallel CTest runs.
Applied to files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/include/OpenMS/**/*.h : Add Doxygen comments for new public methods and classes
Applied to files:
src/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/openms/include/**/*.{h,hpp,hxx} : Prefer forward declarations in headers; include only base class headers, non-pointer members, and templates
Applied to files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.h
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/openms/include/**/*.{h,hpp,hxx} : Add `OPENMS_DLLAPI` macro on all non-template exported classes, structs, functions, and variables; include in friend operator declarations
Applied to files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.h
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/openms/include/**/*.h : Use templates with `_impl.h` only when needed; `.h` files must not include `_impl.h`
Applied to files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.h
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/openms/**/*.{cpp,cc,cxx,h,hpp,hxx} : Use OpenMS primitive types from `OpenMS/CONCEPT/Types.h`
Applied to files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/openms/**/*.{cpp,cc,cxx,h,hpp,hxx} : Use `OpenMS/CONCEPT/Types.h` primitive types instead of standard C++ types for consistency
Applied to files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/openms/include/**/*.{h,hpp,hxx} : Use getter/setter pairs (get/set methods) for protected/private members; no reference getters for primitive types
Applied to files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use appropriate OpenMS containers and algorithms
Applied to files:
src/openms/include/OpenMS/METADATA/MetaInfo.h
📚 Learning: 2025-10-21T13:02:16.431Z
Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8318
File: src/openms/include/OpenMS/ML/CLUSTERING/HashGrid.h:466-480
Timestamp: 2025-10-21T13:02:16.431Z
Learning: In OpenMS, when making internal methods public (e.g., in HashGrid.h), remove XXX/TODO comments about implementation details rather than documenting them in the public API documentation.
Applied to files:
src/openms/include/OpenMS/METADATA/MetaInfo.h
🧬 Code graph analysis (4)
src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp (1)
src/openms/source/METADATA/MetaInfoInterface.cpp (9)
MetaInfoInterface(18-25)MetaInfoInterface(28-33)MetaInfoInterface(35-38)metaEnd(260-264)metaEnd(260-260)metaSize(266-269)metaSize(266-266)addMetaValues(244-252)addMetaValues(244-244)
src/openms/include/OpenMS/METADATA/MetaInfoInterface.h (2)
src/openms/include/OpenMS/METADATA/MetaInfo.h (3)
OpenMS(21-195)OpenMS(201-214)std(198-215)src/openms/include/OpenMS/CONCEPT/HashUtils.h (1)
hash_combine(87-90)
src/openms/source/METADATA/MetaInfoInterface.cpp (1)
src/openms/include/OpenMS/METADATA/MetaInfo.h (1)
empty(159-167)
src/tests/class_tests/openms/source/MetaInfo_test.cpp (1)
src/openms/include/OpenMS/METADATA/MetaInfo.h (3)
begin(175-175)end(177-177)empty(159-167)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: build-and-test (ubuntu-24.04-arm, g++, 13)
- GitHub Check: build-and-test (ubuntu-24.04, clang++, 17)
- GitHub Check: build-and-test (windows-2025, cl.exe, 14.44)
- GitHub Check: build-and-test (macos-14, xcode, 15.4)
- GitHub Check: build-and-test (ubuntu-24.04, g++, 13)
- GitHub Check: build-win
- GitHub Check: build-lnx
- GitHub Check: build-lnx-arm
- GitHub Check: build-macos-arm
- GitHub Check: cppcheck-test
🔇 Additional comments (19)
src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp (6)
360-372: LGTM! Good test coverage for metaBegin().The test properly covers both edge cases: empty
meta_(null pointer case) and non-empty meta info with value verification.
374-376: LGTM!Appropriate use of
NOT_TESTABLEsincemetaEnd()is tested together withmetaBegin().
378-395: LGTM! Comprehensive test for metaSize().Good coverage of state transitions: empty → add → add more → remove → clear.
397-409: LGTM! Good tests for getMetaInfo() accessor.Properly tests both null (empty) and non-null cases with size verification.
411-426: LGTM! Iterator semantics verified via manual loop.The test validates that iterators work correctly and that values have the expected type.
428-444: LGTM! Important edge case coverage for addMetaValues.Tests both directions of empty/non-empty merge, ensuring the fast-path logic in
addMetaValuesis exercised.src/tests/class_tests/openms/source/MetaInfo_test.cpp (5)
244-255: LGTM! Good test coverage for size().Comprehensive state transition testing: empty → add → add more → remove → clear.
257-278: LGTM! Const iterator tests are well structured.Tests both
begin()/end()andcbegin()/cend()with proper verification of iterator behavior.
280-290: LGTM! Mutable iterator test validates write-through behavior.Good verification that modifying through the iterator updates the underlying container.
292-305: LGTM! Range-based for loop test.Validates standard C++ iteration semantics work correctly with the new iterators.
307-336: LGTM! Comprehensive operator+= edge case tests.Good coverage of:
- Adding empty to non-empty (fast-path)
- Adding non-empty to empty (assignment fast-path)
- Merging disjoint keys (full merge path)
src/openms/source/METADATA/MetaInfoInterface.cpp (2)
246-252: LGTM! Clean optimization for addMetaValues.The early return for empty source and direct merge via
operator+=is efficient and correct.
266-269: LGTM!Simple and correct null-safe implementation.
src/openms/include/OpenMS/METADATA/MetaInfo.h (3)
47-52: LGTM! Clean type alias declarations.Public exposure of
MapType,iterator, andconst_iteratorenables proper iterator support. Doxygen comments are present as per coding guidelines.
79-127: LGTM! Well-implemented O(n+m) two-way merge.The algorithm correctly handles:
- Empty source fast-path (line 81)
- Empty target fast-path with direct assignment (lines 82-86)
- Two-way merge with rhs overwriting duplicates (lines 99-115)
- Efficient tail appending (lines 117-118)
- Construction from sorted range using
boost::container::ordered_unique_range(lines 121-125)The implementation is correct and achieves the documented O(n+m) complexity improvement.
164-181: LGTM! Iterator accessors and size() are well documented.All public methods have appropriate Doxygen
///comments as required by coding guidelines. Inline implementation is appropriate for these simple delegating accessors.src/openms/include/OpenMS/METADATA/MetaInfoInterface.h (3)
16-16: Acceptable include addition.The full include of
MetaInfo.his necessary to defineMetaInfoConstIteratorasMetaInfo::const_iterator. While coding guidelines prefer forward declarations, this case requires the complete type definition.
38-39: LGTM! Type alias enables iterator access.Clean typedef with appropriate Doxygen comment.
109-120: LGTM! Well-documented iterator and accessor methods.Doxygen documentation includes
@briefequivalent comments. ThegetMetaInfo()returningnullptrfor empty case is clearly documented.
- Add iterator types (iterator, const_iterator) and methods (begin/end/cbegin/cend) to MetaInfo - Add size() method to MetaInfo for O(1) size queries - Optimize operator+= using O(n+m) two-way merge with boost::ordered_unique_range - Move operator+= implementation from header to .cpp file - Add iterator access to MetaInfoInterface (metaBegin/metaEnd/metaSize) - Optimize addMetaValues() to use operator+= directly instead of getKeys() iteration - Update std::hash<MetaInfoInterface> to use iterators (avoids getKeys() allocation) - Add comprehensive Doxygen docstrings for new public API - Add comprehensive unit tests for new functionality Performance improvements: - operator+= reduced from O(m * log(n+m)) to O(n + m) - addMetaValues() reduced from O(n * log(n)) + registry lookups to O(n + m) - Hash computation now uses direct iteration (zero allocations) Co-Authored-By: Claude Opus 4.5 <[email protected]>
d176c06 to
2a2d5e4
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @src/openms/source/METADATA/MetaInfo.cpp:
- Around line 30-78: The early-return in MetaInfo::operator+= uses a single-line
if without braces; wrap the body in braces to match the project's brace
guideline (change "if (rhs.index_to_value_.empty()) return *this;" to use braces
and return inside, keeping behavior identical), ensuring consistent if-style
across the function.
In @src/openms/source/METADATA/MetaInfoInterface.cpp:
- Around line 254-269: metaBegin() and metaEnd() each create their own static
empty MetaInfo, so when meta_ == nullptr callers get iterators from different
sentinel containers causing UB; replace the two locals with a single shared
sentinel MetaInfo and return its begin()/end() from both functions (e.g.,
introduce one shared static const MetaInfo sentinel via a function or a single
file-static variable and have MetaInfoInterface::metaBegin and metaEnd use that
sentinel), leaving metaSize() as-is; this ensures begin() and end() come from
the same container and fixes the iterator/ hashing UB.
🧹 Nitpick comments (3)
src/openms/include/OpenMS/METADATA/MetaInfo.h (1)
46-53: Public iterator/type aliases are a clean way to enable external iteration.This matches the PR objective and keeps call sites simple (range-for, hashing, etc.).
src/openms/include/OpenMS/METADATA/MetaInfoInterface.h (1)
164-184: Hashing: avoid repeatedmetaEnd()calls; consider stronger mixing than sum.
- Cache
endonce to avoid callingmetaEnd()each iteration.- Since iteration order is already deterministic (flat_map sorted by key), order-independent accumulation isn’t necessary and sum tends to collide more.
Possible improvement (order-dependent, stronger distribution)
std::size_t operator()(const OpenMS::MetaInfoInterface& meta) const noexcept { - std::size_t hash = 0; - // Iterate directly over the underlying flat_map entries - for (auto it = meta.metaBegin(); it != meta.metaEnd(); ++it) + std::size_t hash = 0; + const auto end = meta.metaEnd(); + for (auto it = meta.metaBegin(); it != end; ++it) { - std::size_t pair_hash = OpenMS::hash_int(static_cast<int64_t>(it->first)); - OpenMS::hash_combine(pair_hash, std::hash<OpenMS::DataValue>{}(it->second)); - hash += pair_hash; // Order-independent accumulation + OpenMS::hash_combine(hash, OpenMS::hash_int(it->first)); + OpenMS::hash_combine(hash, std::hash<OpenMS::DataValue>{}(it->second)); } return hash; }src/tests/class_tests/openms/source/MetaInfo_test.cpp (1)
244-337: Test coverage is well targeted for the new API surface (size/iterators/range-for/operator+=).These tests should catch most regressions around empty/non-empty behavior and overwrite semantics.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
src/openms/include/OpenMS/METADATA/MetaInfo.hsrc/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/source/METADATA/MetaInfo.cppsrc/openms/source/METADATA/MetaInfoInterface.cppsrc/tests/class_tests/openms/source/MetaInfoInterface_test.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
- src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp
🧰 Additional context used
📓 Path-based instructions (13)
src/openms/**/*.{cpp,h,hpp,cc,cxx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
src/openms/**/*.{cpp,h,hpp,cc,cxx}: Follow the existing C++ coding conventions in the codebase
Use the established naming patterns for classes, methods, and variables
Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Follow the established error handling patterns
Utilize OpenMS logging mechanisms
Be mindful of memory usage when processing large datasets
Consider algorithmic complexity for data processing operations
Use appropriate OpenMS containers and algorithms
Files:
src/openms/source/METADATA/MetaInfoInterface.cppsrc/openms/source/METADATA/MetaInfo.cppsrc/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
**/*.{cpp,cc,cxx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{cpp,cc,cxx}: Never usestd::coutorstd::cerrdirectly; use OpenMS logging macros instead
Always use braces for control structures, even for single-line blocks (trivial one-liners may stay single-line)
Braces for control structures must align with opening/closing braces on their own lines
Files:
src/openms/source/METADATA/MetaInfoInterface.cppsrc/openms/source/METADATA/MetaInfo.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cpp
**/*.{cpp,cc,cxx,h,hpp,hxx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{cpp,cc,cxx,h,hpp,hxx}: Never usestd::endl; use\nfor performance
Use 2-space indentation for C++/headers; no tabs; Unix line endings
Use classes/types/namespaces in PascalCase
Use lowerCamelCase for method names
Use snake_case for variable names
Use trailing underscore for private/protected member variable names
Use UPPER_SNAKE_CASE for enums and macros
Include space after keywords (if,for,while) and around binary operators
Avoid the C++ preprocessor; preferenum classover macro constants
Files:
src/openms/source/METADATA/MetaInfoInterface.cppsrc/openms/source/METADATA/MetaInfo.cppsrc/tests/class_tests/openms/source/MetaInfo_test.cppsrc/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/openms/**/*.{cpp,cc,cxx,h,hpp,hxx}
📄 CodeRabbit inference engine (AGENTS.md)
src/openms/**/*.{cpp,cc,cxx,h,hpp,hxx}: PreferOpenMS::Stringfor numeric formatting and parsing instead of standard stream operators
UseSize/SignedSizetypes for STL.size()values instead of raw integers
Use OpenMS primitive types fromOpenMS/CONCEPT/Types.h
Derive custom exceptions fromException::Base; throw with file/line/OPENMS_PRETTY_FUNCTION; catch by reference
Avoid pointers; prefer references in C++ code
UseOpenMS/CONCEPT/Types.hprimitive types instead of standard C++ types for consistency
Use lower_case_with_underscores for method/function parameters and document ranges/units
Files:
src/openms/source/METADATA/MetaInfoInterface.cppsrc/openms/source/METADATA/MetaInfo.cppsrc/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/openms/source/**/*.{cpp,cc,cxx}
📄 CodeRabbit inference engine (AGENTS.md)
Include at least ~5% of code as comments in C++ using
//style, plain English describing the next few lines
Files:
src/openms/source/METADATA/MetaInfoInterface.cppsrc/openms/source/METADATA/MetaInfo.cpp
src/openms/**/*.{h,hpp,hxx,cpp,cc,cxx}
📄 CodeRabbit inference engine (AGENTS.md)
Include
$Maintainer:$marker in file preamble of every header and source file
Files:
src/openms/source/METADATA/MetaInfoInterface.cppsrc/openms/source/METADATA/MetaInfo.cppsrc/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/openms/**/*.{cpp,cc,cxx}
📄 CodeRabbit inference engine (AGENTS.md)
Use
OPENMS_LOG_WARN,OPENMS_LOG_INFO, and other OpenMS logging macros instead ofstd::coutorstd::cerr
Files:
src/openms/source/METADATA/MetaInfoInterface.cppsrc/openms/source/METADATA/MetaInfo.cpp
src/tests/class_tests/openms/**/*.cpp
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Write unit tests for new functionality
Files:
src/tests/class_tests/openms/source/MetaInfo_test.cpp
src/tests/class_tests/openms/source/**/*_test.cpp
📄 CodeRabbit inference engine (AGENTS.md)
src/tests/class_tests/openms/source/**/*_test.cpp: UseSTART_SECTIONandEND_SECTIONmacros in C++ unit tests; wrap template methods with 2+ arguments in parentheses
UseNEW_TMP_FILEmacro for each output file in tests to avoid side effects
Wrap template methods with 2+ arguments in parentheses when used withSTART_SECTIONmacro
Files:
src/tests/class_tests/openms/source/MetaInfo_test.cpp
src/openms/include/OpenMS/**/*.h
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Add Doxygen comments for new public methods and classes
Files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
**/*.{h,hpp,hxx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{h,hpp,hxx}: Never addusing namespaceorusing std::...in header files; allowed in.cppfiles only
Follow the Rule-of-0 or Rule-of-6 for class definitions; no user-defined destructors unless necessary
Files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/openms/include/**/*.{h,hpp,hxx}
📄 CodeRabbit inference engine (AGENTS.md)
src/openms/include/**/*.{h,hpp,hxx}: AddOPENMS_DLLAPImacro on all non-template exported classes, structs, functions, and variables; include in friend operator declarations
Use getter/setter pairs (get/set methods) for protected/private members; no reference getters for primitive types
Use Doxygen documentation with/** */block comments and@tags (not\backslash);@briefis required
Include@param[in],@param[out], or@param[in,out]direction tags for all method parameters in Doxygen documentation
Prefer forward declarations in headers; include only base class headers, non-pointer members, and templates
Always implement and include$Maintainer:marker in file headers, along with$Authors:and copyright notice
Files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
src/openms/include/**/*.h
📄 CodeRabbit inference engine (AGENTS.md)
Use templates with
_impl.honly when needed;.hfiles must not include_impl.h
Files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
🧠 Learnings (8)
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality
Applied to files:
src/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2026-01-07T06:33:27.217Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.217Z
Learning: Add unit tests in `src/tests/class_tests/openms/source/ClassName_test.cpp` and register in `executables.cmake` for all new classes
Applied to files:
src/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/tests/class_tests/openms/source/**/*_test.cpp : Use `START_SECTION` and `END_SECTION` macros in C++ unit tests; wrap template methods with 2+ arguments in parentheses
Applied to files:
src/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/*Test.cpp : Follow naming convention: `ClassNameTest.cpp` for `ClassName`
Applied to files:
src/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/tests/class_tests/openms/source/**/*_test.cpp : Use `NEW_TMP_FILE` macro for each output file in tests to avoid side effects
Applied to files:
src/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2025-09-03T12:58:20.032Z
Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8177
File: src/tests/topp/CMakeLists.txt:1857-1865
Timestamp: 2025-09-03T12:58:20.032Z
Learning: OpenMS tests: When adding new TOPP tests in src/tests/topp/CMakeLists.txt that compare outputs via FuzzyDiff, always add set_tests_properties("<tool>_<n>_out<m>" PROPERTIES DEPENDS "<tool>_<n>") to avoid flakiness under parallel CTest runs.
Applied to files:
src/tests/class_tests/openms/source/MetaInfo_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use appropriate OpenMS containers and algorithms
Applied to files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.hsrc/openms/include/OpenMS/METADATA/MetaInfo.h
📚 Learning: 2026-01-07T06:33:27.218Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-07T06:33:27.218Z
Learning: Applies to src/openms/include/**/*.{h,hpp,hxx} : Prefer forward declarations in headers; include only base class headers, non-pointer members, and templates
Applied to files:
src/openms/include/OpenMS/METADATA/MetaInfoInterface.h
🧬 Code graph analysis (3)
src/openms/source/METADATA/MetaInfoInterface.cpp (2)
src/openms/include/OpenMS/METADATA/MetaInfo.h (1)
empty(120-136)src/openms/source/METADATA/MetaInfo.cpp (2)
empty(182-185)empty(182-182)
src/tests/class_tests/openms/source/MetaInfo_test.cpp (3)
src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp (2)
START_SECTION(412-429)START_SECTION(414-414)src/openms/source/METADATA/MetaInfo.cpp (3)
MetaInfo(18-18)empty(182-185)empty(182-182)src/openms/include/OpenMS/METADATA/MetaInfo.h (3)
begin(161-161)end(167-167)empty(120-136)
src/openms/include/OpenMS/METADATA/MetaInfo.h (1)
src/openms/source/METADATA/MetaInfo.cpp (7)
MetaInfo(18-18)rhs(20-23)rhs(20-20)rhs(25-28)rhs(25-25)rhs(30-78)rhs(30-30)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: build-lnx-arm
- GitHub Check: build-lnx
- GitHub Check: build-win
- GitHub Check: build-macos-arm
- GitHub Check: build-and-test (windows-2025, cl.exe, 14.44)
- GitHub Check: build-and-test (ubuntu-24.04-arm, g++, 13)
- GitHub Check: build-and-test (macos-14, xcode, 15.4)
- GitHub Check: build-and-test (ubuntu-24.04, clang++, 17)
- GitHub Check: build-and-test (ubuntu-24.04, g++, 13)
- GitHub Check: cppcheck-test
🔇 Additional comments (5)
src/openms/include/OpenMS/METADATA/MetaInfo.h (2)
76-89: operator+= contract is clear and matches the implementation.Docs explicitly state overwrite semantics and expected complexity.
125-175: The iterator/size accessors are correct. The note warning users that modifying the key may invalidate the sorted order invariant is accurate—boost::container::flat_mapusesstd::pair<Key, T>(notstd::pair<const Key, T>), so keys are indeed mutable via iterator. No adjustment needed.src/openms/include/OpenMS/METADATA/MetaInfoInterface.h (2)
16-17: IncludingMetaInfo.hhere is reasonable given the exposed iterator typedef.A forward declaration can’t provide
MetaInfo::const_iterator, so the include is justified. (Based on learnings, prefer forward declarations unless the full definition is required.)
38-45: Public iterator accessors are a solid addition; ensure null-meta empty-range is truly safe.The API contract says “empty range if null internal pointer”; the .cpp implementation must ensure
metaBegin()/metaEnd()iterators come from the same sentinel container (see critical note on MetaInfoInterface.cpp).Also applies to: 114-145
src/openms/source/METADATA/MetaInfoInterface.cpp (1)
244-252:addMetaValues()fast-path + merge usage looks great.Early-return on null/empty source and using
operator+=is a clear win in complexity and avoids per-key overhead.
Summary
Addresses #8076 by:
MetaInfoandMetaInfoInterfaceto eliminategetKeys()allocation overheadoperator+=using O(n+m) two-way merge algorithmaddMetaValues()to useoperator+=directlyChanges
MetaInfo.h
MapType,iterator,const_iteratortype aliases (public)begin()/end()/cbegin()/cend()iterator methodssize()method for O(1) size queriesoperator+=with optimized two-way merge usingboost::ordered_unique_rangeMetaInfoInterface.h
MetaInfoConstIteratortypedefmetaBegin()/metaEnd()/metaSize()iterator methodsgetMetaInfo()for direct MetaInfo access (returns nullptr if empty)std::hash<MetaInfoInterface>to use iterators (avoids allocations)MetaInfoInterface.cpp
addMetaValues()to use*meta_ += *from.meta_directlyPerformance Impact
operator+=addMetaValues()Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements
Tests
✏️ Tip: You can customize this high-level summary in your review settings.