mengdiwang / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

A sorted ComputingMap #504

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'd like to be able to construct a ComputingMap with sorted keys. 
Alternatively, I'd like to be able to combine the functionality of two 
different map types. For example, I'd like be able to construct a SortedMap 
"view" on top of a ComputingMap or vice versa.

See http://stackoverflow.com/questions/4519382/a-sorted-computingmap for a 
related discussion.

Original issue reported on code.google.com by cowwoc...@gmail.com on 24 Dec 2010 at 5:18

GoogleCodeExporter commented 9 years ago
You could use ForwardingMap with the ComputingMap as the delegate.

Original comment by boppenh...@google.com on 31 Dec 2010 at 6:27

GoogleCodeExporter commented 9 years ago
How will using ForwardingMap result in sorted keys?

Original comment by cowwoc...@gmail.com on 1 Jan 2011 at 3:36

GoogleCodeExporter commented 9 years ago
You would need override the appropriate method(s) of ForwardingMap.

Original comment by boppenh...@google.com on 1 Jan 2011 at 9:30

GoogleCodeExporter commented 9 years ago
Sorry, you're going to have to give me a bit more guidance here. Are you 
proposing the following?

1. The ForwardingMap should maintain references to a TreeMap and a ComputingMap.
2. Anytime the user requests a value, the TreeMap is consulted first. If it is 
missing the key, the ComputingMap is used to generate it.
3. Anytime a key is computed, it is added into the TreeMap.
4. iterator() iterates over the TreeMap (ignoring the ComputingMap)

So far so good, but then how do I get expiring keys to work?

Original comment by cowwoc...@gmail.com on 1 Jan 2011 at 9:09

GoogleCodeExporter commented 9 years ago
This was my mistake, I forgot that entrySet and keySet return mutable views and 
not immutable snapshots.  My proposed solution is probably not feasible.  If I 
think of something better, I'll post again.

Original comment by boppenh...@google.com on 1 Jan 2011 at 10:20

GoogleCodeExporter commented 9 years ago
I'm afraid that a sorted version of our computing map would be a *very* large 
effort and require extreme duplication of code from MapMaker, and I don't 
expect this would ever be a priority.  I agree with Ben Manes's advice on SO.

Original comment by kevinb@google.com on 12 Jan 2011 at 9:37

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09