[squeak-dev] The Trunk: Collections-eem.455.mcz
commits at source.squeak.org
commits at source.squeak.org
Thu Sep 8 17:43:31 UTC 2011
Eliot Miranda uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-eem.455.mcz
==================== Summary ====================
Name: Collections-eem.455
Author: eem
Time: 8 September 2011, 10:43:02.64 am
UUID: 717b6721-47e5-4edb-aaa9-66e942c4943a
Ancestors: Collections-ul.454
Add findNearbyBinaryIndex: for DebuggerMethodMap's rangeForPC:contextIsActiveContext:.
=============== Diff against Collections-ul.454 ===============
Item was added:
+ ----- Method: SequenceableCollection>>findNearbyBinaryIndex: (in category 'enumerating') -----
+ findNearbyBinaryIndex: aBlock
+ "Search for an element in the receiver using binary search.
+ The argument aBlock is a one-element block returning
+ 0 - if the element is the one searched for
+ <0 - if the search should continue in the first half
+ >0 - if the search should continue in the second half
+ If no matching element is found, answer the closest index we could find,
+ answering 0 if the element should preceed all items in the collection,
+ and size + 1 if the element should follow all items in the collection."
+ | index low high test |
+ low := 1.
+ high := self size.
+ [index := high + low // 2.
+ low > high] whileFalse:[
+ test := aBlock value: (self at: index).
+ test = 0
+ ifTrue:[^index]
+ ifFalse:[test > 0
+ ifTrue: [low := index + 1]
+ ifFalse: [high := index - 1]]].
+ ^index = self size ifTrue: [index + 1] ifFalse: [index]!
More information about the Squeak-dev
mailing list
|