Separate the lifetimes of each input of OrdMap::diff and OrdSet::diff #168
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.
This is a breaking change but only for code that uses turbofish syntax on the
diff
method, theDiffIter
type, or theDiffItem
type.Motivation:
We use
diff
in an algorithm that merges two maps similar tounion_with_key
, but tries to maximize sharing of internal nodes between similar maps. See "Stage 2" in #166. This works by collecting the results ofdiff
into twoVec
s of(key, value)
pairs that would need to be inserted in either input map in order to turn it into the desired merge/union. After that is done, we pick the smaller set of updates in order to decide which of the input maps to mutate.At the moment these
Vec
contain cloned keys and cloned values. With this PR, they could instead be borrowed with eachVec
only borrowing from one of the two input maps. After we’ve decided whichVec
to use, only its contents needs to be cloned for inserting into the mutated map.The full algorithm is at https://foss.heptapod.net/octobus/mercurial-devel/-/commit/53e9ccfaacd492852419cb9dca1abae1765a7474#1e7b6882ee05cf3bc9882ed81b2a0a8dac61ded6_179_182