Repository navigation
keep DualTreeBidiMap consistent when changed through a sub map - #745
Open
rootvector2 wants to merge 1 commit into
Open
rootvector2 wants to merge 1 commit into
rootvector2 wants to merge 1 commit into
Conversation
A sub map view decorates an inner bidi map whose normalMap is restricted to the range while its reverseMap is the full map. Clearing the keySet, values or entrySet of a sub map wiped the whole reverse map, put could leave two keys with one value or drop a mapping before rejecting a key out of range, and values().remove() could drop the reverse entry of a value outside the range. The view now decorates a ViewBidiMap that handles the restricted normalMap.
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.
A
DualTreeBidiMapsub map (subMap,headMap,tailMap) decorates an inner bidi map whosenormalMapis restricted to the range while itsreverseMapis the full map, and the inheritedAbstractDualBidiMapcode assumes both hold the same mappings. SokeySet().clear(),values().clear(),entrySet().clear()andretainAllof an empty collection on a sub map wipe the whole reverse map,putof a value held by a key outside the range leaves two keys with that value, aputrejected for a key out of range has already removed the mapping that held the value, andvalues().remove()drops the reverse entry of a value outside the range. Found while readingViewMap, then measured with a randomized differential test of the sub maps againstTreeMap: 189778 of 500000 cases left the map and its inverse out of step.The view now decorates a private
ViewBidiMapthat overridesclear,containsValueandputfor the restrictednormalMap, andValues.contains/Values.removego through the parent map the wayView.clearalready does. The fix sits in the inner map becauseputAll, the collection views and nested sub maps all reach it, which the existingViewMap.clearandViewMap.containsValueoverrides could not cover. The differential test is clean over 1200000 cases after the change, and the newAbstractSortedBidiMapTestcases fail before it and pass after.mvn; that'smvnon the command line by itself.