Foundation Classes, NCollection - Add OrderedMap and OrderedDataMap containers#1072
Merged
dpasukhi merged 2 commits intoOpen-Cascade-SAS:IRfrom Feb 12, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces two new insertion-order-preserving hash containers to OCCT's NCollection module. These containers combine O(1) hash lookup with deterministic iteration order via an intrusive doubly-linked list threaded through hash nodes, offering an alternative to IndexedMap/IndexedDataMap with O(1) removal instead of O(n).
Changes:
- Added
NCollection_OrderedMap<K>for key-only sets with insertion order preservation - Added
NCollection_OrderedDataMap<K,V>for key-value maps with insertion order preservation - Comprehensive test coverage (85+ tests) for both containers covering edge cases, move semantics, and custom hashers
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| NCollection_OrderedMap.hxx | Header-only template for ordered key set with O(1) operations |
| NCollection_OrderedDataMap.hxx | Header-only template for ordered key-value map with O(1) operations |
| NCollection/FILES.cmake | Registered new header files in build system |
| NCollection_OrderedMap_Test.cxx | 27 test cases covering OrderedMap functionality |
| NCollection_OrderedDataMap_Test.cxx | 58 test cases covering OrderedDataMap functionality |
| GTests/FILES.cmake | Registered new test files in build system |
| return &p->ChangeValue(); | ||
| } | ||
|
|
||
| //! ChangeFind returns mofifiable Item by Key. Raises if Key was not bound |
There was a problem hiding this comment.
Corrected spelling of 'mofifiable' to 'modifiable'.
Suggested change
| //! ChangeFind returns mofifiable Item by Key. Raises if Key was not bound | |
| //! ChangeFind returns modifiable Item by Key. Raises if Key was not bound |
…ontainers Add two new hash-based containers that preserve insertion order via an intrusive doubly-linked list threaded through the hash nodes: - NCollection_OrderedMap<K> (key-only, like NCollection_Map) - NCollection_OrderedDataMap<K,V> (key-value, like NCollection_DataMap) Both provide O(1) hash lookup, O(1) append/remove, and deterministic iteration in insertion order. Removal unlinks from the doubly-linked list in O(1), unlike NCollection_IndexedMap which requires O(n) swap-and-shrink on its dense array. Public API mirrors the corresponding unordered containers: - OrderedMap: Add, Added, Emplace, Emplaced, TryEmplace, TryEmplaced, Contains, Contained, Remove, First, Last - OrderedDataMap: Bind, Bound, TryBind, TryBound, Emplace, Emplaced, TryEmplace, TryEmplaced, IsBound, Contained, UnBind, Seek, Find, ChangeSeek, ChangeFind, Items, First, Last, FirstValue, LastValue, ChangeFirstValue, ChangeLastValue Both containers are header-only templates inheriting NCollection_BaseMap. Iterators walk the linked list (not bucket chains) and are compatible with NCollection_StlIterator for STL range-based for loops. GTests added: 85 tests covering insertion order preservation, add/remove in all positions, copy/move/assign/exchange semantics, resize stability, First/Last access, Contained optional lookup, TryEmplace/TryEmplaced no-overwrite semantics, structured bindings via Items(), and custom stateful hashers.
…lection_OrderedDataMap
02b26bb to
fa28fa7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add two new hash-based containers that preserve insertion order via an intrusive doubly-linked list threaded through the hash nodes:
Both provide O(1) hash lookup, O(1) append/remove, and deterministic iteration in insertion order. Removal unlinks from the doubly-linked list in O(1), unlike NCollection_IndexedMap which requires O(n) swap-and-shrink on its dense array.
Public API mirrors the corresponding unordered containers:
Both containers are header-only templates inheriting NCollection_BaseMap. Iterators walk the linked list (not bucket chains) and are compatible with NCollection_StlIterator for STL range-based for loops.
GTests added: 85 tests covering insertion order preservation, add/remove in all positions, copy/move/assign/exchange semantics, resize stability, First/Last access, Contained optional lookup, TryEmplace/TryEmplaced no-overwrite semantics, structured bindings via Items(), and custom stateful hashers.