Fixed allSelectorsSent because a simpler implementation was overriding the original.
[cslatevm.git] / tests / benchmark / fannkuch.slate
blob59b10518c2854e1f77913b0a152edebbf3f21fa3
2 n@(Integer traits) fannkuch
3 [| perm0 count maxFlipsCount m r flipsCount k k2 temp i j |
4   perm ::= Array newSize: n.
5   perm1 ::= Array newSize: n.
6   count ::= Array newSize: n.
7   maxPerm ::= Array newSize: n.
8   maxFlipsCount := -1.
9   m := n - 1.
11   0 below: n do: [| :i | perm1 at: i put: i].
12   r := n.
13   [
14     [r = 1] whileFalse:
15       [count at: r - 1 put: r.
16        r -= 1].
17     (perm1 at: 0) == 0 \/ [(perm1 at: m) == m] ifFalse:
18       [0 below: n  do:
19          [| :i | perm at: i put: (perm1 at: i)].
20        flipsCount := 0.
21        k := perm at: 0.
22        [k = 0] whileFalse:
23          [k2 := k + 1 bitShift: -1.
24           0 below: k2 do:
25             [| :i |
26              temp := perm at: i.
27              perm at: i put: (perm at: k - i).
28              perm at: k - i put: temp].
29           flipsCount += 1.
30           k := perm at: 0].
31        flipsCount > maxFlipsCount ifTrue:
32          [maxFlipsCount := flipsCount.
33           0 below: n do:
34             [| :i | maxPerm at: i put: (perm1 at: i)]]].
35     [r = n ifTrue: [^ maxFlipsCount].
36      perm0 := perm1 at: 0.
37      i := 0.
38      [i < r] whileTrue:
39        [j := i + 1.
40         perm1 at: i put: (perm1 at: j).
41         i := j].
42      perm1 at: r put: perm0.
43      count at: r put: (count at: r) - 1.
44      r += 1]
45       until: [(count at: r - 1) > 0].
46     r -= 1
47   ] loop.