'From Squeak3.2 of 11 July 2002 [latest update: #4935] on 5 August 2002 at 3:36:14 pm'! "Change Set: KeysAtValue-nk Date: 2 August 2002 Author: Ned Konz This CS: * Fixes IdentityDictionary>>keyAtValue: to work right * Adds keysAtValue: and keysAtIdentityValue: methods to Dictionary that answer the entire set of keys for a given value. Right now keysAtValue: raises an exception if none are found; perhaps it should just return an empty collection. "! !Dictionary methodsFor: 'accessing' stamp: 'nk 8/2/2002 09:46'! keyAtValue: value "Answer the first key that is the external name for the argument, value. If there is none, raise an exception." ^self keyAtValue: value ifAbsent: [self errorValueNotFound]! ! !Dictionary methodsFor: 'accessing' stamp: 'nk 8/2/2002 09:46'! keyAtValue: value ifAbsent: exceptionBlock "Answer the first key that is the external name for the argument, value. If there is none, answer the result of evaluating exceptionBlock. : Use =, not ==, so strings like 'this' can be found. Note that MethodDictionary continues to use == so it will be fast." self associationsDo: [:association | value = association value ifTrue: [^association key]]. ^exceptionBlock value! ! !Dictionary methodsFor: 'accessing' stamp: 'nk 8/2/2002 09:45'! keysAtIdentityValue: value "Answer all the keys (possibly none) that are the external names for the argument, value." ^self keysAtIdentityValue: value ifNone: [ {} ]! ! !Dictionary methodsFor: 'accessing' stamp: 'nk 8/2/2002 09:45'! keysAtIdentityValue: value ifNone: exceptionBlock "Answer the keys that are the external names for the argument, value. If there are none, answer the result of evaluating exceptionBlock." | retval | retval _ Set new. self associationsDo: [:association | value == association value ifTrue: [ retval add: association key]]. retval isEmpty ifTrue: [ ^exceptionBlock value ]. ^retval.! ! !Dictionary methodsFor: 'accessing' stamp: 'nk 8/2/2002 09:45'! keysAtValue: value "Answer the keys (possibly none) that are the external names for the argument, value." ^self keysAtValue: value ifNone: [ {} ]! ! !Dictionary methodsFor: 'accessing' stamp: 'nk 8/2/2002 09:45'! keysAtValue: value ifNone: exceptionBlock "Answer the keys that are the external names for the argument, value. If there are none, answer the result of evaluating exceptionBlock." | retval | retval _ Set new. self associationsDo: [:association | value = association value ifTrue: [ retval add: association key]]. retval isEmpty ifTrue: [ ^exceptionBlock value ]. ^retval.! ! IdentityDictionary removeSelector: #keyAtValue:ifAbsent:!