Eliot Miranda uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-eem.656.mcz ==================== Summary ==================== Name: Collections-eem.656 Author: eem Time: 25 September 2015, 11:36:48.911 am UUID: 50ec1b3e-c058-4167-889e-836e994b500b Ancestors: Collections-ul.655 Add Dictionary>>at:ifPresent:ifAbsentPut:. Move Dictionary>>fasterKeys & keyForIdentity: to 50Deprecated =============== Diff against Collections-ul.655 =============== Item was added: + ----- Method: Dictionary>>at:ifPresent:ifAbsentPut: (in category 'accessing') ----- + at: key ifPresent: oneArgBlock ifAbsentPut: absentBlock + "Lookup the given key in the receiver. If it is present, answer the value of + evaluating oneArgBlock with the value associated with the key. Otherwise + add the value of absentBlock under the key, and answer that value." + + | index value | + index := self scanFor: key. + (array at: index) ifNotNil: + [:element| + ^oneArgBlock value: element value]. + value := absentBlock value. + self atNewIndex: index put: (Association key: key value: value). + ^value! Item was removed: - ----- Method: Dictionary>>fasterKeys (in category 'accessing') ----- - fasterKeys - "Contrary to old version of #keys, this method returned an Array rather than a Set. - This was faster because no lookup: was performed. - But now, #keys also return an Array, so don't use #fasterKeys anymore." - - self deprecated: 'use #keys'. - - ^self keys. - ! Item was removed: - ----- Method: Dictionary>>keyForIdentity: (in category 'accessing') ----- - keyForIdentity: anObject - "If anObject is one of the values of the receive, return its key, else return nil. Contrast #keyAtValue: in which there is only an equality check, here there is an identity check" - - self deprecated: 'Use #keyAtIdentityValue:ifAbsent:'. - ^self keyAtIdentityValue: anObject ifAbsent: nil! |
Implementing #at:ifPresent:ifAbsentPut: without reusing #at:ifAbsent: and
#at:ifAbsentPut: implies that it must be defined in some of its subclasses too to make it work. This is the reason why #at:ifAbsentPut: and #at:ifPresent:ifAbsent: reuse the low-level methods, sacrificing performance. Levente On Fri, 25 Sep 2015, [hidden email] wrote: > Eliot Miranda uploaded a new version of Collections to project The Trunk: > http://source.squeak.org/trunk/Collections-eem.656.mcz > > ==================== Summary ==================== > > Name: Collections-eem.656 > Author: eem > Time: 25 September 2015, 11:36:48.911 am > UUID: 50ec1b3e-c058-4167-889e-836e994b500b > Ancestors: Collections-ul.655 > > Add Dictionary>>at:ifPresent:ifAbsentPut:. > Move Dictionary>>fasterKeys & keyForIdentity: to 50Deprecated > > =============== Diff against Collections-ul.655 =============== > > Item was added: > + ----- Method: Dictionary>>at:ifPresent:ifAbsentPut: (in category 'accessing') ----- > + at: key ifPresent: oneArgBlock ifAbsentPut: absentBlock > + "Lookup the given key in the receiver. If it is present, answer the value of > + evaluating oneArgBlock with the value associated with the key. Otherwise > + add the value of absentBlock under the key, and answer that value." > + > + | index value | > + index := self scanFor: key. > + (array at: index) ifNotNil: > + [:element| > + ^oneArgBlock value: element value]. > + value := absentBlock value. > + self atNewIndex: index put: (Association key: key value: value). > + ^value! > > Item was removed: > - ----- Method: Dictionary>>fasterKeys (in category 'accessing') ----- > - fasterKeys > - "Contrary to old version of #keys, this method returned an Array rather than a Set. > - This was faster because no lookup: was performed. > - But now, #keys also return an Array, so don't use #fasterKeys anymore." > - > - self deprecated: 'use #keys'. > - > - ^self keys. > - ! > > Item was removed: > - ----- Method: Dictionary>>keyForIdentity: (in category 'accessing') ----- > - keyForIdentity: anObject > - "If anObject is one of the values of the receive, return its key, else return nil. Contrast #keyAtValue: in which there is only an equality check, here there is an identity check" > - > - self deprecated: 'Use #keyAtIdentityValue:ifAbsent:'. > - ^self keyAtIdentityValue: anObject ifAbsent: nil! > > > |
Hi Levente,
> On Sep 26, 2015, at 11:03 AM, Levente Uzonyi <[hidden email]> wrote: > > Implementing #at:ifPresent:ifAbsentPut: without reusing #at:ifAbsent: and #at:ifAbsentPut: implies that it must be defined in some of its subclasses too to make it work. > This is the reason why #at:ifAbsentPut: and #at:ifPresent:ifAbsent: reuse the low-level methods, sacrificing performance. I understand. But a) using a single scanFor: saves half the search work in the ifAbsentPut: case and b) no extra effort is required if the subclass overrides scanFor: which is the real low level method. So I'm happy with my decision. > Levente _,,,^..^,,,_ (phone) > >> On Fri, 25 Sep 2015, [hidden email] wrote: >> >> Eliot Miranda uploaded a new version of Collections to project The Trunk: >> http://source.squeak.org/trunk/Collections-eem.656.mcz >> >> ==================== Summary ==================== >> >> Name: Collections-eem.656 >> Author: eem >> Time: 25 September 2015, 11:36:48.911 am >> UUID: 50ec1b3e-c058-4167-889e-836e994b500b >> Ancestors: Collections-ul.655 >> >> Add Dictionary>>at:ifPresent:ifAbsentPut:. >> Move Dictionary>>fasterKeys & keyForIdentity: to 50Deprecated >> >> =============== Diff against Collections-ul.655 =============== >> >> Item was added: >> + ----- Method: Dictionary>>at:ifPresent:ifAbsentPut: (in category 'accessing') ----- >> + at: key ifPresent: oneArgBlock ifAbsentPut: absentBlock >> + "Lookup the given key in the receiver. If it is present, answer the value of >> + evaluating oneArgBlock with the value associated with the key. Otherwise >> + add the value of absentBlock under the key, and answer that value." >> + >> + | index value | >> + index := self scanFor: key. >> + (array at: index) ifNotNil: >> + [:element| >> + ^oneArgBlock value: element value]. >> + value := absentBlock value. >> + self atNewIndex: index put: (Association key: key value: value). >> + ^value! >> >> Item was removed: >> - ----- Method: Dictionary>>fasterKeys (in category 'accessing') ----- >> - fasterKeys >> - "Contrary to old version of #keys, this method returned an Array rather than a Set. >> - This was faster because no lookup: was performed. >> - But now, #keys also return an Array, so don't use #fasterKeys anymore." >> - >> - self deprecated: 'use #keys'. >> - >> - ^self keys. >> - ! >> >> Item was removed: >> - ----- Method: Dictionary>>keyForIdentity: (in category 'accessing') ----- >> - keyForIdentity: anObject >> - "If anObject is one of the values of the receive, return its key, else return nil. Contrast #keyAtValue: in which there is only an equality check, here there is an identity check" >> - >> - self deprecated: 'Use #keyAtIdentityValue:ifAbsent:'. >> - ^self keyAtIdentityValue: anObject ifAbsent: nil! > |
> On Sep 26, 2015, at 11:30 AM, Eliot Miranda <[hidden email]> wrote: > > Hi Levente, > >> On Sep 26, 2015, at 11:03 AM, Levente Uzonyi <[hidden email]> wrote: >> >> Implementing #at:ifPresent:ifAbsentPut: without reusing #at:ifAbsent: and #at:ifAbsentPut: implies that it must be defined in some of its subclasses too to make it work. >> This is the reason why #at:ifAbsentPut: and #at:ifPresent:ifAbsent: reuse the low-level methods, sacrificing performance. > > I understand. But a) using a single scanFor: saves half the search work in the ifAbsentPut: case and b) no extra effort is required if the subclass overrides scanFor: which is the real low level method. So I'm happy with my decision. And I'll take a look at subclasses soon. > >> Levente > > _,,,^..^,,,_ (phone) > >> >>> On Fri, 25 Sep 2015, [hidden email] wrote: >>> >>> Eliot Miranda uploaded a new version of Collections to project The Trunk: >>> http://source.squeak.org/trunk/Collections-eem.656.mcz >>> >>> ==================== Summary ==================== >>> >>> Name: Collections-eem.656 >>> Author: eem >>> Time: 25 September 2015, 11:36:48.911 am >>> UUID: 50ec1b3e-c058-4167-889e-836e994b500b >>> Ancestors: Collections-ul.655 >>> >>> Add Dictionary>>at:ifPresent:ifAbsentPut:. >>> Move Dictionary>>fasterKeys & keyForIdentity: to 50Deprecated >>> >>> =============== Diff against Collections-ul.655 =============== >>> >>> Item was added: >>> + ----- Method: Dictionary>>at:ifPresent:ifAbsentPut: (in category 'accessing') ----- >>> + at: key ifPresent: oneArgBlock ifAbsentPut: absentBlock >>> + "Lookup the given key in the receiver. If it is present, answer the value of >>> + evaluating oneArgBlock with the value associated with the key. Otherwise >>> + add the value of absentBlock under the key, and answer that value." >>> + >>> + | index value | >>> + index := self scanFor: key. >>> + (array at: index) ifNotNil: >>> + [:element| >>> + ^oneArgBlock value: element value]. >>> + value := absentBlock value. >>> + self atNewIndex: index put: (Association key: key value: value). >>> + ^value! >>> >>> Item was removed: >>> - ----- Method: Dictionary>>fasterKeys (in category 'accessing') ----- >>> - fasterKeys >>> - "Contrary to old version of #keys, this method returned an Array rather than a Set. >>> - This was faster because no lookup: was performed. >>> - But now, #keys also return an Array, so don't use #fasterKeys anymore." >>> - >>> - self deprecated: 'use #keys'. >>> - >>> - ^self keys. >>> - ! >>> >>> Item was removed: >>> - ----- Method: Dictionary>>keyForIdentity: (in category 'accessing') ----- >>> - keyForIdentity: anObject >>> - "If anObject is one of the values of the receive, return its key, else return nil. Contrast #keyAtValue: in which there is only an equality check, here there is an identity check" >>> - >>> - self deprecated: 'Use #keyAtIdentityValue:ifAbsent:'. >>> - ^self keyAtIdentityValue: anObject ifAbsent: nil! >> |
On Sat, 26 Sep 2015, Eliot Miranda wrote:
> >> On Sep 26, 2015, at 11:30 AM, Eliot Miranda <[hidden email]> wrote: >> >> Hi Levente, >> >>> On Sep 26, 2015, at 11:03 AM, Levente Uzonyi <[hidden email]> wrote: >>> >>> Implementing #at:ifPresent:ifAbsentPut: without reusing #at:ifAbsent: and #at:ifAbsentPut: implies that it must be defined in some of its subclasses too to make it work. >>> This is the reason why #at:ifAbsentPut: and #at:ifPresent:ifAbsent: reuse the low-level methods, sacrificing performance. >> >> I understand. But a) using a single scanFor: saves half the search work in the ifAbsentPut: case and b) no extra effort is required if the subclass overrides scanFor: which is the real low level method. So I'm happy with my decision. I understand. :) IIRC it was Bert who was against changing #at:ifAbsentPut: a few years ago, because EToys has some subclasses of Dictionary, which would have stopped working if the implementation had changed. I don't think it's reasonable to subclass Dictionary, I mean the subclasses of Dictionary I've seen in external packages turned out to be unnecessary, so maybe we should reconsider this for the other two selectors as well. Mainly because they are used more widely than your new method. Levente > > > And I'll take a look at subclasses soon. > >> >>> Levente >> >> _,,,^..^,,,_ (phone) >> >>> >>>> On Fri, 25 Sep 2015, [hidden email] wrote: >>>> >>>> Eliot Miranda uploaded a new version of Collections to project The Trunk: >>>> http://source.squeak.org/trunk/Collections-eem.656.mcz >>>> >>>> ==================== Summary ==================== >>>> >>>> Name: Collections-eem.656 >>>> Author: eem >>>> Time: 25 September 2015, 11:36:48.911 am >>>> UUID: 50ec1b3e-c058-4167-889e-836e994b500b >>>> Ancestors: Collections-ul.655 >>>> >>>> Add Dictionary>>at:ifPresent:ifAbsentPut:. >>>> Move Dictionary>>fasterKeys & keyForIdentity: to 50Deprecated >>>> >>>> =============== Diff against Collections-ul.655 =============== >>>> >>>> Item was added: >>>> + ----- Method: Dictionary>>at:ifPresent:ifAbsentPut: (in category 'accessing') ----- >>>> + at: key ifPresent: oneArgBlock ifAbsentPut: absentBlock >>>> + "Lookup the given key in the receiver. If it is present, answer the value of >>>> + evaluating oneArgBlock with the value associated with the key. Otherwise >>>> + add the value of absentBlock under the key, and answer that value." >>>> + >>>> + | index value | >>>> + index := self scanFor: key. >>>> + (array at: index) ifNotNil: >>>> + [:element| >>>> + ^oneArgBlock value: element value]. >>>> + value := absentBlock value. >>>> + self atNewIndex: index put: (Association key: key value: value). >>>> + ^value! >>>> >>>> Item was removed: >>>> - ----- Method: Dictionary>>fasterKeys (in category 'accessing') ----- >>>> - fasterKeys >>>> - "Contrary to old version of #keys, this method returned an Array rather than a Set. >>>> - This was faster because no lookup: was performed. >>>> - But now, #keys also return an Array, so don't use #fasterKeys anymore." >>>> - >>>> - self deprecated: 'use #keys'. >>>> - >>>> - ^self keys. >>>> - ! >>>> >>>> Item was removed: >>>> - ----- Method: Dictionary>>keyForIdentity: (in category 'accessing') ----- >>>> - keyForIdentity: anObject >>>> - "If anObject is one of the values of the receive, return its key, else return nil. Contrast #keyAtValue: in which there is only an equality check, here there is an identity check" >>>> - >>>> - self deprecated: 'Use #keyAtIdentityValue:ifAbsent:'. >>>> - ^self keyAtIdentityValue: anObject ifAbsent: nil! >>> > > |
Free forum by Nabble | Edit this page |