--- a/ReindexedCollection.st Fri May 14 13:39:41 2004 +0200
+++ b/ReindexedCollection.st Mon Jun 07 11:05:31 2004 +0200
@@ -15,6 +15,10 @@
with in linear algorithm.
The elements in the ReindexedCollection are elements in the sequenceable collection at
some start to some stop at some step.
+
+ ReindexedCollection allows for efficient use of first/rest-like algorithms (i.e. aka Lisp)
+ applied to Sequenceable collections, as they avoid element-copying.
+
See class side examples.
[Instance Variables:]
@@ -182,6 +186,87 @@
self shouldNotImplement
! !
+!ReindexedCollection methodsFor:'converting-reindexed'!
+
+from:startIndex
+ "return a new collection representing the receivers elements starting at startIndex."
+
+ interval step == 1 ifTrue:[
+ ^ ReindexedCollection
+ on:sequence
+ from:(interval start + startIndex - 1)
+ to:(interval stop)
+ by:(interval step)
+ ].
+ "could be more intelligent here..."
+ ^ super from:startIndex
+
+ "
+ |coll cdr cddr cdddr|
+
+ coll := #(1 2 3 4 5 6 7 8 9 10).
+ cdr := coll from:2.
+ cddr := cdr from:2.
+ cdddr := cddr from:2.
+ "
+!
+
+from:startIndex to:stopIndex
+ "return a new collection representing the receivers elements
+ starting at startIndex upTo and including endIndex."
+
+ interval step == 1 ifTrue:[
+ ^ ReindexedCollection
+ on:sequence
+ from:(interval start + startIndex - 1)
+ to:((interval start + stopIndex - 1) min:interval stop)
+ by:1
+ ].
+ "could be more intelligent here..."
+ ^ super from:startIndex to:stopIndex
+
+ "
+ |coll cdrButLast cddrButLast2 cdddrButLast3|
+
+ coll := #(1 2 3 4 5 6 7 8 9 10).
+ cdrButLast := coll from:2 to:9.
+ cddrButLast2 := cdrButLast from:2 to:7.
+ cdddrButLast3 := cddrButLast2 from:2 to:5.
+ "
+
+ "
+ |coll cdrButLast cddrButLast2 cdddrButLast3|
+
+ coll := 1 to:100.
+ cdrButLast := coll from:2 to:99.
+ cddrButLast2 := cdrButLast from:2 to:97.
+ cdddrButLast3 := cddrButLast2 from:2 to:95.
+ "
+!
+
+to:stopIndex
+ "return a new collection representing the receivers elements upTo and including endIndex."
+
+ interval step == 1 ifTrue:[
+ ^ ReindexedCollection
+ on:sequence
+ from:(interval start)
+ to:((interval start + stopIndex - 1) min:interval stop)
+ by:1
+ ].
+ "could be more intelligent here..."
+ ^ super to:stopIndex
+
+ "
+ |coll butLast butLast2 butLast3|
+
+ coll := #(1 2 3 4 5 6 7 8 9 10).
+ butLast := coll to:9.
+ butLast2 := butLast to:8.
+ butLast3 := butLast2 to:7.
+ "
+! !
+
!ReindexedCollection methodsFor:'initialization'!
initialize: aSequence from: start to: stop by: step
@@ -205,5 +290,5 @@
!ReindexedCollection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/ReindexedCollection.st,v 1.2 2003-05-04 17:10:57 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/ReindexedCollection.st,v 1.3 2004-06-07 09:05:31 cg Exp $'
! !