| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class Fields { | 5 class Fields { |
| 6 Fields(int i, int j) : fld1 = i, fld2 = j, fld5 = true {} | 6 Fields(int i, int j) : fld1 = i, fld2 = j, fld5 = true {} |
| 7 int fld1; | 7 int fld1; |
| 8 final int fld2; | 8 final int fld2; |
| 9 static int fld3; | 9 static int fld3; |
| 10 static final int fld4 = 10; | 10 static final int fld4 = 10; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 void push(int pile, TowersDisk disk) { | 114 void push(int pile, TowersDisk disk) { |
| 115 TowersDisk top = piles[pile]; | 115 TowersDisk top = piles[pile]; |
| 116 if ((top != null) && (disk.size >= top.size)) | 116 if ((top != null) && (disk.size >= top.size)) |
| 117 Error.error("Cannot put a big disk on a smaller disk."); | 117 Error.error("Cannot put a big disk on a smaller disk."); |
| 118 disk.next = top; | 118 disk.next = top; |
| 119 piles[pile] = disk; | 119 piles[pile] = disk; |
| 120 } | 120 } |
| 121 | 121 |
| 122 TowersDisk pop(int pile) { | 122 TowersDisk pop(int pile) { |
| 123 var top = piles[pile]; | 123 var top = piles[pile]; |
| 124 if (top == null) | 124 if (top === null) |
| 125 Error.error("Attempting to remove a disk from an empty pile."); | 125 Error.error("Attempting to remove a disk from an empty pile."); |
| 126 piles[pile] = top.next; | 126 piles[pile] = top.next; |
| 127 top.next = null; | 127 top.next = null; |
| 128 return top; | 128 return top; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void moveTop(int from, int to) { | 131 void moveTop(int from, int to) { |
| 132 push(to, pop(from)); | 132 push(to, pop(from)); |
| 133 movesDone++; | 133 movesDone++; |
| 134 } | 134 } |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 // T r e e S o r t | 517 // T r e e S o r t |
| 518 class TreeNodePress { | 518 class TreeNodePress { |
| 519 int value; | 519 int value; |
| 520 TreeNodePress left; | 520 TreeNodePress left; |
| 521 TreeNodePress right; | 521 TreeNodePress right; |
| 522 | 522 |
| 523 TreeNodePress(int n) : value = n {} | 523 TreeNodePress(int n) : value = n {} |
| 524 | 524 |
| 525 void insert(int n) { | 525 void insert(int n) { |
| 526 if (n < value) { | 526 if (n < value) { |
| 527 if (left == null) left = new TreeNodePress(n); | 527 if (left === null) left = new TreeNodePress(n); |
| 528 else left.insert(n); | 528 else left.insert(n); |
| 529 } else { | 529 } else { |
| 530 if (right == null) right = new TreeNodePress(n); | 530 if (right === null) right = new TreeNodePress(n); |
| 531 else right.insert(n); | 531 else right.insert(n); |
| 532 } | 532 } |
| 533 } | 533 } |
| 534 | 534 |
| 535 void check() { | 535 void check() { |
| 536 TreeNodePress left = this.left; | 536 TreeNodePress left = this.left; |
| 537 TreeNodePress right = this.right; | 537 TreeNodePress right = this.right; |
| 538 int value = this.value; | 538 int value = this.value; |
| 539 | 539 |
| 540 return ((left == null) || ((left.value < value) && left.check())) && | 540 return ((left === null) || ((left.value < value) && left.check())) && |
| 541 ((right == null) || ((right.value >= value) && right.check())); | 541 ((right === null) || ((right.value >= value) && right.check())); |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 | 544 |
| 545 class TreeSort { | 545 class TreeSort { |
| 546 static void sort(List<int> a) { | 546 static void sort(List<int> a) { |
| 547 int len = a.length; | 547 int len = a.length; |
| 548 TreeNodePress tree = new TreeNodePress(a[0]); | 548 TreeNodePress tree = new TreeNodePress(a[0]); |
| 549 for (var i = 1; i < len; i++) tree.insert(a[i]); | 549 for (var i = 1; i < len; i++) tree.insert(a[i]); |
| 550 if (!tree.check()) Error.error("Invalid result, tree not sorted"); | 550 if (!tree.check()) Error.error("Invalid result, tree not sorted"); |
| 551 } | 551 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 602 |
| 603 static ListElement makeList(int length) { | 603 static ListElement makeList(int length) { |
| 604 if (length == 0) return null; | 604 if (length == 0) return null; |
| 605 return new ListElement(length, makeList(length - 1)); | 605 return new ListElement(length, makeList(length - 1)); |
| 606 } | 606 } |
| 607 | 607 |
| 608 static bool isShorter(ListElement x, ListElement y) { | 608 static bool isShorter(ListElement x, ListElement y) { |
| 609 ListElement xTail = x; | 609 ListElement xTail = x; |
| 610 ListElement yTail = y; | 610 ListElement yTail = y; |
| 611 while (yTail != null) { | 611 while (yTail != null) { |
| 612 if (xTail == null) return true; | 612 if (xTail === null) return true; |
| 613 xTail = xTail.next; | 613 xTail = xTail.next; |
| 614 yTail = yTail.next; | 614 yTail = yTail.next; |
| 615 } | 615 } |
| 616 return false; | 616 return false; |
| 617 } | 617 } |
| 618 } | 618 } |
| 619 | 619 |
| 620 class Takl { | 620 class Takl { |
| 621 static ListElement takl(ListElement x, ListElement y, ListElement z) { | 621 static ListElement takl(ListElement x, ListElement y, ListElement z) { |
| 622 if (ListElement.isShorter(y, x)) { | 622 if (ListElement.isShorter(y, x)) { |
| (...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 } | 2130 } |
| 2131 | 2131 |
| 2132 | 2132 |
| 2133 class LineProcessor extends Isolate { | 2133 class LineProcessor extends Isolate { |
| 2134 | 2134 |
| 2135 LineProcessor() : super() { } | 2135 LineProcessor() : super() { } |
| 2136 | 2136 |
| 2137 void main() { | 2137 void main() { |
| 2138 this.port.receive((message, SendPort replyTo) { | 2138 this.port.receive((message, SendPort replyTo) { |
| 2139 if (message == MandelIsolateTest.TERMINATION_MESSAGE) { | 2139 if (message == MandelIsolateTest.TERMINATION_MESSAGE) { |
| 2140 assert(replyTo == null); | 2140 assert(replyTo === null); |
| 2141 this.port.close(); | 2141 this.port.close(); |
| 2142 } else { | 2142 } else { |
| 2143 replyTo.send(_processLine(message), null); | 2143 replyTo.send(_processLine(message), null); |
| 2144 } | 2144 } |
| 2145 }); | 2145 }); |
| 2146 } | 2146 } |
| 2147 | 2147 |
| 2148 static List<int> _processLine(int y) { | 2148 static List<int> _processLine(int y) { |
| 2149 double inverseN = 2.0 / MandelIsolateTest.N; | 2149 double inverseN = 2.0 / MandelIsolateTest.N; |
| 2150 double Civ = y * inverseN - 1.0; | 2150 double Civ = y * inverseN - 1.0; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2189 }); | 2189 }); |
| 2190 }); | 2190 }); |
| 2191 } | 2191 } |
| 2192 | 2192 |
| 2193 void main() { | 2193 void main() { |
| 2194 this.port.receive((ignored, replyTo) { | 2194 this.port.receive((ignored, replyTo) { |
| 2195 replyTo.send("foo", null); | 2195 replyTo.send("foo", null); |
| 2196 }); | 2196 }); |
| 2197 } | 2197 } |
| 2198 } | 2198 } |
| OLD | NEW |