Sized (original) (raw)

Brian Goetz brian.goetz at oracle.com
Fri Nov 2 15:53:09 PDT 2012


I think you're focusing on another problem. These things have size() methods already; I'm trying to capture this in a finer-grained interface. The "size in O(1) time" is a whole orthogonal concern.

On 11/2/2012 6:27 PM, Kevin Bourrillion wrote:

My mistake: CHM only has to walk through every /segment/ to add up the size, and I was thinking of it as actually traversing every element.

In any event. It's undeniably true that there are numerous implementations of Collection out there that don't know their size without completely iterating themselves. I still say that if there's any value in Sized, it lies in making those implementations /not/ implement it while others do.

On Fri, Nov 2, 2012 at 3:22 PM, Brian Goetz <brian.goetz at oracle.com_ _<mailto:brian.goetz at oracle.com>> wrote: Of course, some collections, like the key set of a ConcurrentHashMap, don't know their size any more than a garden-variety Iterable does. That's not exactly true. In the absence of interference from concurrent modification, the key set of a CHM absolutely knows its size. It's just that in the presence of interference, the reported size may be stale by the time you receive it.

-- Kevin Bourrillion | Java Librarian | Google, Inc. |kevinb at google.com <mailto:kevinb at google.com>



More information about the lambda-libs-spec-observers mailing list