-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Unimplement Map from CharSequenceMap to obey contract #11704
base: main
Are you sure you want to change the base?
Core: Unimplement Map from CharSequenceMap to obey contract #11704
Conversation
2c5fe4c
to
02cb792
Compare
BTW Guava has a concept of |
53b446f
to
1c03a14
Compare
1c03a14
to
fca920d
Compare
`CharSequenceMap` did not follow `Map` contract fully - `Map.keySet` is supposed to be a view, but `CharSequenceMap` returned a copy. Fixing this one can be hard given how `CharSequenceMap` is implemented internally. - `Map.equals` should compare maps by value. I.e. different map implementations with same key/value pairs are supposed to be equal. `CharSequenceMap` could certainly implement this correctly, but it does not today. The benefit of doing so is unclear and time necessary to do so correctly is non-negligible (we would need to define semantics what to when `CharSequenceMap` is compared to a map with more keys, but such that each key compared as char sequences is equal to some key in the `CharSequenceMap`). Also, having a Map implementation that does not compare the keys by equality is error-prone: - it's likely that new default Map interface methods assume equality-based comparison semantics. JDK maintains non-equality based Map implementation (Comparator-based and Identity-based), and it surely doesn't go without maintenance burden (and not without bugs either, e.g. https://bugs.openjdk.org/browse/JDK-8178355) - it's not unlikely someone tries to make a defensive copy of a map with `ImmutableMap.copyOf` or `Map.copyOf`, resulting in a map with different semantics. Instead of fixing the `CharSequenceMap` to obey the `Map` contract, it seems more pragmatic to just stop implementing the `Map` interface, which this commit does, resulting in a simple to understand class contract and behavior. This commit provides a copy of `CharSequenceMap`, `PathMap`, with `Map` interface removed. Additional positive side-effects of the change - less code and easier to understand contracts - strongly typed `get` and `containsKey` methods (the need to accept `Object` in these was forced by `Map` interface). `CharSequenceSet` has similar issues, to be addressed in a follow-up. Rename CharSequenceMap to PathMap Restore original CharSequenceMap Deprecate CharSequenceMap
fca920d
to
6e99c84
Compare
@nastra PTAL. after this lands i'd like to fix the |
Sorry for the delay. I'm a bit overloaded currently with reviews, so this might me take a while to get back to. Hopefully someone else can find some time to review this |
CharSequenceMap
did not followMap
contract fullyMap.keySet
is supposed to be a view, butCharSequenceMap
returned a copy. Fixing this one can be hard given howCharSequenceMap
is implemented internally.Map.equals
should compare maps by value. I.e. different map implementations with same key/value pairs are supposed to be equal.CharSequenceMap
could certainly implement this correctly, but it does not today. The benefit of doing so is unclear and time necessary to do so correctly is non-negligible (we would need to define semantics what to whenCharSequenceMap
is compared to a map with more keys, but such that each key compared as char sequences is equal to some key in theCharSequenceMap
).Also, having a Map implementation that does not compare the keys by equality is error-prone:
ImmutableMap.copyOf
orMap.copyOf
, resulting in a map with different semantics.Instead of fixing the
CharSequenceMap
to obey theMap
contract, it seems more pragmatic to just stop implementing theMap
interface, which this commit does, resulting in a simple to understand class contract and behavior.This PR provides a copy of
CharSequenceMap
,PathMap
, withMap
interface removed.Additional positive side-effects of the change
get
andcontainsKey
methods (the need to acceptObject
in these was forced byMap
interface).CharSequenceSet
has similar issues, to be addressed in a follow-up.cc @anuragmantri @aokolnychyi @amogh-jahagirdar @nastra