class: OrderedDictionary
authorClaus Gittinger <cg@exept.de>
Fri, 11 Jul 2014 11:14:55 +0200
changeset 16765 72c7f90b2c4d
parent 16764 4b8fa96d42b0
child 16766 c71254785e72
class: OrderedDictionary comment/format in:5 methods changed: #copyWithout: fix: copyWithout returned the original collection; also tuned to avoid creating temporary assocs
OrderedDictionary.st
--- a/OrderedDictionary.st	Fri Jul 11 02:25:55 2014 +0200
+++ b/OrderedDictionary.st	Fri Jul 11 11:14:55 2014 +0200
@@ -473,9 +473,33 @@
      does not include the argument, anAssociation
      No error is reported, if elementToSkip is not in the collection."
 
-    | newDict |
+    | newDict keyToIgnore valueToIgnore|
+
     newDict := self species new:order size - 1.
-    self associationsDo:[:assoc | anAssociation = assoc ifFalse:[newDict add:assoc]]
+"/    self associationsDo:[:assoc | anAssociation = assoc ifFalse:[newDict add:assoc]].
+
+    keyToIgnore := anAssociation key.
+    valueToIgnore := anAssociation value.
+    self keysAndValuesDo:[:k :v |
+        (keyToIgnore = k and:[valueToIgnore = v]) ifFalse:[
+            newDict at:k put:v
+        ]
+    ].
+    ^ newDict.
+
+    "
+     |d d2|
+
+     d := OrderedDictionary new
+            at:1 put:'1';
+            at:2 put:'2';
+            at:3 put:'3';
+            at:4 put:'4';
+            at:5 put:'5';
+            yourself.
+     d2 := d copyWithout:(4->'4').
+     d2      
+    "
 !
 
 postCopy
@@ -495,7 +519,13 @@
 !
 
 associationsDo: aBlock 
-    "Evaluate aBlock for each of the dictionary's associations."
+    "Evaluate aBlock for each of the dictionary's associations.
+     Enumerate them in the order by which they were added.
+
+     See also:
+        #keysAndValuesDo:  (which passes keys & values separately)
+        #keysDo:           (which passes keys only)
+        #do:               (which passes values only)"
 
     order do: [:key | aBlock value: (self associationAt: key)]
 !
@@ -558,7 +588,8 @@
 !
 
 do: aBlock 
-    "Evaluate aBlock for each of the dictionary's values."
+    "Evaluate aBlock for each of the dictionary's values.
+     Enumerate them in the order by which they were added."
 
     order do: [:key | aBlock value: (self at: key)]
 !
@@ -663,7 +694,7 @@
 
      See also:
         #associationsDo:   (which passes key-value associations)
-        #keysAndValuesDo:  (which passes keys & values separately)
+        #keysDo:           (which passes keys only)
         #do:               (which passes values only)
 
      WARNING: do not add/remove elements while iterating over the receiver.
@@ -697,6 +728,7 @@
 
 keysDo:aBlock
     "evaluate the argument, aBlock for every key in the collection.
+     Enumerate them in the order by which they were added.
 
      See also:
         #associationsDo:   (which passes key-value associations)
@@ -714,7 +746,7 @@
 
 reverseDo: aBlock 
     "Evaluate aBlock with each of the dictionary's associations as the argument,
-    starting with the last element and taking each in sequence up to the first."
+     starting with the last added element and taking each in sequence up to the first."
 
     |sz  "{ Class:SmallInteger }"|
 
@@ -1072,10 +1104,10 @@
 !OrderedDictionary class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/OrderedDictionary.st,v 1.46 2014-03-05 13:19:29 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/OrderedDictionary.st,v 1.47 2014-07-11 09:14:55 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/OrderedDictionary.st,v 1.46 2014-03-05 13:19:29 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/OrderedDictionary.st,v 1.47 2014-07-11 09:14:55 cg Exp $'
 ! !