The Inbox: Collections-ul.874.mcz

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

The Inbox: Collections-ul.874.mcz

commits-2
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!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ul.874.mcz

Chris Muller-3
Be sure to load Collections-ul.873 first.  When I tried to load this one first directly, my image locked.


On Wed, Feb 5, 2020 at 9:47 AM <[hidden email]> wrote:
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!




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ul.874.mcz

Levente Uzonyi
Right, I should have written a few lines about why there are two mczs.
The idea is to load Collections-ul.873 first then Collections-ul-874
separated by an update map entry to ensure GoodPrimes gets initialized.
The cause of the error is that code loading is not atomic, so the new
GoodPrimes will be accessed before it is initialized. That's what the
"migration only" part works around.

Levente

On Wed, 5 Feb 2020, Chris Muller wrote:

> Be sure to load Collections-ul.873 first.  When I tried to load this one first directly, my image locked.
>
> On Wed, Feb 5, 2020 at 9:47 AM <[hidden email]> wrote:
>       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!
>
>
>
>