Skip to content

Foundation Classes, NCollection - Add OrderedMap and OrderedDataMap containers#1072

Merged
dpasukhi merged 2 commits intoOpen-Cascade-SAS:IRfrom
dpasukhi:ncol_ordered_map
Feb 12, 2026
Merged

Foundation Classes, NCollection - Add OrderedMap and OrderedDataMap containers#1072
dpasukhi merged 2 commits intoOpen-Cascade-SAS:IRfrom
dpasukhi:ncol_ordered_map

Conversation

@dpasukhi
Copy link
Member

Add two new hash-based containers that preserve insertion order via an intrusive doubly-linked list threaded through the hash nodes:

  • NCollection_OrderedMap (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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot uses AI. Check for mistakes.
…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.
@dpasukhi dpasukhi changed the title Foundation Classes, NCollection - Add OrderedMap and OrderedDataMap c ontainers Foundation Classes, NCollection - Add OrderedMap and OrderedDataMap containers Feb 12, 2026
@dpasukhi dpasukhi merged commit 27788ce into Open-Cascade-SAS:IR Feb 12, 2026
18 checks passed
@dpasukhi dpasukhi deleted the ncol_ordered_map branch February 12, 2026 22:56
@github-project-automation github-project-automation bot moved this from Todo to Done in Maintenance Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants