# HG changeset patch # User Claus Gittinger # Date 1140014254 -3600 # Node ID 62e21d3b40e206d2f23a232070ede65d8584e52a # Parent 4f4898011dd5a39dff4b7b3ed06d39d5e5d44a66 *** empty log message *** diff -r 4f4898011dd5 -r 62e21d3b40e2 LinkedList.st --- a/LinkedList.st Wed Feb 15 14:51:31 2006 +0100 +++ b/LinkedList.st Wed Feb 15 15:37:34 2006 +0100 @@ -146,15 +146,25 @@ Notice, that many methods in SeqColl are based on at:-access, so other inherited methods may be very slow (showing square runtime)." + ^ self at:index ifAbsent:[ self subscriptBoundsError:index] +! + +at: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 index 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:[^ self subscriptBoundsError:index]. - theLink := theLink nextLink. - runIndex := runIndex + 1. + theLink isNil ifTrue:[^ exceptionBlock value]. + theLink := theLink nextLink. + runIndex := runIndex + 1. ]. ^ theLink ! @@ -412,5 +422,5 @@ !LinkedList class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.34 2000-08-22 13:48:28 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.35 2006-02-15 14:37:34 cg Exp $' ! !