[Pkg] The Trunk: Collections-ul.457.mcz
commits at source.squeak.org
commits at source.squeak.org
Sat Sep 10 13:37:49 UTC 2011
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.457.mcz
==================== Summary ====================
Name: Collections-ul.457
Author: ul
Time: 10 September 2011, 3:31:39.521 pm
UUID: f07d7d2f-b42d-6241-be93-164c512d5296
Ancestors: Collections-fbs.456
- no need to call #resetTo: from OrderedCollection class >> newFrom:, because it's already called by #new: (#setCollection:)
- reuse existing binary search method in SequenceableCollection >> findNearbyBinaryIndex:
=============== Diff against Collections-fbs.456 ===============
Item was changed:
----- Method: OrderedCollection class>>newFrom: (in category 'instance creation') -----
newFrom: aCollection
"Answer an instance of me containing the same elements as aCollection."
^(self new: aCollection size)
- resetTo: 1;
addAll: aCollection;
yourself
" OrderedCollection newFrom: {1. 2. 3}
{1. 2. 3} as: OrderedCollection
{4. 2. 7} as: SortedCollection
"!
Item was changed:
----- 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."
+
+ ^self
+ findBinaryIndex: aBlock
+ ifNone: [ :lower :upper |
+ lower = self size
+ ifTrue: [ upper ]
+ ifFalse: [ lower ] ]!
- | 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 Packages
mailing list