Merge jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 16 Feb 2016 07:24:34 +0000
branchjv
changeset 19229 c20beb908660
parent 19228 f2f3abaadcb4 (current diff)
parent 19224 9799d5bedd22 (diff)
child 19236 e6403ba50de1
Merge
Collection.st
Dictionary.st
SequenceableCollection.st
Stream.st
--- a/Collection.st	Mon Feb 15 09:26:34 2016 +0000
+++ b/Collection.st	Tue Feb 16 07:24:34 2016 +0000
@@ -1609,12 +1609,12 @@
     "return a Dictionary with the receiver collection's elements,
      using the original keys of the receiver as dictionary key.
      Notice: this is redefined in Dictionary, where it returns the receiver. 
-     Use asNewDictionary, if you intent to modify the returned collection.
+     Use asNewDictionary, if you intend to modify the returned collection.
      See associationsAsDictionary if you already have a collection of associations"
 
     |d|
 
-    d := Dictionary new.
+    d := Dictionary new:self size.
     self keysAndValuesDo:[:k :v | d at:k put:v].
     ^ d
 
--- a/Dictionary.st	Mon Feb 15 09:26:34 2016 +0000
+++ b/Dictionary.st	Tue Feb 16 07:24:34 2016 +0000
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1991 by Claus Gittinger
 	      All Rights Reserved
@@ -205,6 +203,23 @@
     "
 !
 
+withKeys:aCollection valueBlock:aOneArgBlock
+    "return a Dictionary with keys from aCollection's elements,
+     using aOneArgBlock to generate the values from aCollection's elements."
+
+    |d|
+
+    d := self new:aCollection size.
+    aCollection do:[:each|
+        d at:each put:(aOneArgBlock value:each).
+    ].
+    ^ d
+
+    "
+     Dictionary withKeys:#(10 20 30 40 50 60 70 80 90) valueBlock:[:e| e asString] 
+    "
+!
+
 withKeysAndValues:anArray
     "return a new instance where keys and values are taken from alternating
      elements of anArray"
@@ -221,6 +236,23 @@
     "
      Dictionary withKeysAndValues:#('one' 1 'two' 2 'three' 3 'four' 4)
     "
+!
+
+withValues:aCollection keyBlock:aOneArgBlock
+    "return a Dictionary with values from aCollection's elements,
+     using aOneArgBlock to generate the keys from aCollection's elements."
+
+    |d|
+
+    d := self new:aCollection size.
+    aCollection do:[:each|
+        d at:(aOneArgBlock value:each) put:each.
+    ].
+    ^ d
+
+    "
+     Dictionary withValues:#(10 20 30 40 50 60 70 80 90) keyBlock:[:e| e asString] 
+    "
 ! !
 
 !Dictionary class methodsFor:'Compatibility-Squeak'!
@@ -260,6 +292,7 @@
     ^ true
 ! !
 
+
 !Dictionary methodsFor:'accessing'!
 
 associationAt:aKey
@@ -2273,6 +2306,7 @@
     ^ aVisitor visitDictionary:self with:aParameter
 ! !
 
+
 !Dictionary class methodsFor:'documentation'!
 
 version
--- a/SequenceableCollection.st	Mon Feb 15 09:26:34 2016 +0000
+++ b/SequenceableCollection.st	Tue Feb 16 07:24:34 2016 +0000
@@ -398,6 +398,7 @@
     ^ self == SequenceableCollection
 ! !
 
+
 !SequenceableCollection methodsFor:'Compatibility-Squeak'!
 
 allButFirst
@@ -710,6 +711,7 @@
     ^ self replaceFrom:start to:stop with:anArray startingAt:repStart
 ! !
 
+
 !SequenceableCollection methodsFor:'accessing'!
 
 after:anObject
@@ -1801,6 +1803,35 @@
     "Modified: / 13.11.2001 / 13:49:18 / cg"
 !
 
+commonElementsWith:otherCollection
+    "Answer whether the receiver's size is the same as otherCollection's size,
+     and each of the receiver's elements equal the corresponding element of otherCollection.
+     This should probably replace the current definition of #= ."
+
+    |size otherSize commonSize "{ Class: SmallInteger }" commonElements|
+
+    (otherCollection == self) ifTrue:[^ self].
+    otherCollection isSequenceable ifFalse: [^ self error:'not sequenceable'].
+    size := self size.
+    otherSize := otherCollection size.
+    commonSize := size min:otherSize.
+
+    commonElements := self species new:commonSize.
+
+    1 to:commonSize do:[:index |
+        |el|
+        el := self at:index.
+        el = (otherCollection at: index) ifTrue:[
+            commonElements at:index put:el.
+        ]
+    ].
+    ^ commonElements
+
+    "
+        #(1 2 3) commonElementsWith:#(4 2 3 4)
+    "
+!
+
 commonPrefixWith:aCollection
     "return the common prefix of myself and the argument, aCollection.
      If there is none, an empty collection is returned."
@@ -7734,6 +7765,7 @@
     "Created: 14.2.1997 / 16:13:03 / cg"
 ! !
 
+
 !SequenceableCollection methodsFor:'searching'!
 
 detect:aBlock startingAt:startIndex
--- a/Stream.st	Mon Feb 15 09:26:34 2016 +0000
+++ b/Stream.st	Tue Feb 16 07:24:34 2016 +0000
@@ -275,6 +275,8 @@
     "Modified: 10.1.1996 / 19:39:19 / cg"
 ! !
 
+
+
 !Stream methodsFor:'accessing'!
 
 contents
@@ -3595,7 +3597,7 @@
 readWait
     "suspend the current process, until the receiver
      becomes ready for reading. If data is already available,
-     return immediate.
+     return immediately.
      The other threads are not affected by the wait."
 
     ^ self readWaitWithTimeoutMs:nil