Re: Why doesn't ArrayDeque implement the List interface?



Giovanni Azua wrote:
"Mike Schilling" <mscottschilling@xxxxxxxxxxx> wrote
No, the get method would be trivial to implement:

public T get(int i)
{
if ( i < 0 || i >= size)
throw new IllegalIndexException();
return members[(firstIndex + i) % size];
}

No, I was not refering to this access method but to a binary search method.

But indexed get is the method the OP needs that ArrayDeque does not
implement.

If ArrayDeque did implement a fast get(i), it would meet the conditions
for the RandomAccess interface, and would presumably implement it. The
binarySearch in Collections would be O(log n). There would be no need to
do anything (other than implement RandomAccess) in ArrayDeque to
implement binary search.

Even more trivial would be just to myDeque.getArray() and get the i-th element.

As far as I can tell, ArrayDeque does not have a getArray method. If you
mean toArray, that is not a solution because it is an O(n) operation. It
is the same time complexity, and higher space complexity, than the
LinkedList random element indexed get.

If the List is not performance-critical the choice of implementing class
does not matter. Any List would be as good as any other List. This
discussion only makes sense in the context of a need for a List that
has both fast indexed access and fast head and tail insert and delete.

Patricia
.