#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Wed, 03 Oct 2018 13:16:41 +0200
changeset 23396 a5cda5279311
parent 23395 be07f3742fe8
child 23397 be7145659501
#FEATURE by cg class: Collection added: #includesAllKeys: #includesAnyKeys: #includesKey: comment/format in: #includesAll: #includesAny: #includesAnyIdentical:
Collection.st
--- a/Collection.st	Tue Oct 02 17:31:02 2018 +0200
+++ b/Collection.st	Wed Oct 03 13:16:41 2018 +0200
@@ -297,6 +297,8 @@
     ^ self newWithSize:n
 ! !
 
+
+
 !Collection class methodsFor:'Signal constants'!
 
 emptyCollectionSignal
@@ -358,6 +360,7 @@
     ^ self == Collection
 ! !
 
+
 !Collection methodsFor:'Compatibility-ANSI'!
 
 identityIncludes:anObject
@@ -367,6 +370,7 @@
     ^ self includesIdentical:anObject.
 ! !
 
+
 !Collection methodsFor:'Compatibility-Squeak'!
 
 , aCollection
@@ -527,6 +531,7 @@
     ^ self ifEmpty:ifEmptyValue ifNotEmpty:ifNotEmptyValue
 ! !
 
+
 !Collection methodsFor:'accessing'!
 
 anElement
@@ -6054,8 +6059,9 @@
 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
-             slow for big receivers/args.
+     Notice: depending on the concrete collection,
+             this method may have O² runtime behavior,
+             and may be slow for big receivers/args.
              Think about using a Set, or Dictionary."
 
     ^ aCollection conform:[:element | (self includes:element)]
@@ -6067,23 +6073,43 @@
     "
 
     "Modified: / 13-10-2006 / 12:54:50 / cg"
+    "Modified (comment): / 03-10-2018 / 13:14:10 / Claus Gittinger"
+!
+
+includesAllKeys:aCollectionOfKeys
+    "return true if the receiver includes all keys in aCollectionOfKeys,
+     false if any is missing."
+
+    ^ aCollectionOfKeys conform:[:element | (self includesKey:element)]
+
+    "
+     #(1 2 3 4 5 6 7) includesAll:#(1 2 3)
+     #('hello' 'there' 'world') includesAll:#('hello' 'world')
+     #(1 2 3 4 5 6 7) includesAll:#(7 8 9)
+    "
+
+    "Created: / 03-10-2018 / 13:12:16 / Claus Gittinger"
 !
 
 includesAny:searchedElementsCollection
     "return true if the receiver includes any from the argument, aCollection.
      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.
-        Think about using a Set or Dictionary.
+     Notice: 
+        depending on the concrete collection,
+        this method may have O² runtime behavior,
+        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.
+        probable elements towards the beginning of aCollection, 
+        to avoid useless searches.
 
         Also: I am not sure, if (and if so, at which breakeven),
         it is better to reverse the loops, and walk over the receiver's
         elements once, walking over the searched elements in the inner loop.
-        If the receiver is large, caching effects will definitely favour this, as
-        the smaller collection might fit into the cache.
+        If the receiver is large, caching effects will definitely favour this,
+        as the smaller collection might fit into the cache.
     "
 
     |mySize searchedSize|
@@ -6144,6 +6170,7 @@
     "
 
     "Modified (comment): / 12-02-2017 / 11:47:42 / cg"
+    "Modified (comment): / 03-10-2018 / 13:15:39 / Claus Gittinger"
 !
 
 includesAnyIdentical:searchedElementsCollection
@@ -6151,7 +6178,9 @@
      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.
+        depending on the concrete collection,
+        this method may have 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."
@@ -6169,6 +6198,16 @@
     "
 
     "Modified (comment): / 30-04-2016 / 17:13:38 / cg"
+    "Modified (comment): / 03-10-2018 / 13:16:09 / Claus Gittinger"
+!
+
+includesAnyKeys:aCollectionOfKeys
+    "return true if the receiver includes any key from aCollectionOfKeys,
+     false if none is present."
+
+    ^ aCollectionOfKeys contains:[:element | (self includesKey:element)]
+
+    "Created: / 03-10-2018 / 13:12:53 / Claus Gittinger"
 !
 
 includesIdentical:searchedElement
@@ -6185,6 +6224,12 @@
     "Modified (comment): / 30-04-2016 / 17:10:34 / cg"
 !
 
+includesKey:aKey
+    ^ self subclassResponsibility
+
+    "Created: / 03-10-2018 / 13:13:31 / Claus Gittinger"
+!
+
 isCollection
     "return true, if the receiver is some kind of collection;
      true is returned here - the method is redefined from Object."
@@ -6367,6 +6412,7 @@
     ^ aVisitor visitCollection:self with:aParameter
 ! !
 
+
 !Collection class methodsFor:'documentation'!
 
 version