js/src/devtools/jint/sunspider/access-fannkuch.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* The Great Computer Language Shootout
michael@0 2 http://shootout.alioth.debian.org/
michael@0 3 contributed by Isaac Gouy */
michael@0 4
michael@0 5 function fannkuch(n) {
michael@0 6 var check = 0;
michael@0 7 var perm = Array(n);
michael@0 8 var perm1 = Array(n);
michael@0 9 var count = Array(n);
michael@0 10 var maxPerm = Array(n);
michael@0 11 var maxFlipsCount = 0;
michael@0 12 var m = n - 1;
michael@0 13
michael@0 14 /* BEGIN LOOP */
michael@0 15 for (var i = 0; i < n; i++) perm1[i] = i;
michael@0 16 /* END LOOP */
michael@0 17 var r = n;
michael@0 18
michael@0 19 /* BEGIN LOOP */
michael@0 20 while (true) {
michael@0 21 // write-out the first 30 permutations
michael@0 22 if (check < 30){
michael@0 23 var s = "";
michael@0 24 /* BEGIN LOOP */
michael@0 25 for(var i=0; i<n; i++) s += (perm1[i]+1).toString();
michael@0 26 /* END LOOP */
michael@0 27 check++;
michael@0 28 }
michael@0 29
michael@0 30 /* BEGIN LOOP */
michael@0 31 while (r != 1) { count[r - 1] = r; r--; }
michael@0 32 /* END LOOP */
michael@0 33 if (!(perm1[0] == 0 || perm1[m] == m)) {
michael@0 34 /* BEGIN LOOP */
michael@0 35 for (var i = 0; i < n; i++) perm[i] = perm1[i];
michael@0 36 /* END LOOP */
michael@0 37
michael@0 38 var flipsCount = 0;
michael@0 39 var k;
michael@0 40
michael@0 41 /* BEGIN LOOP */
michael@0 42 while (!((k = perm[0]) == 0)) {
michael@0 43 var k2 = (k + 1) >> 1;
michael@0 44 /* BEGIN LOOP */
michael@0 45 for (var i = 0; i < k2; i++) {
michael@0 46 var temp = perm[i]; perm[i] = perm[k - i]; perm[k - i] = temp;
michael@0 47 }
michael@0 48 /* END LOOP */
michael@0 49 flipsCount++;
michael@0 50 }
michael@0 51 /* END LOOP */
michael@0 52
michael@0 53 if (flipsCount > maxFlipsCount) {
michael@0 54 maxFlipsCount = flipsCount;
michael@0 55 /* BEGIN LOOP */
michael@0 56 for (var i = 0; i < n; i++) maxPerm[i] = perm1[i];
michael@0 57 /* END LOOP */
michael@0 58 }
michael@0 59 }
michael@0 60
michael@0 61 /* BEGIN LOOP */
michael@0 62 while (true) {
michael@0 63 if (r == n) return maxFlipsCount;
michael@0 64 var perm0 = perm1[0];
michael@0 65 var i = 0;
michael@0 66 /* BEGIN LOOP */
michael@0 67 while (i < r) {
michael@0 68 var j = i + 1;
michael@0 69 perm1[i] = perm1[j];
michael@0 70 i = j;
michael@0 71 }
michael@0 72 /* END LOOP */
michael@0 73 perm1[r] = perm0;
michael@0 74
michael@0 75 count[r] = count[r] - 1;
michael@0 76 if (count[r] > 0) break;
michael@0 77 r++;
michael@0 78 }
michael@0 79 /* END LOOP */
michael@0 80 }
michael@0 81 /* END LOOP */
michael@0 82 }
michael@0 83
michael@0 84 var n = 8;
michael@0 85 var ret = fannkuch(n);
michael@0 86

mercurial