[Pkg] The Trunk: Collections-nice.858.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Nov 17 11:46:12 UTC 2019


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

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

Name: Collections-nice.858
Author: nice
Time: 17 November 2019, 12:46:04.058035 pm
UUID: cd5d4533-11f2-2340-8957-a577330de15d
Ancestors: Collections-pre.857

Fix union: and intersection: of CharacterSet

We must avoid using naive loops for huge sets that canBeEnumerated not.

An enumerationCost scale is introduced for that purpose.

The idea is that intersection: must be performed by the cheapest set, while union: must be performed by the most expensive. The most expensive eventually knows how to handle loops lazily.

=============== Diff against Collections-pre.857 ===============

Item was added:
+ ----- Method: ByteCharacterSet>>enumerationCost (in category 'private') -----
+ enumerationCost
+ 	"Low cost. I do not hold more than 256 characters."
+ 	
+ 	^10!

Item was removed:
- ----- Method: ByteCharacterSet>>union: (in category 'enumerating') -----
- union: aCollection
- 	(self isCharacters: aCollection) ifFalse: [^super union: aCollection].
- 	(self species = aCollection species and: [self class ~= aCollection class]) ifTrue: [^aCollection union: self].
- 	^self copy addAll: aCollection; yourself!

Item was changed:
  Collection subclass: #CharacterSet
  	instanceVariableNames: 'byteArrayMap'
  	classVariableNames: 'Ascii CrLf NonAscii NonSeparators Separators'
  	poolDictionaries: ''
  	category: 'Collections-Support'!
  
+ !CharacterSet commentStamp: 'nice 11/17/2019 12:26' prior: 0!
+ A set of characters.  Lookups for inclusion are very fast.
+ CharacterSet is the abstract class that is visible to the outside world.
+ Subclasses should be considered as implementation details.!
- !CharacterSet commentStamp: '<historical>' prior: 0!
- A set of characters.  Lookups for inclusion are very fast.!

Item was added:
+ ----- Method: CharacterSet>>as: (in category 'converting') -----
+ as: otherClass
+ 	otherClass = CharacterSet ifTrue: [^self].
+ 	^super as: otherClass!

Item was added:
+ ----- Method: CharacterSet>>enumerationCost (in category 'private') -----
+ enumerationCost
+ 	"Answer an integer giving a scale of cost, especially for do: loops."
+ 	
+ 	^self subclassResponsibility!

Item was added:
+ ----- Method: CharacterSet>>intersection: (in category 'enumerating') -----
+ intersection: aCollection
+ 	(self species = aCollection species and: [aCollection enumerationCost < self enumerationCost]) ifTrue: [^aCollection intersection: self].
+ 	^ self select: [:each | aCollection includes: each]!

Item was added:
+ ----- Method: CharacterSet>>union: (in category 'enumerating') -----
+ union: aCollection
+ 	(self isCharacters: aCollection) ifFalse: [^super union: aCollection].
+ 	(self species = aCollection species and: [aCollection enumerationCost > self enumerationCost]) ifTrue: [^aCollection union: self].
+ 	^self copy addAll: aCollection; yourself!

Item was added:
+ ----- Method: CharacterSetComplement>>enumerationCost (in category 'private') -----
+ enumerationCost
+ 	"The maximum cost. I can't even do: loops, it's too expensive."
+ 	
+ 	^100!

Item was removed:
- ----- Method: LazyCharacterSet>>complement (in category 'converting') -----
- complement
- 	^self class including: [:char | (block value: char) not]!

Item was added:
+ ----- Method: LazyCharacterSet>>enumerationCost (in category 'private') -----
+ enumerationCost
+ 	"The maximum cost. I can't even do: loops, it's too expensive."
+ 	
+ 	^100!

Item was changed:
  ----- Method: LazyCharacterSet>>intersection: (in category 'enumerating') -----
  intersection: aCollection
+ 	^((self isCharacters: aCollection)
+ 		ifTrue: [aCollection select: block]
+ 		ifFalse:
+ 			["protect feeding block with non character"
+ 			aCollection select: [:e |e isCharacter and: [block value: e]]]) as: CharacterSet
+ 		!
- 	(self species = aCollection species or: [aCollection isString or: [aCollection allSatisfy: [:e | e isCharacter]]]) ifFalse: [^super intersection: aCollection].
- 	^self class including: [:c | (aCollection includes: c) and: [block value: c]]!

Item was added:
+ ----- Method: WideCharacterSet>>enumerationCost (in category 'private') -----
+ enumerationCost
+ 	"Medium cost. I can hold many characters eventually."
+ 	
+ 	^50!

Item was removed:
- ----- Method: WideCharacterSet>>union: (in category 'enumerating') -----
- union: aCollection
- 	(self isCharacters: aCollection) ifFalse: [^super union: aCollection].
- 	(self species = aCollection species and: [self class ~= aCollection class]) ifTrue: [^aCollection union: self].
- 	^self copy addAll: aCollection; yourself!



More information about the Packages mailing list