--- 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 $'
! !