[Pkg] The Trunk: Collections-ul.648.mcz
commits at source.squeak.org
commits at source.squeak.org
Mon Aug 24 16:11:05 UTC 2015
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.648.mcz
==================== Summary ====================
Name: Collections-ul.648
Author: ul
Time: 23 August 2015, 11:56:36.78 pm
UUID: 03127fe2-feda-47f9-ba11-984377a172ff
Ancestors: Collections-ul.647
CharacterSet:
- store the size in an instance variable
- moved removal logic to #remove:ifAbsent:, while kept the behavior of #remove:
- migrate existing instances by sending #size in the postscript
=============== Diff against Collections-ul.647 ===============
Item was changed:
Collection subclass: #CharacterSet
+ instanceVariableNames: 'map tally'
- instanceVariableNames: 'map'
classVariableNames: 'CrLf NonSeparators Separators'
poolDictionaries: ''
category: 'Collections-Support'!
!CharacterSet commentStamp: '<historical>' prior: 0!
A set of characters. Lookups for inclusion are very fast.!
Item was changed:
----- Method: CharacterSet>>= (in category 'comparison') -----
= anObject
+
+ self species == anObject species ifFalse: [ ^false ].
+ self size. "to migrate existing instances"
+ anObject size = tally ifFalse: [ ^false ].
+ ^self byteArrayMap = anObject byteArrayMap!
- ^self species == anObject species and: [
- self byteArrayMap = anObject byteArrayMap ]!
Item was changed:
----- Method: CharacterSet>>add: (in category 'collection ops') -----
add: aCharacter
"I automatically become a WideCharacterSet if you add a wide character to myself"
+ | index |
+ (index := aCharacter asInteger + 1) <= 256 ifFalse: [
+ | wide |
+ wide := WideCharacterSet new.
+ wide addAll: self.
+ wide add: aCharacter.
+ self becomeForward: wide.
+ ^aCharacter ].
+ (map at: index) = 1 ifTrue: [ ^aCharacter ].
+ self size. "to migrate existing instances."
+ map at: index put: 1.
+ tally := tally + 1.
- aCharacter asciiValue >= 256
- ifTrue: [| wide |
- wide := WideCharacterSet new.
- wide addAll: self.
- wide add: aCharacter.
- self becomeForward: wide.
- ^aCharacter].
- map at: aCharacter asciiValue + 1 put: 1.
^aCharacter!
Item was changed:
----- Method: CharacterSet>>do: (in category 'collection ops') -----
do: aBlock
"evaluate aBlock with each character in the set"
+ | index |
+ self size. "to migrate existing instances"
+ tally >= 128 ifTrue: [ "dense"
+ index := 0.
+ [ (index := index + 1) <= 256 ] whileTrue: [
+ (map at: index) = 1 ifTrue: [
+ aBlock value: (Character value: index - 1) ] ].
+ ^self ].
+ "sparse"
+ index := 0.
+ [ (index := map indexOf: 1 startingAt: index + 1) = 0 ] whileFalse: [
+ aBlock value: (Character value: index - 1) ].
+ !
- Character allByteCharacters do: [ :c |
- (self includes: c) ifTrue: [ aBlock value: c ] ]
- !
Item was changed:
----- Method: CharacterSet>>initialize (in category 'private') -----
initialize
+
+ map := ByteArray new: 256.
+ tally := 0!
- map := ByteArray new: 256 withAll: 0.!
Item was changed:
----- Method: CharacterSet>>remove: (in category 'collection ops') -----
remove: aCharacter
+
+ ^self remove: aCharacter ifAbsent: aCharacter!
- aCharacter asciiValue >= 256
- ifFalse: ["Guard against wide characters"
- map at: aCharacter asciiValue + 1 put: 0].
- ^aCharacter!
Item was changed:
----- Method: CharacterSet>>remove:ifAbsent: (in category 'collection ops') -----
remove: aCharacter ifAbsent: aBlock
+
+ | index |
+ (index := aCharacter asciiValue + 1) <= 256 ifFalse: [ ^aBlock value ].
+ (map at: index) = 0 ifTrue: [ ^aBlock value ].
+ self size. "to migrate existing instances."
+ map at: index put: 0.
+ tally := tally - 1.
+ ^aCharacter!
- (self includes: aCharacter) ifFalse: [^aBlock value].
- ^self remove: aCharacter!
Item was changed:
----- Method: CharacterSet>>removeAll (in category 'removing') -----
removeAll
+ map atAllPut: 0.
+ tally := 0!
- map atAllPut: 0!
Item was changed:
----- Method: CharacterSet>>size (in category 'collection ops') -----
size
+
+ ^tally ifNil: [
+ | index count |
+ index := count := 0.
+ [ (index := map indexOf: 1 startingAt: index + 1) = 0 ] whileFalse: [
+ count := count + 1 ].
+ tally := count ]!
- ^map sum!
Item was changed:
+ (PackageInfo named: 'Collections') postscript: 'CharacterSet allInstancesDo: #size'!
- (PackageInfo named: 'Collections') postscript: 'WideCharacterSet allInstancesDo: #migrate'!
More information about the Packages
mailing list