eric-milles commented on pull request #1456:
URL: https://github.com/apache/groovy/pull/1456#issuecomment-760479409


   The actual implementation for `get(int i)` in `LinkedList` starts from head 
or tail:
   ```java
       public E get(int index) {
           checkElementIndex(index);
           return node(index).item;
       }
       Node<E> node(int index) {
           // assert isElementIndex(index);
   
           if (index < (size >> 1)) {
               Node<E> x = first;
               for (int i = 0; i < index; i++)
                   x = x.next;
               return x;
           } else {
               Node<E> x = last;
               for (int i = size - 1; i > index; i--)
                   x = x.prev;
               return x;
           }
       }
   ```
   
   So `last(List)` is not O(n) if that was the perception.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to