Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.897.mcz ==================== Summary ==================== Name: Collections-ul.897 Author: ul Time: 31 May 2020, 12:23:26.517191 am UUID: 16d2c780-9e9c-4012-8149-fee4227d45bc Ancestors: Collections-ul.896 WeakIdentityDictionary: - made it work as other weak hashed collections: - no modification during element lookup - simpler code - same runtime complexity Other: - removed ByteArray >> #atAllPut: because it was same the as in its superclass =============== Diff against Collections-nice.895 =============== Item was removed: - ----- Method: ByteArray>>atAllPut: (in category 'accessing') ----- - atAllPut: value - "Fill the receiver with the given value" - - <primitive: 145> - super atAllPut: value! Item was changed: ----- Method: String>>< (in category 'comparing') ----- < aString "Answer whether the receiver sorts before aString. The collation order is simple ascii (with case differences)." + ^(self compareWith: aString) < 0! - ^ (self compare: self with: aString collated: AsciiOrder) = 1! Item was changed: ----- Method: String>><= (in category 'comparing') ----- <= aString "Answer whether the receiver sorts before or equal to aString. The collation order is simple ascii (with case differences)." + ^(self compareWith: aString) <= 0! - ^ (self compare: self with: aString collated: AsciiOrder) <= 2! Item was changed: ----- Method: String>>= (in category 'comparing') ----- = aString "Answer whether the receiver sorts equally as aString. The collation order is simple ascii (with case differences)." self == aString ifTrue: [ ^true ]. aString isString ifFalse: [ ^false ]. self size = aString size ifFalse: [ ^false ]. + ^ (self compareWith: aString) = 0! - ^ (self compare: self with: aString collated: AsciiOrder) = 2! Item was changed: ----- Method: String>>> (in category 'comparing') ----- > aString "Answer whether the receiver sorts after aString. The collation order is simple ascii (with case differences)." + ^(self compareWith: aString) > 0! - ^ (self compare: self with: aString collated: AsciiOrder) = 3! Item was changed: ----- Method: String>>>= (in category 'comparing') ----- >= aString "Answer whether the receiver sorts after or equal to aString. The collation order is simple ascii (with case differences)." + ^(self compareWith: aString) >= 0! - ^ (self compare: self with: aString collated: AsciiOrder) >= 2! Item was changed: ----- Method: String>>compare:caseSensitive: (in category 'comparing') ----- compare: aString caseSensitive: aBool "Answer a comparison code telling how the receiver sorts relative to aString: 1 - before 2 - equal 3 - after. " | map | map := aBool ifTrue:[CaseSensitiveOrder] ifFalse:[CaseInsensitiveOrder]. + ^(self compareWith: aString collated: map) + 2! - ^self compare: self with: aString collated: map! Item was added: + ----- Method: String>>compareWith: (in category 'comparing') ----- + compareWith: aString + + "<primitive: 158>" + ^(self compare: self with: aString collated: AsciiOrder) - 2! Item was added: + ----- Method: String>>compareWith:collated: (in category 'comparing') ----- + compareWith: aString collated: collation + + "<primitive: 158>" + ^(self compare: self with: aString collated: collation) - 2! Item was removed: - ----- Method: WeakIdentityDictionary>>cleanupIndex: (in category 'private') ----- - cleanupIndex: anInteger - array at: anInteger put: vacuum. - tally := tally - 1. - self fixCollisionsFrom: anInteger.! Item was changed: ----- Method: WeakIdentityDictionary>>fixCollisionsFrom: (in category 'private') ----- fixCollisionsFrom: start "The element at start has been removed and replaced by vacuum. This method moves forward from there, relocating any entries that had been placed below due to collisions with this one." | element index | index := start. [ (element := array at: (index := index \\ array size + 1)) == vacuum ] whileFalse: [ element ifNil: [ "The binding at this slot was reclaimed - finish the cleanup" array at: index put: vacuum. tally := tally - 1 ] ifNotNil: [| newIndex | + (newIndex := self scanFor: element key) = index ifFalse: [ - (newIndex := self scanWithoutGarbagingFor: element key) = index ifFalse: [ array at: newIndex put: element; at: index put: vacuum ] ] ]! Item was changed: ----- Method: WeakIdentityDictionary>>removeKey:ifAbsent: (in category 'removing') ----- removeKey: key ifAbsent: aBlock "Remove key (and its associated value) from the receiver. If key is not in the receiver, answer the result of evaluating aBlock. Otherwise, answer the value externally named by key." | index association | index := self scanFor: key. (association := (array at: index)) == vacuum ifTrue: [ ^aBlock value ]. + array at: index put: vacuum. + tally := tally - 1. + self fixCollisionsFrom: index. - self cleanupIndex: index. ^association value! Item was changed: ----- Method: WeakIdentityDictionary>>scanFor: (in category 'private') ----- scanFor: anObject "Scan the array for the first slot containing either - a vacuum object indicating an empty slot - or a binding whose key matches anObject. + Answer the index of that slot or raise an error if no slot is found which should never happen." - Answer the index of that slot or raise an error if no slot is found. - When garbage collected slots are encountered, perform a clean-up." + | index start size | + index := start := anObject scaledIdentityHash \\ (size := array size) + 1. + [ + (array at: index) ifNotNil: [ :element | + (element == vacuum or: [ element key == anObject ]) + ifTrue: [ ^index ] ]. + (index := index \\ size + 1) = start ] whileFalse. - | index start rescan | - [ - rescan := false. - index := start := anObject scaledIdentityHash \\ array size + 1. - [ - (array at: index) - ifNil: - ["Object at this slot has been garbage collected. - A rescan is necessary because fixing collisions - might have moved the target before current index." - self cleanupIndex: index. - rescan := true] - ifNotNil: - [:element | (element == vacuum or: [ element key == anObject ]) - ifTrue: [ ^index ]. - (index := index \\ array size + 1) = start ] ] whileFalse. - rescan ] whileTrue. self errorNoFreeSpace! Item was changed: ----- Method: WeakIdentityDictionary>>scanForEmptySlotFor: (in category 'private') ----- scanForEmptySlotFor: anObject + "Scan the array for the first empty slot marked by vacuum object or nil. + Answer the index of that slot or raise an error if no slot is found, which should never happen." - "Scan the array for the first empty slot marked by vacuum object. - Answer the index of that slot or raise an error if no slot is found. - Ignore the slots that have been garbage collected (those containing nil)." | index start | index := start := anObject scaledIdentityHash \\ array size + 1. [ + | element | + ((element := array at: index) == vacuum or: [ element == nil ]) ifTrue: [ ^index ]. - (array at: index) - ifNotNil: - [:element | element == vacuum ifTrue: [ ^index ] ]. (index := index \\ array size + 1) = start ] whileFalse. self errorNoFreeSpace! Item was removed: - ----- Method: WeakIdentityDictionary>>scanWithoutGarbagingFor: (in category 'private') ----- - scanWithoutGarbagingFor: anObject - "Scan the array for the first slot containing either - - a vacuum object indicating an empty slot - - or a binding whose key matches anObject. - Answer the index of that slot or raise an error if no slot is found. - Ignore the slots that have been garbage collected (those containing nil)" - - | index start | - index := start := anObject scaledIdentityHash \\ array size + 1. - [ - (array at: index) - ifNotNil: - [:element | (element == vacuum or: [ element key == anObject ]) - ifTrue: [ ^index ] ]. - (index := index \\ array size + 1) = start ] whileFalse. - self errorNoFreeSpace! |
Free forum by Nabble | Edit this page |