oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
authorca
Fri, 08 Mar 1996 11:02:11 +0100
changeset 1090 def6e50a2d13
parent 1089 6df9414b354f
child 1091 2c5955064bbd
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
OrdColl.st
OrderedCollection.st
--- a/OrdColl.st	Thu Mar 07 19:42:16 1996 +0100
+++ b/OrdColl.st	Fri Mar 08 11:02:11 1996 +0100
@@ -622,19 +622,32 @@
      passing both index and element as arguments."
 
     |start  "{ Class:SmallInteger }"
-     stop   "{ Class:SmallInteger }" |
+     stop   "{ Class:SmallInteger }" 
+     idx    "{ Class:SmallInteger }" |
 
     stop := lastIndex.
     start := firstIndex.
+    idx := 1.
     start to:stop do:[:index |
-	aTwoArgBlock value:index value:(contentsArray at:index)
+        aTwoArgBlock value:idx value:(contentsArray at:index).
+        idx := idx + 1.
     ]
 
     "
      #(10 20 30 40) asOrderedCollection keysAndValuesDo:[:index :value |
-	Transcript show:index; show:' '; showCr:value
+        Transcript show:index; show:' '; showCr:value
      ]  
     "
+    "
+     |oc|
+
+     oc := #(10 20 30 40 50 60 70 80) asOrderedCollection.
+     oc removeFirst; removeFirst.
+     oc keysAndValuesDo:[:index :value |
+        Transcript show:index; show:' '; showCr:value
+     ]  
+    "
+
 !
 
 keysAndValuesReverseDo:aTwoArgBlock
@@ -642,17 +655,30 @@
      passing both index and element as arguments."
 
     |start  "{ Class:SmallInteger }"
-     stop   "{ Class:SmallInteger }" |
+     stop   "{ Class:SmallInteger }" 
+     idx    "{ Class:SmallInteger }"|
 
     stop := lastIndex.
     start := firstIndex.
+    idx := (stop - start + 1).
     stop to:start by: -1 do:[:index |
-	aTwoArgBlock value:index value:(contentsArray at:index)
+        aTwoArgBlock value:idx value:(contentsArray at:index).
+        idx := idx - 1.
     ]
 
     "
      #(10 20 30 40) asOrderedCollection keysAndValuesReverseDo:[:index :value |
-	Transcript show:index; show:' '; showCr:value
+        Transcript show:index; show:' '; showCr:value
+     ]  
+    "
+
+    "
+     |oc|
+
+     oc := #(10 20 30 40 50 60 70 80) asOrderedCollection.
+     oc removeFirst; removeFirst.
+     oc keysAndValuesReverseDo:[:index :value |
+        Transcript show:index; show:' '; showCr:value
      ]  
     "
 !
@@ -1117,5 +1143,5 @@
 !OrderedCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.40 1996-03-06 15:03:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.41 1996-03-08 10:02:11 ca Exp $'
 ! !
--- a/OrderedCollection.st	Thu Mar 07 19:42:16 1996 +0100
+++ b/OrderedCollection.st	Fri Mar 08 11:02:11 1996 +0100
@@ -622,19 +622,32 @@
      passing both index and element as arguments."
 
     |start  "{ Class:SmallInteger }"
-     stop   "{ Class:SmallInteger }" |
+     stop   "{ Class:SmallInteger }" 
+     idx    "{ Class:SmallInteger }" |
 
     stop := lastIndex.
     start := firstIndex.
+    idx := 1.
     start to:stop do:[:index |
-	aTwoArgBlock value:index value:(contentsArray at:index)
+        aTwoArgBlock value:idx value:(contentsArray at:index).
+        idx := idx + 1.
     ]
 
     "
      #(10 20 30 40) asOrderedCollection keysAndValuesDo:[:index :value |
-	Transcript show:index; show:' '; showCr:value
+        Transcript show:index; show:' '; showCr:value
      ]  
     "
+    "
+     |oc|
+
+     oc := #(10 20 30 40 50 60 70 80) asOrderedCollection.
+     oc removeFirst; removeFirst.
+     oc keysAndValuesDo:[:index :value |
+        Transcript show:index; show:' '; showCr:value
+     ]  
+    "
+
 !
 
 keysAndValuesReverseDo:aTwoArgBlock
@@ -642,17 +655,30 @@
      passing both index and element as arguments."
 
     |start  "{ Class:SmallInteger }"
-     stop   "{ Class:SmallInteger }" |
+     stop   "{ Class:SmallInteger }" 
+     idx    "{ Class:SmallInteger }"|
 
     stop := lastIndex.
     start := firstIndex.
+    idx := (stop - start + 1).
     stop to:start by: -1 do:[:index |
-	aTwoArgBlock value:index value:(contentsArray at:index)
+        aTwoArgBlock value:idx value:(contentsArray at:index).
+        idx := idx - 1.
     ]
 
     "
      #(10 20 30 40) asOrderedCollection keysAndValuesReverseDo:[:index :value |
-	Transcript show:index; show:' '; showCr:value
+        Transcript show:index; show:' '; showCr:value
+     ]  
+    "
+
+    "
+     |oc|
+
+     oc := #(10 20 30 40 50 60 70 80) asOrderedCollection.
+     oc removeFirst; removeFirst.
+     oc keysAndValuesReverseDo:[:index :value |
+        Transcript show:index; show:' '; showCr:value
      ]  
     "
 !
@@ -1117,5 +1143,5 @@
 !OrderedCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.40 1996-03-06 15:03:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.41 1996-03-08 10:02:11 ca Exp $'
 ! !