--- a/Collection.st Wed Feb 15 22:29:42 2017 +0100
+++ b/Collection.st Thu Feb 16 13:45:01 2017 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
@@ -343,6 +345,7 @@
^ self
! !
+
!Collection methodsFor:'Compatibility-ANSI'!
identityIncludes:anObject
@@ -1426,6 +1429,23 @@
ret at:i put:(self removeLast).
].
^ ret
+!
+
+testAndAdd:anElement
+ "add the argument, anObject to the receiver.
+ Answer true, if the element did already exist in the collection,
+ false otherwise.
+
+ WARNING: do not add elements while iterating over the receiver.
+ Iterate over a copy to do this."
+
+ (self includes:anElement) ifTrue:[
+ ^ true.
+ ].
+ self add:anElement.
+ ^ false.
+
+ "Created: / 16-02-2017 / 13:41:58 / stefan"
! !
!Collection methodsFor:'bulk operations'!
@@ -4351,7 +4371,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
@@ -5708,7 +5728,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."
@@ -5728,7 +5748,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.
@@ -5805,7 +5825,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."