ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kev Jackson <>
Subject Re: Massively OT, 'Closures in Java' [was Re: AW: [Patch] modifiedselector, style, remove unused code, slightly more lazy DigestAlgorithm.getValue (now with added source code -doh!)]
Date Mon, 28 Feb 2005 11:18:54 GMT
Jose Alberto Fernandez wrote:

>AFAIU, LinkedList.get(N) requires traversing the list to position N
>on every call [O(n^2)], so usage of an iteratoe is much cheaper on this
>as there is no array behind the scenes. 
>Jose Alberto
I've just worked out why it's ok to do it this way (with respect to my 
particular use-case).  Basically I *want* to traverse the entire list, 
I'm not trying to pick out any particular position in the list (yes 
truly expensive using LinkedList.get(i)).  In my method I simply call 
get(i) from 0..List.size():

from docs
<quote>Operations that index into the list will traverse the list from 
the begining or the end, whichever is closer to the specified index.</quote>

So as I'm asking for position 0, the traversal starts at the head of the 
list, then I simply walk the list with the loop calling get(i), which 
also happens to be the next element in the list from where the list 
cursor currently is (ListIterator interface docs).  Serendipity I 
suppose, but my usage is the most efficient for LinkedLists and also 
happens to be performant with ArrayLists, to do the particular traversal 
that I'm doing.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message