TreeMap specific override of putIfAbsent/merge

Paul Sandoz paul.sandoz at oracle.com
Fri May 20 14:57:18 UTC 2016


Hi Tomasz,

If there was any rejection it was probably due to time constraints than for any technical reasons.

It should be easy to refactor the TreeMap.put implementation into say a private putVal accepting a boolean argument and both put and putIfAbsent call putVal (same pattern as in HashMap).

The compute* methods may require separate implementations with almost duplicated kind of patterns.

An OCA [1] compliant patch would be appreciated, which should also include updates to relevant tests where appropriate.

Thanks,
Paul.

[1] http://www.oracle.com/technetwork/community/oca-486395.html <http://www.oracle.com/technetwork/community/oca-486395.html>

> On 20 May 2016, at 15:19, Tomasz Kowalczewski <tomasz.kowalczewski at gmail.com> wrote:
> 
> Hi all,
> 
> TreeMap does not have its own specific overrides of Map methods that were
> added in java 8. In our specific usage we do what is effective a merge
> operation:
> 
> For incoming K and V:
> 1. get value from map
> 2. if present - merge with incoming value V
> 3. if absent - associate K with V in the map
> 
> For case where K is not in the map we traverse the tree map it twice.
> Implementing TreeMap specific override of putIfAbsent would allow as to
> avoid this cost.
> 
> Was such change considered in past and rejected? Is anyone interested in a
> patch that implements it?
> 
> --
> Regards,
> Tomasz Kowalczewski




More information about the core-libs-dev mailing list