[Pkg] The Trunk: Collections-ul.589.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Feb 13 01:25:06 UTC 2019


Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.589.mcz

==================== Summary ====================

Name: Collections-ul.589
Author: ul
Time: 17 December 2014, 3:31:06.906 pm
UUID: 3f079add-7154-43c9-a265-bd59cb4cbcb8
Ancestors: Collections-bf.588

- Deprecated Collection class >> #randomForPicking.
- Replaced all accesses to RandomForPicking with ThreadSafeRandom value.
- WeakKeyDictionary >> associationsDo: ignores associations with GC'd keys. This affects all enumerator methods, and makes overriding #keysDo: unnecessary.
- Added a new method SequenceableCollection #>> groupsDo:, which works like #groupsOf:atATimeDo:, but uses the block's argument count as the group size.

Depends on Kernel-ul.891

=============== Diff against Collections-bf.588 ===============

Item was changed:
  ----- Method: Collection class>>randomForPicking (in category 'private') -----
  randomForPicking
+ 
+ 	self deprecated: 'Use ThreadSafeRandom value instead. It''s not thread-safe to use this instance without the unaccessible MutexForPicking semaphore.'.
  	^ RandomForPicking!

Item was changed:
  ----- Method: Collection>>atRandom (in category 'accessing') -----
  atRandom
+ 	"Answer a random element of the receiver.  Uses the process-local random number generator. Causes an error if self has no elements."
- 	"Answer a random element of the receiver.  Uses a shared random 
- 	number generator owned by class Collection.  If you use this a lot, 
- 	define your own instance of Random and use #atRandom:.  Causes 
- 	an error if self has no elements."
  
+ 	^self atRandom: ThreadSafeRandom value
- 	^ self class mutexForPicking critical: [
- 		self atRandom: self class randomForPicking ]
  
  "Examples:
  	#('one' 'or' 'the' 'other') atRandom
  	(1 to: 10) atRandom
  	'Just pick one of these letters at random' atRandom
  	#(3 7 4 9 21) asSet atRandom		(just to show it also works for Sets)
  "!

Item was added:
+ ----- Method: SequenceableCollection>>groupsDo: (in category 'enumerating') -----
+ groupsDo: aBlock 
+ 	"Evaluate aBlock with my elements taken n at a time, where n is the number of arguments of aBlock. Ignore any leftovers at the end."
+ 	
+ 	| index argumentArray numArgs endIndex |
+ 	numArgs := aBlock numArgs.
+ 	numArgs
+ 		caseOf: { 
+ 			[ 0 ] -> [ ^self error: 'At least one block argument expected.' ].
+ 			[ 1 ] -> [ ^self do: aBlock ].
+ 			[ 2 ] -> [ ^self pairsDo: aBlock ] }
+ 		otherwise: [].
+ 	argumentArray := Array new: numArgs.
+ 	index := 1.
+ 	endIndex := self size - numArgs + 1.
+ 	[ index <= endIndex ] whileTrue: [
+ 		argumentArray
+ 			replaceFrom: 1
+ 			to: numArgs
+ 			with: self
+ 			startingAt: index.
+ 		aBlock valueWithArguments: argumentArray.
+ 		index := index + numArgs ].!

Item was changed:
  ----- Method: SequenceableCollection>>shuffle (in category 'shuffling') -----
  shuffle
  
+ 	^self shuffleBy: ThreadSafeRandom value!
- 	^self shuffleBy: Collection randomForPicking!

Item was changed:
  ----- Method: SequenceableCollection>>shuffled (in category 'copying') -----
  shuffled
+ 	^ self shuffledBy: ThreadSafeRandom value
- 	^ self shuffledBy: Collection randomForPicking
  
  "Examples:
  	($A to: $Z) shuffled
  "!

Item was added:
+ ----- Method: WeakKeyDictionary>>associationsDo: (in category 'enumerating') -----
+ associationsDo: aBlock 
+ 	"Evaluate aBlock for each of the receiver's elements (key/value 
+ 	associations)."
+ 
+ 	tally = 0 ifTrue: [ ^self].
+ 	1 to: array size do: [ :index |
+ 		(array at: index) ifNotNil: [ :association |
+ 			association key ifNotNil: [ :key | "Don't let the key go away."
+ 				aBlock value: association ] ] ]!

Item was removed:
- ----- Method: WeakKeyDictionary>>keysDo: (in category 'enumerating') -----
- keysDo: aBlock 
- 	"Evaluate aBlock for each of the receiver's keys."
- 	
- 	self associationsDo: [ :association |
- 		association key ifNotNil: [ :key | "Don't let the key go away"
- 			aBlock value: key ] ].!



More information about the Packages mailing list