Fix inconsistent indexing between LeftValues
and RightValues
#8
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.
I noticed something I overlooked when I first implemented$i$ corresponds to the same element regardless if accessed from
LeftValues
andRightValues
. In a standardDictionary
,Keys
andValues
share the same indices. That is, as long as the dictionary is not mutated and the indices remain stable, indexkeys
orvalues
:This is the expected behavior for index-based access in a$i$ refers to a different element in
Dictionary
. However,BijectiveDictionary
's current implementation has a bug. The reason the docs mention that order is not guaranteed forleftValues
andrightValues
is becauseLeftValues
uses_ltr
andRightValues
uses_rtl
. However, since_rtl
is a separate dictionary, it has different indices. This means indexleftValues
andrightValues
. This behavior is unexpected and is not consistent withDictionary
.Taking another look at this, there is no reason
RightValues
can’t also use_ltr
; this pull request modifiesRightValues
accordingly.