#keyAtValue: in PluggableLookupTable

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

#keyAtValue: in PluggableLookupTable

Peter Goodall-4
Hi,

I don't seem to be able to do a backward equality lookup in
PluggableLookupTable or Dictionary.

This may be the right behavior - because it isn't the key that's being
compared. But would
be simpler to use if the comparison policy was same as SearchPolicy -  or at
least pluggable.
In a comment for Dictionary>>#keyAtValue:  I see:
   #todo "ANSI standard states that #= be used rather than #==, but long
established standard is the latter".


----------------Test Script-------------------------------------------
table := PluggableLookupTable searchPolicy: SearchPolicy equality.

testString := 'Fred'.
table at: 'found it! ' put: testString.

(Array with: testString  with: testString copy)
 collect:[:each |
  table keyAtValue: each  ifAbsent:['using identity to search']].


-->> #('found it! ' 'using identity to search')

----------------End--------------------------------------------------

--

Regards,

--Peter Goodall


Reply | Threaded
Open this post in threaded view
|

Re: #keyAtValue: in PluggableLookupTable

Blair McGlashan
"Peter Goodall" <[hidden email]> wrote in message
news:3fe15678$0$18690$[hidden email]...
> Hi,
>
> I don't seem to be able to do a backward equality lookup in
> PluggableLookupTable or Dictionary.
>
> This may be the right behavior - because it isn't the key that's being
> compared. But would
> be simpler to use if the comparison policy was same as SearchPolicy -  or
at
> least pluggable.
> In a comment for Dictionary>>#keyAtValue:  I see:
>    #todo "ANSI standard states that #= be used rather than #==, but long
> established standard is the latter".

This has come up a number of times in the past, so you can find more
explanatory detail in the newsgroup archive if you wish, however to
summarise:
1) The standard Smalltalk-80 definition of
Dictionary>>keyAtValue:[ifAbsent:] uses #==
2) You can use #keyAtEqualValue:[ifAbsent:] if you want an equality search.

Regards

Blair