--- a/Dictionary.st Wed May 24 14:44:58 1995 +0200
+++ b/Dictionary.st Tue Jun 06 05:56:11 1995 +0200
@@ -21,7 +21,7 @@
COPYRIGHT (c) 1991 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.20 1995-05-16 17:06:43 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.21 1995-06-06 03:53:44 claus Exp $
'!
!Dictionary class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.20 1995-05-16 17:06:43 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.21 1995-06-06 03:53:44 claus Exp $
"
!
@@ -102,6 +102,25 @@
"
Dictionary withKeysAndValues:#('one' 1 'two' 2 'three' 3 'four' 4)
"
+!
+
+withKeys:keyArray andValues:valueArray
+ "return a new instance where keys and values are taken from
+ the argumentArrays."
+
+ |newDict sz "{ Class: SmallInteger }"|
+
+ sz := keyArray size.
+ newDict := self new:sz.
+ keyArray with:valueArray do:[:key :value |
+ newDict at:key put:value
+ ].
+ ^ newDict
+
+ "
+ Dictionary withKeys:#('one' 'two' 'three' 'four')
+ andValues:#(1 2 3 4)
+ "
! !
!Dictionary methodsFor:'inspecting'!
@@ -296,7 +315,9 @@
"return the key whose value is identical (i.e. using #== for compare)
to the argument, nil if none found.
This is a slow access, since there is no fast reverse mapping.
- The value is searched for using identity compare."
+ NOTICE:
+ The value is searched for using identity compare;
+ use #keyAtEqualValue: to compare for equality."
^ self keyAtValue:aValue ifAbsent:[nil]
!
@@ -304,7 +325,10 @@
keyAtValue:aValue ifAbsent:exceptionBlock
"return the key whose value is identical (i.e. using #== for compare)
to the argument, if not found, return the value of exceptionBlock.
- This is a slow access, since there is no fast reverse mapping."
+ This is a slow access, since there is no fast reverse mapping.
+ NOTICE:
+ The value is searched for using identity compare;
+ use #keyAtEqualValue:ifAbsent: to compare for equality."
keyArray keysAndValuesDo:[:index :aKey |
(aKey notNil and:[aKey ~~ DeletedEntry]) ifTrue:[
@@ -312,6 +336,33 @@
].
].
^ exceptionBlock value
+!
+
+keyAtEqualValue:aValue
+ "return the key whose value is equal (i.e. using #= for compare)
+ to the argument, nil if none found.
+ This is a slow access, since there is no fast reverse mapping.
+ NOTICE:
+ The value is searched for using equality compare;
+ use #keyAtValue: to compare for identity."
+
+ ^ self keyAtEqualValue:aValue ifAbsent:[nil]
+!
+
+keyAtEqualValue:aValue ifAbsent:exceptionBlock
+ "return the key whose value is equal (i.e. using #= for compare)
+ to the argument, if not found, return the value of exceptionBlock.
+ This is a slow access, since there is no fast reverse mapping.
+ NOTICE:
+ The value is searched for using equality compare;
+ use #keyAtValue:ifAbsent: to compare for identity."
+
+ keyArray keysAndValuesDo:[:index :aKey |
+ (aKey notNil and:[aKey ~~ DeletedEntry]) ifTrue:[
+ (valueArray at:index) = aValue ifTrue:[^ aKey].
+ ].
+ ].
+ ^ exceptionBlock value
! !
!Dictionary methodsFor:'adding & removing'!