Random access in ArrayDeque

Martin Buchholz martinrb at google.com
Tue Feb 11 23:16:42 UTC 2014


On Sat, Feb 8, 2014 at 11:33 AM, Doug Lea <dl at cs.oswego.edu> wrote:

> On 02/07/2014 01:59 PM, Martin Buchholz wrote:
>
>  ArrayDeque should implement most of the methods in List, notably get(i).
>>
>> ArrayDeque should not actually implement List itself, because the change
>> in
>> contract/behavior for hashCode/equals would be too great.
>>
>
> Right. My vague recollection is that these were among initial reasons
> for not implementing List. Also, the List.sublist method is questionable
> for a Queue.
>

I don't think of ArrayDeque as a queue/deque at all.  We just have two
fundamental data structures here (ArrayList (ordinary resizable array) and
ArrayDeque (circular resizable array)) both of which can implement List and
Queue in reasonable ways, and ArrayDeque can additionally implement Deque.
 ArrayList.subList/listIterator implement "live" views with
ConcurrentModificationException checking.  I don't see why ArrayDeque
couldn't do the same - that's what users will expect.

You don't really need an asList method - subList(0, size()) would be
equivalent. Although making an independent copy on asList is also
attractive for avoiding overhead.

I started some implementation work - mostly just very tedious in the way
we're used to maintaining java.util collections.



More information about the core-libs-dev mailing list