diff -r 47341245c458 -r 46ac2aac776b LinkedList.st --- a/LinkedList.st Tue Dec 30 13:47:13 2014 +0100 +++ b/LinkedList.st Tue Dec 30 13:50:31 2014 +0100 @@ -215,6 +215,36 @@ lastLink isNil ifTrue:[self emptyCollectionError]. ^ lastLink +! + +linkAt:index + "return the n'th element - use of this method should be avoided, + since it is slow to walk through the list - think about using + another collection if you need indexed access. + Notice, that many methods in SeqColl are based on at:-access, + so other inherited methods may be very slow (showing square runtime)." + + ^ self linkAt:index ifAbsent:[ self subscriptBoundsError:index] +! + +linkAt:index ifAbsent:exceptionBlock + "return the n'th element - use of this method should be avoided, + since it is slow to walk through the list - think about using + another collection if you need indexed access. + Notice, that many methods in SeqColl are based on at:-access, + so other inherited methods may be very slow (showing square runtime)." + + |theLink + runIndex "{Class: SmallInteger}"| + + theLink := firstLink. + runIndex := 1. + [runIndex == index] whileFalse:[ + theLink isNil ifTrue:[^ exceptionBlock value]. + theLink := theLink nextLink. + runIndex := runIndex + 1. + ]. + ^ theLink ! ! !LinkedList methodsFor:'adding & removing'! @@ -478,10 +508,10 @@ !LinkedList class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.46 2014-12-30 00:36:46 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.47 2014-12-30 12:50:31 cg Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.46 2014-12-30 00:36:46 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.47 2014-12-30 12:50:31 cg Exp $' ! !