| 51 | |
| 52 | // Comparator that compares only keys |
| 53 | struct KeyCompareWithId { |
| 54 | Compare mComp; |
| 55 | |
| 56 | KeyCompareWithId(const Compare& comp = Compare()) : mComp(comp) {} |
| 57 | |
| 58 | bool operator()(const ValueWithId& a, const ValueWithId& b) const { |
| 59 | // Compare keys; if keys are equal, compare IDs to maintain stable order |
| 60 | if (mComp(a.value, b.value)) { |
| 61 | return true; |
| 62 | } |
| 63 | if (mComp(b.value, a.value)) { |
| 64 | return false; |
| 65 | } |
| 66 | // Keys are equal - use ID for ordering |
| 67 | return a.unique_id < b.unique_id; |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | using TreeType = RedBlackTree<ValueWithId, KeyCompareWithId, Allocator>; |
| 72 | TreeType mTree; |