[squeak-dev] The Inbox: Collections-ul.874.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Feb 5 15:47:54 UTC 2020
Levente Uzonyi uploaded a new version of Collections to project The Inbox:
http://source.squeak.org/inbox/Collections-ul.874.mcz
==================== Summary ====================
Name: Collections-ul.874
Author: ul
Time: 5 February 2020, 4:40:30.240914 pm
UUID: de45f7ed-0176-48ed-b7d5-3811cbc0fcb9
Ancestors: Collections-ul.873
- remove cruft and migration code from HashedCollection class >> #goodPrimeAtLeast:
=============== Diff against Collections-ul.873 ===============
Item was changed:
----- Method: HashedCollection class>>goodPrimeAtLeast: (in category 'sizing') -----
goodPrimeAtLeast: lowerLimit
"Answer the smallest good prime >= lowerlimit.
If lowerLimit is larger than the largest known good prime, just make it odd.
Use linear search, and exponential search to speed up cases when lowerLimit is small (<2500 and <100000, respectively).
Assume that there are goodPrimes greater than 100000."
| highIndex midIndex lowIndex prime |
- lowerLimit <= 7 ifTrue: [
- lowerLimit <= 3 ifTrue: [ ^3 ].
- lowerLimit <= 5 ifTrue: [ ^5 ].
- ^7 ].
- GoodPrimes ifNil: [ "migration only"
- self initializeGoodPrimes ].
lowerLimit < 2500 ifTrue: [
"Use linear search when the limit is small. The boundary is based on measurements."
+ highIndex := 1.
- highIndex := 4. "skip 3 5 and 7"
[ (GoodPrimes at: highIndex) < lowerLimit ] whileTrue: [
highIndex := highIndex + 1 ].
^GoodPrimes at: highIndex ].
lowerLimit < 100000
ifTrue: [
"Use exponential search when the limit is not too large. The boundary is based on measurements."
highIndex := 1.
[ (GoodPrimes at: highIndex) < lowerLimit ] whileTrue: [
highIndex := highIndex * 2 ].
lowIndex := highIndex // 2 + 1. "highIndex // 2 was smaller than lowerLimit" ]
ifFalse: [
"Regular binary search."
lowIndex := 1.
highIndex := GoodPrimes size.
"Check whether the largest prime would fit"
(GoodPrimes at: highIndex) < lowerLimit ifTrue: [
^lowerLimit bitOr: 1 ]. ].
[ highIndex - lowIndex <= 1 ] whileFalse: [
midIndex := highIndex + lowIndex // 2.
prime := GoodPrimes at: midIndex.
lowerLimit < prime
ifTrue: [ highIndex := midIndex ]
ifFalse: [
lowerLimit > prime
ifTrue: [ lowIndex := midIndex ]
ifFalse: [ ^prime ] ] ].
(GoodPrimes at: lowIndex) >= lowerLimit ifTrue: [ ^GoodPrimes at: lowIndex ].
^GoodPrimes at: highIndex!
More information about the Squeak-dev
mailing list
|