You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mahout.apache.org by Benson Margulies <bi...@gmail.com> on 2010/01/10 21:17:23 UTC

[math] Question of taste: 'ObjectArrayList'

Colt brought us 'ObjectArrayList'. You might ask, what advantage does
it have over ArrayList<T>?

Well, I just found myself writing the following to use ArrayList<T> in
the xxxObjectHashMap set. I could rework ObjectArrayList to be a
subclass of ArrayList that provided this efficiently, instead of my
current plan to throw it out altogether once I've got other things
cleaned up. Thoughts?

  private void resizeArrayList(ArrayList<T> l, int size) {
    while (size < l.size()) {
      l.add(null);
    }
    while(size > l.size()) {
      l.remove(l.size()-1);
    }
  }

Re: [math] Question of taste: 'ObjectArrayList'

Posted by Benson Margulies <bi...@gmail.com>.
Ted,

I had much the same thoughts while driving to the grocery store after
sending that message.

Death to the class, and I'll clean up the implementation of the users
of the resize business.

--benson


On Sun, Jan 10, 2010 at 4:38 PM, Ted Dunning <te...@gmail.com> wrote:
> I take it that the point of this code is to allow filling an ArrayList with
> null values efficiently.  This might sometimes be useful, I suppose.
>
> It sounds like you are saying that the virtue of the ObjectArrayList is that
> we own it and can make this resizing method efficient.  I don't see any
> advantage of that strategy versus forking some other implementation or even
> starting a new implementation from scratch.  I am also not clear on the
> virtues of this resizing in general.  In particular, the idiom
>
>    if (l.size() > size) l.sublist(size, l.size() - size).clear()
>
> seems a better way to clear a bunch of values.  Collections.fill() applied
> to a sublist should be good as well.
>
> If you just need to fill in an ArrayList quickly to a desired size, then
> addAll from a static list of nulls could be a bit faster.  Is speed really
> important here, though?
>
> As a side note, the tests in your code appear to be backwards.
>
> On Sun, Jan 10, 2010 at 12:17 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> Colt brought us 'ObjectArrayList'. You might ask, what advantage does
>> it have over ArrayList<T>?
>>
>> Well, I just found myself writing the following to use ArrayList<T> in
>> the xxxObjectHashMap set. I could rework ObjectArrayList to be a
>> subclass of ArrayList that provided this efficiently, instead of my
>> current plan to throw it out altogether once I've got other things
>> cleaned up. Thoughts?
>>
>>  private void resizeArrayList(ArrayList<T> l, int size) {
>>    while (size < l.size()) {
>>      l.add(null);
>>    }
>>    while(size > l.size()) {
>>      l.remove(l.size()-1);
>>    }
>>  }
>>
>
>
>
> --
> Ted Dunning, CTO
> DeepDyve
>

Re: [math] Question of taste: 'ObjectArrayList'

Posted by Benson Margulies <bi...@gmail.com>.
p.s.

.sdrawkcab si od I gnihtyreve os cibaraA tuoba gnikniht neeb evah I.

On Sun, Jan 10, 2010 at 4:38 PM, Ted Dunning <te...@gmail.com> wrote:
> I take it that the point of this code is to allow filling an ArrayList with
> null values efficiently.  This might sometimes be useful, I suppose.
>
> It sounds like you are saying that the virtue of the ObjectArrayList is that
> we own it and can make this resizing method efficient.  I don't see any
> advantage of that strategy versus forking some other implementation or even
> starting a new implementation from scratch.  I am also not clear on the
> virtues of this resizing in general.  In particular, the idiom
>
>    if (l.size() > size) l.sublist(size, l.size() - size).clear()
>
> seems a better way to clear a bunch of values.  Collections.fill() applied
> to a sublist should be good as well.
>
> If you just need to fill in an ArrayList quickly to a desired size, then
> addAll from a static list of nulls could be a bit faster.  Is speed really
> important here, though?
>
> As a side note, the tests in your code appear to be backwards.
>
> On Sun, Jan 10, 2010 at 12:17 PM, Benson Margulies <bi...@gmail.com>wrote:
>
>> Colt brought us 'ObjectArrayList'. You might ask, what advantage does
>> it have over ArrayList<T>?
>>
>> Well, I just found myself writing the following to use ArrayList<T> in
>> the xxxObjectHashMap set. I could rework ObjectArrayList to be a
>> subclass of ArrayList that provided this efficiently, instead of my
>> current plan to throw it out altogether once I've got other things
>> cleaned up. Thoughts?
>>
>>  private void resizeArrayList(ArrayList<T> l, int size) {
>>    while (size < l.size()) {
>>      l.add(null);
>>    }
>>    while(size > l.size()) {
>>      l.remove(l.size()-1);
>>    }
>>  }
>>
>
>
>
> --
> Ted Dunning, CTO
> DeepDyve
>

Re: [math] Question of taste: 'ObjectArrayList'

Posted by Ted Dunning <te...@gmail.com>.
I take it that the point of this code is to allow filling an ArrayList with
null values efficiently.  This might sometimes be useful, I suppose.

It sounds like you are saying that the virtue of the ObjectArrayList is that
we own it and can make this resizing method efficient.  I don't see any
advantage of that strategy versus forking some other implementation or even
starting a new implementation from scratch.  I am also not clear on the
virtues of this resizing in general.  In particular, the idiom

    if (l.size() > size) l.sublist(size, l.size() - size).clear()

seems a better way to clear a bunch of values.  Collections.fill() applied
to a sublist should be good as well.

If you just need to fill in an ArrayList quickly to a desired size, then
addAll from a static list of nulls could be a bit faster.  Is speed really
important here, though?

As a side note, the tests in your code appear to be backwards.

On Sun, Jan 10, 2010 at 12:17 PM, Benson Margulies <bi...@gmail.com>wrote:

> Colt brought us 'ObjectArrayList'. You might ask, what advantage does
> it have over ArrayList<T>?
>
> Well, I just found myself writing the following to use ArrayList<T> in
> the xxxObjectHashMap set. I could rework ObjectArrayList to be a
> subclass of ArrayList that provided this efficiently, instead of my
> current plan to throw it out altogether once I've got other things
> cleaned up. Thoughts?
>
>  private void resizeArrayList(ArrayList<T> l, int size) {
>    while (size < l.size()) {
>      l.add(null);
>    }
>    while(size > l.size()) {
>      l.remove(l.size()-1);
>    }
>  }
>



-- 
Ted Dunning, CTO
DeepDyve

Re: [math] Question of taste: 'ObjectArrayList'

Posted by Sean Owen <sr...@gmail.com>.
I weakly vote for chucking it out.

On Sun, Jan 10, 2010 at 8:17 PM, Benson Margulies <bi...@gmail.com> wrote:
> Colt brought us 'ObjectArrayList'. You might ask, what advantage does
> it have over ArrayList<T>?
>