Re: Why doesn't ArrayDeque implement the List interface?
- From: Patricia Shanahan <pats@xxxxxxx>
- Date: Tue, 10 Mar 2009 09:05:56 -0700
Giovanni Azua wrote:
"Mike Schilling" <mscottschilling@xxxxxxxxxxx> wroteNo, the get method would be trivial to implement:No, I was not refering to this access method but to a binary search method.
public T get(int i)
{
if ( i < 0 || i >= size)
throw new IllegalIndexException();
return members[(firstIndex + i) % size];
}
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
.
- References:
- Why doesn't ArrayDeque implement the List interface?
- From: Joe Gottman
- Re: Why doesn't ArrayDeque implement the List interface?
- From: Giovanni Azua
- Re: Why doesn't ArrayDeque implement the List interface?
- From: Mike Schilling
- Re: Why doesn't ArrayDeque implement the List interface?
- From: Giovanni Azua
- Re: Why doesn't ArrayDeque implement the List interface?
- From: Joe Gottman
- Re: Why doesn't ArrayDeque implement the List interface?
- From: Giovanni Azua
- Re: Why doesn't ArrayDeque implement the List interface?
- From: Mike Schilling
- Re: Why doesn't ArrayDeque implement the List interface?
- From: Giovanni Azua
- Why doesn't ArrayDeque implement the List interface?
- Prev by Date: Re: Why doesn't ArrayDeque implement the List interface?
- Next by Date: Re: ONE ARRAYLIST IN MANY CLASSES QUESTION
- Previous by thread: Re: Why doesn't ArrayDeque implement the List interface?
- Next by thread: Re: Why doesn't ArrayDeque implement the List interface?
- Index(es):