#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Thu, 26 Apr 2018 18:00:16 +0200
changeset 22714 cdb3f825f5ae
parent 22713 a92c5ffef073
child 22715 c938e3910594
#FEATURE by cg class: Collection added: #copyWithout:
Collection.st
--- a/Collection.st	Thu Apr 26 15:39:51 2018 +0200
+++ b/Collection.st	Thu Apr 26 18:00:16 2018 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
               All Rights Reserved
@@ -366,6 +368,7 @@
     ^ self
 ! !
 
+
 !Collection methodsFor:'Compatibility-ANSI'!
 
 identityIncludes:anObject
@@ -2373,6 +2376,28 @@
     ^ newColl
 !
 
+copyWithout:elementToSkip
+    "return a new collection consisting of a copy of the receiver, 
+     with ALL elements equal to elementToSkip left out.
+     No error is reported, if elementToSkip is not in the collection.
+     This is a slow generic fallback. Many collections redefine this for performance."
+
+    |copy|
+
+    copy := self species new.
+    self do:[:each |
+        each = elementToSkip ifFalse:[
+            copy add:each
+        ].
+    ].
+    ^ copy
+
+    "
+     #($a $b $c $d $e $f $g $a $b $a $d $a $f $a) asBag copyWithout:$a
+     #($a $b $c $d $e $f $g $a $b $a $d $a $f $a) asSet copyWithout:$a
+    "
+!
+
 postCopyFrom:original
     "sent to a freshly copied object to give it a chance to adjust things.
      Notice, that for Sets/Dicts etc. a rehash is not needed, since the copy
@@ -4537,7 +4562,7 @@
     aStream nextPut:$)
 
     "
-     #(1 2 3 'hello' $a $ü) printOn:Transcript
+     #(1 2 3 'hello' $a $ü) printOn:Transcript
      (Array new:100000) printOn:Transcript
      (Array new:100000) printOn:Stdout
      (Array new:100000) printString size
@@ -5896,7 +5921,7 @@
 includesAll:aCollection
     "return true if the receiver includes all elements of
      the argument, aCollection; false if any is missing.
-     Notice: this method has O² runtime behavior and may be
+     Notice: this method has O² runtime behavior and may be
              slow for big receivers/args.
              Think about using a Set, or Dictionary."
 
@@ -5916,7 +5941,7 @@
      Return false if it includes none.
      Uses #= (value compare)
      Notice:
-        this method has O² runtime behavior for some subclasses and may be slow for big receivers/args.
+        this method has O² runtime behavior for some subclasses and may be slow for big receivers/args.
         Think about using a Set or Dictionary.
         Some speedup is also possible, by arranging highly
         probable elements towards the beginning of aCollection, to avoid useless searches.
@@ -5993,7 +6018,7 @@
      Return false if it includes none.
      Use identity compare for comparing.
      Notice:
-        this method has O² runtime behavior for some subclasses and may be slow for big receivers/args.
+        this method has O² runtime behavior for some subclasses and may be slow for big receivers/args.
         Think about using a Set or Dictionary.
         Some speedup is also possible, by arranging highly
         probable elements towards the beginning of aCollection, to avoid useless searches."