Repository navigation
Preserve equivalent element order during deserialization of multimap and multiset (#865) - #890
Open
Tyagiquamar wants to merge 1 commit into
Open
Tyagiquamar wants to merge 1 commit into
Tyagiquamar wants to merge 1 commit into
Conversation
|
您的邮件我已收到,谢谢合作!
|
This branch has not been deployed
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.
Summary of Changes
Fixes #865
In standard C++ containers with equivalent keys (
std::multimapandstd::multiset), the relative order of elements that compare equivalent is required to be preserved as their order of insertion.Previously,
pair_associative_container.hppandset.hppinitialized their insertion hint tomap.begin()/set.begin(), and then passed the iterator returned byemplace_hint()into the next iteration. Because associative container hint insertion inserts the new element immediately prior to the hint position, using the previous element's iterator as a hint caused each successive equivalent key to be inserted before the preceding one, reversing the order of equivalent keys on every serialization round-trip.This change fixes the deserialization behavior:
pair_associative_container.hppto passmap.end()as the insertion hint. Because serialized archives are written in forward sorted order, incoming elements belong at the end of the container, preserving the original sequence of equivalent keys in O(1) amortized insertion time.set.hppto passset.end()as the insertion hint for set and multiset containers.unittests/multimap.hppandunittests/multiset.hppwith full sequence equality assertions (std::equal) in addition to count checks.unittests/multimap.cppandunittests/multiset.cpp.Verification
All unit tests passed in Linux Docker (
gcc:14.3.0):