'From Pharo1.2a of ''11 June 2010'' [Latest update: #12220] on 31 October 2010 at 2:53:10 am'! !WeakKeyDictionary methodsFor: 'accessing' stamp: 'IgorStasenko 10/31/2010 02:48'! overridingAt: key put: anObject "Set the value at key to be anObject. If key is not found, create a new entry for key and set is value to anObject. Answer anObject. May override an association with key == nil" | index element | key isNil ifTrue:[^anObject]. index := self scanForKeyOrNil: key. "There should always be room." index = 0 ifTrue: [ self error: 'No space left in dictionary' ]. element := array at: index. element == nil ifTrue: [self atNewIndex: index put: (WeakKeyAssociation key: key value: anObject)] ifFalse: [ element expired ifTrue: [ tally := tally + 1]. element key: key. element value: anObject. self fullCheck. ]. ^ anObject! ! !WeakKeyDictionary methodsFor: 'private' stamp: 'IgorStasenko 10/31/2010 02:48'! scanForKeyOrNil: anObject "Same as scanFor: , but treats association with key == nil as empty slot" | element start finish | finish := array size. start := self startIndexFor: anObject. "Search from (hash mod size) to the end." start to: finish do: [:index | ((element := array at: index) == nil or: [ element key isNil or: [self compare: element key to: anObject]]) ifTrue: [^ index ]]. "Search from 1 to where we started." 1 to: start-1 do: [:index | ((element := array at: index) == nil or: [ element key isNil or: [self compare: element key to: anObject]]) ifTrue: [^ index ]]. ^ 0 "No match AND no empty slot"! !