[concurrency-interest] Questions about ArrayDeque

Joshua Bloch josh at bloch.us
Fri Jul 21 12:40:53 EDT 2006


Gregg,

I'm not sure what you mean. Rémi was talking about implementation
details, not visible APIs.  He proposed a new implementation for an
existing constructor that was broken in two ways (one of which I
pointed out, and the other, Martin).

           Josh

On 7/21/06, Gregg Wonderly <gregg at cytetech.com> wrote:
>
>
> Joshua Bloch wrote:
> > Rémi,
> >
> >
> >
> >>Ok, else, ArrayList used toArray() in its constructor that takes a
> >>collection,
> >>but ArrayDeque doesn't do the same trick, is there a reason ?
> >>
> >>The code can be something like this one :
> >>public ArrayDeque(Collection<? extends E> c) {
> >>        int size=c.size();
> >>        allocateElements(size);
> >>        c.toArray(elements);
> >>        tail=size;
> >>}
> >
> >
> > Yes, there is a reason:  internally, ArrayDeque instances have arrays
> > whose size are a power of two, so the aforementioned trick wouldn't
> > work.
>
> It should be easy enough to find the correct power of two for allocating right?
>  Then the APIs would be consistent.  These odd implementation details creeping
> into the visible API really adds a lot of confusion.
>
> Someones going to write some code to make it possible for them to stuff a
> Collection in.  Surely there's value in the class already having such an
> implementation?
>
> Gregg Wonderly
>



More information about the Concurrency-interest mailing list